14

I am writing a bash script that will automatically install and configure AWS CLI tools. I am able to install AWS CLI tools but unable to configure it.

My script is something like this:

#!/bin/bash


wget https://s3.amazonaws.com/aws-cli/awscli-bundle.zip
unzip awscli-bundle.zip
sudo ./awscli-bundle/install -i /usr/local/aws -b /usr/local/bin/aws
./awscli-bundle/install -b ~/bin/aws
./awscli-bundle/install -h

aws configure
AWS Access Key ID [None]: ABCDEFGHIJKLMNOP   ## unable to provide this data
AWS Secret Access Key [None]: xbdwsdADDS/ssfsfa/afzfASADQASAd   ## unable to provide this data
Default region name [None]: us-west-2   ## unable to provide this data
Default output format [None]: json   ## unable to provide this data

I wish to do the configuration using this script too. I wish that I can provide these credentials via script so that it prevents manual entry. How can this be done?

1
  • If you're looking to run this on instances you launch, consider using IAM Roles for EC2 instead of embedding your credentials. The instance takes care of issuing temporary credentials and rotating them, you just need to specify the IAM role when you launch the instance. You will still need to install the actual tools though. Commented Jul 4, 2014 at 0:24

3 Answers 3

20

Use a configuration file rather than the aws configure command. Create a file called ~/.aws/config that looks like this:

[default]
aws_access_key_id=AKIAIOSFODNN7EXAMPLE
aws_secret_access_key=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
region=us-west-2
output=json

More info in the docs.

Sign up to request clarification or add additional context in comments.

3 Comments

Other than that, you can also set the credentials, region and output as environment variables or cli arguments. See: docs.aws.amazon.com/cli/latest/userguide/…
I am unable to find directory ~/.aws/
you will need to create the directory ~/.aws and inside it the file 'config'
2

the best practice is to install the awscli utility by BASH and copy the file from your own specified location of 2 files

without hitting

#aws configure 

command these files will not get created, you can copy and paste the files using bash script and get all the execution done

~/.aws/credintials
~/.aws/config

where credentials contains

[default]
aws_access_key_id=ABCDEFGHIJKLMNOP
aws_secret_access_key=xbdwsdADDS/ssfsfa/afzfASADQASAd

and config file contains

[default]
output=json
region=us-west-2

This will help you to keep the keys at one place and you can also push the same for your execution for any CMT tool as well like Ansible.

Comments

2

you additionally configure this from the command line which will create the configuration file

aws configure set aws_access_key_id ABCDEFGHIJKLMNOP
aws configure set aws_secret_access_key xbdwsdADDS/ssfsfa/afzfASADQASAd
aws configure set default.region eu-west-1

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.