Skip to content

Instantly share code, notes, and snippets.

@rcarrata
Last active October 4, 2021 14:48
Show Gist options
  • Save rcarrata/e8afe638bd18244a2e934b949c25ac93 to your computer and use it in GitHub Desktop.
Save rcarrata/e8afe638bd18244a2e934b949c25ac93 to your computer and use it in GitHub Desktop.
Install AWS and set up AWS Credentials
echo "## Please give me the AWSKEY"
read AWSKEY
echo "## Please give me the AWS_SECRET_KEY"
read AWSSECRETKEY
echo "## Please give me the REGION"
read REGION
aws --version &> /dev/null
if [ $? == 0 ]; then
echo "AWS Already installed"
aws --version
else
echo "## Download the AWS CLI"
curl "https://s3.amazonaws.com/aws-cli/awscli-bundle.zip" -o "awscli-bundle.zip"
unzip awscli-bundle.zip
echo "## Download the AWS CLI"
./awscli-bundle/install -i /usr/local/aws -b /bin/aws
echo "## Checking the versio"
/bin/aws --version
fi
echo "## Backup and remove preexistent creds"
cp -pr $HOME/.aws /tmp
rm -rf $HOME/.aws
mkdir $HOME/.aws
echo "## Installing the new creds"
cat << EOF > $HOME/.aws/credentials
[default]
aws_access_key_id = ${AWSKEY}
aws_secret_access_key = ${AWSSECRETKEY}
region = $REGION
EOF
echo "## Testing aws cli"
aws sts get-caller-identity
@rcarrata
Copy link
Author

rcarrata commented Oct 4, 2021

  • Tested and working in aws bastion instance :
# cat /etc/redhat-release
Red Hat Enterprise Linux release 8.2 (Ootpa)
  • Running the aws set credentials:
bash test.sh
## Please give me the AWSKEY
xxxx
## Please give me the AWS_SECRET_KEY
xxxx
## Please give me the REGION
eu-west-1
AWS Already installed
aws-cli/1.20.53 Python/3.6.8 Linux/4.18.0-193.14.3.el8_2.x86_64 botocore/1.21.53
## Backup and remove preexistent creds
## Installing the new creds
## Testing aws cli
{
    "UserId": "xxx",
    "Account": "xxx",
    "Arn": "arn:aws:iam::xx:user/xx"
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment