1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Boto3で利用中のAWSアカウントIDを取得する

Posted at

概要

  • AWS SDK for Python(Boto3)で操作中のAWSアカウントIDを取得します
  • 利用サービスは AWS Security Token Service(STS)です

コード

import boto3

sts = boto3.client('sts')
id_info = sts.get_caller_identity()
print(id_info['Account'])

振り返り

  • Accountは数字のみ12桁のアカウントIDがセットされます
  • 他に、UserId、Arnなどの要素が含まれます
  • 要するにAWS CLIの下記コマンドをコードにしたということですね
aws sts get-caller-identity
1
1
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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?