authentication for boto3

0

I am watching a few boto3 videos from youtube to see how the python script gets authenticated from AWS to run a script.

  1. Using aws configure to create a profile file, then via the following to get authenticated. aws_management_console = boto3.session.Session(profile_name="default")
  2. some demo does not include any authentication, how is that script authenticated to run ? Enter image description here

thanks a lot !!

gongya
asked 3 months ago136 views
2 Answers
0
Accepted Answer

Hello.

boto3 will read the authentication information of "~/.aws/credentials" set for the OS user who executed the script without including the code below.
The authentication information to be read is "default", so if you have set a different profile, you will need to specify the profile using the code below.

aws_management_console = boto3.session.Session(profile_name="default")

https://boto3.amazonaws.com/v1/documentation/api/latest/guide/credentials.html

Boto3 will look in several locations when searching for credentials. The mechanism in which Boto3 looks for credentials is to search through a list of possible locations and stop as soon as it finds credentials. The order in which Boto3 searches for credentials is:

  • Passing credentials as parameters in the boto.client() method
  • Passing credentials as parameters when creating a Session object
  • Environment variables
  • Shared credential file (~/.aws/credentials)
  • AWS config file (~/.aws/config)
  • Assume Role provider
  • Boto2 config file (/etc/boto.cfg and ~/.boto)
  • Instance metadata service on an Amazon EC2 instance that has an IAM role configured.
profile picture
EXPERT
answered 3 months ago
EXPERT
reviewed 3 months ago
  • By the way, if the environment running boto3 is EC2, you can use IAM roles, so there is no need to configure "~/.aws/credentials".

0

thanks so much for such a quick response !!!

gongya
answered 3 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions