Boto3: get credentials dynamically?

后端 未结 3 1247
暗喜
暗喜 2020-12-08 09:58

I am struggling to find out how I can get my aws_access_key_id and aws_secret_access_key dynamically from my code.

In boto2 I could do the following: boto.con

3条回答
  •  感情败类
    2020-12-08 10:21

    Can I suggest that accessing the keys is WRONG using boto3:

    import boto3
    session = boto3.Session(profile_name="my-profile")
    
    dynamodb = session.resource(
        "dynamodb",
        region_name=session.region_name,
        # aws_access_key_id=session.get_credentials().access_key,
        # aws_secret_access_key=session.get_credentials().secret_key,
    )
    

    Notice, I commented out accessing the keys because 1:

    Any clients created from this session will use credentials from the [my-profile] section of ~/.aws/credentials.

提交回复
热议问题