LoginSignup
0
0

More than 1 year has passed since last update.

LambdaでWorkSpacesの情報を取得する

Last updated at Posted at 2022-06-02

前提

  • 今回取得するのはWorkSpacesのコンピュータ名とユーザ名の一覧のみ
  • 結果はcsvファイルに保存
  • Lambda Python3.9で実行

処理

    response = client.describe_workspaces()
    ALL_INFO = response['Workspaces']
    file = "/tmp/LIST.csv"

    with open(file, "w", newline='',encoding="utf-8") as f:
        writer = csv.writer(f)
        for INFO in ALL_INFO:
            COMPUTERNAME = INFO["ComputerName"]
            USER_NAME = INFO["UserName"]
            REQUIRED_INFORMATION = []
            REQUIRED_INFORMATION.append(COMPUTERNAME)
            REQUIRED_INFORMATION.append(USER_NAME)
            writer.writerow(REQUIRED_INFORMATION)
    while 'NextToken' in response:
        with open(file, "a", newline='',encoding="utf-8") as f:
            writer = csv.writer(f)
            response = client.describe_workspaces(NextToken=response['NextToken'])
            ALL_INFO = response['Workspaces']
            for INFO in ALL_INFO:
                COMPUTERNAME = INFO["ComputerName"]
                USER_NAME = INFO["UserName"]
                REQUIRED_INFORMATION = []
                REQUIRED_INFORMATION.append(COMPUTERNAME)
                REQUIRED_INFORMATION.append(USER_NAME)
                writer.writerow(REQUIRED_INFORMATION)

補足

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0