How can I use the AWS profile for managing Credentials?
I am currently working as a cloud solutions architect and managing multiple AWS accounts for different environments. How can I use the AWS profiles to manage Credentials and Configuration efficiently across this environment?
In the context of AWS, you can manage credentials and Configuration efficiently across multiple or different AWS accounts by using the AWS profile using several steps which are given below:-
Create AWS profiles
You can create AWS profiles for each environment in your AWS Credentials. You can also specify a default profile. Here is the example given of how you can create AWS profiles in the credentials file:-
[default]
Aws_access_key_id = YOUR_DEFAULT_ACCESS_KEY_ID
Aws_secret_access_key = YOUR_DEFAULT_SECRET_ACCESS_KEY
[development]
Aws_access_key_id = YOUR_DEVELOPMENT_ACCESS_KEY_ID
Aws_secret_access_key = YOUR_DEVELOPMENT_SECRET_ACCESS_KEY
Region = us-west-2
[testing]
Aws_access_key_id = YOUR_TESTING_ACCESS_KEY_ID
Aws_secret_access_key = YOUR_TESTING_SECRET_ACCESS_KEY
Region = us-east-1
[production]
Aws_access_key_id = YOUR_PRODUCTION_ACCESS_KEY_ID
Aws_secret_access_key = YOUR_PRODUCTION_SECRET_ACCESS_KEY
Region = eu-west-1
Setting AWS profile environment variable
You can set the “aws profile” environment optionally for specifying which AWS profile to use of the CLI command. Here is the example given of setting the AWS profile environment variable:-
“export AWS_PROFILE=development”
Switch between AWS profiles
You can also easily switch between AWS profiles by specifying the “profile” options in the Aws CLI Command. Here is the example given of listing S3 buckets by using a specific AWS profile:-
AWS S3 1s - - profile development
Use AWS SDK with profiles
When you are using AWS SDK in your coding then you can specify the profile name in the SDK Configuration or session initialization. Here is the example given by using Boto3 with an AWS profile:-
Import boto3
Session = boto3.Session(profile_name=’development’)
S3_client = session.client(‘s3’)
Buckets = s3_client.list_buckets()
For bucket in buckets[‘Buckets’]:
Print(bucket[‘Name’])