Boto3 uses old credentials

前端 未结 2 1480
离开以前
离开以前 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条回答
  •  孤独总比滥情好
    2021-01-02 18:49

    You need boto3.session.Session to overwrite the access credentials.

    Just do this reference http://boto3.readthedocs.io/en/latest/reference/core/session.html

    import boto3
    
    # Assign you own access 
    mysession = boto3.session.Session(aws_access_key_id='foo1', aws_secret_access_key='bar1')
    
    # If you want to use different profile call foobar inside .aws/credentials
    mysession = boto3.session.Session(profile_name="fooboar")
    
    # Afterwards, just declare your AWS client/resource services    
    sqs_resource=mysession.resource("sqs")
    
    # or client 
    s3_client=mysession.client("s3")
    

    Basically, little change to your code. you just pass in the session instead of direct boto3.client/boto3.resource

    self.sts_client = mysession.client('sts')
    

提交回复
热议问题