Boto3 uses old credentials

前端 未结 2 1470
离开以前
离开以前 2021-01-02 17:47

I am using tkinter to create gui application that returns the security groups. Currently if you want to change your credentials (e.g. if you accidentally entere

2条回答
  •  旧时难觅i
    2021-01-02 18:25

    Sure, just create different sessions from botocore.session.Session object for each set of credentials:

    import boto3
    s1 = boto3.session.Session(aws_access_key_id='foo1', aws_secret_access_key='bar1')
    s2 = boto3.session.Session(aws_access_key_id='foo2', aws_secret_access_key='bar2')
    

    Also you can leverage set_credentials method to keep 1 session an change creds on the fly:

    import botocore
    session - botocore.session.Session()
    
    session.set_credentials('foo', 'bar')
    client = session.create_client('s3')
    client._request_signer._credentials.access_key
    u'foo'
    
    session.set_credentials('foo1', 'bar')
    client = session.create_client('s3')
    client._request_signer._credentials.access_key
    u'foo1'
    

提交回复
热议问题