3
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からaccess_key, secret_keyを取得する

Posted at

boto3からprofileを指定してIDとパスワードを取得する

def get_credentials():
    import boto3
    session = boto3.session.Session(profile_name='default')
    credentials = session.get_credentials()
    return {'ID': credentials.access_key, 'PW': credentials.secret_key}

参考

Do not hard code credentials

client = boto3.client(
's3',
# Hard coded strings as credentials, not recommended.
aws_access_key_id='AKIAIO5FODNN7EXAMPLE',
aws_secret_access_key='ABCDEF+c2L7yXeGvUyrPgYsDnWRRC1AYEXAMPLE'
)


> Hard coded strings as credentials, not recommended.
> Hard coded strings as credentials, not recommended.
> Hard coded strings as credentials, not recommended.

間違っても、コード内にAKIAI~と書かないようにしましょう。
GitHubにソースをアップロードして大変な事になります。(経験談)

## 余談

https://qiita.com/hatobeam75/items/f9430f016a8366b63cf0

私はCognitoからID, PWを取得する前の確認用に使っていました。
Sessionでは無くID/PWを要求するタイプのAPIを用いる場合は間違ってもハードコードしないようにしてください。
GitHubにソースをアップロードして大変な事になります。(2回目)
3
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
3
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?