I want to automate the Configuring the AWS Command Line Interface shown at this page in python. I want to do so so that i don't have to manually type in every step (like the aws access key id,secret access key,region and output format) as I have a large number of servers that needs this step.
Is there way that I can code this in a python script and when I run that python on individual servers it will do this profile setup? With this I will only have to run a script in each server and not run run every individual step.
Quick configuration with aws configure For general use, the aws configure command is the fastest way to set up your AWS CLI installation. When you enter this command, the AWS CLI prompts you for four pieces of information: Access key ID. Secret access key.
Choose Users from the navigation bar and then choose your AWS user name (not the check box). Choose the Security credentials tab, and then choose Create access key. If you already have an access key but you can't access your secret key, make the old key inactive and create a new one.
aws configure setSpecify the profile that you want to view or modify with the --profile setting. For example, the following command sets the region in the profile named integ . To remove a setting, use an empty string as the value, or manually delete the setting in your config and credentials files in a text editor.
When you type this command, the AWS CLI prompts you for four pieces of information: Access key, secret access key, AWS Region, and output format.
In order to set the name for the default AWS CLI profile, set the AWS_PROFILE environment variable to the name of the profile stored in your credentials and config files, e.g. admin for a named profile, or default for the default profile. Copied!
I suggest using Ansible
and copy the config files to servers. Easiest and error free. If Ansible
is ruled out, call aws configure set
If you want to create the config file, execute the following in subprocess
:
aws configure set aws_access_key_id xxxxxxxxx
aws configure set aws_secret_access_key xxxxxxxxx
....
If you want to set it in the Python script only, set the environment variable in the script:
import os
os.environ['aws_access_key_id'] = 'xxxxxxxxx'
helloV is helpful, should be upvoted.
Here's my re-working of it ( you may or may not need the sudo in last command )
( note this is bash, not python - many ways to pythonise the general idea :-) )
aws configure set default.region us-east-1
aws configure set aws_access_key_id 'YOUR_ACCESS_KEY'
aws configure set aws_secret_access_key 'YOUR_SECRET_KEY'
aws ecr get-login | sudo sh
And here as a one liner .
aws configure set default.region us-east-1; aws configure set aws_access_key_id 'YOURSACCESSKEY' ; aws configure set aws_secret_access_key 'YOUR_SECRET_KEY'; aws ecr get-login | sudo sh
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With