Skip to content

Instantly share code, notes, and snippets.

View ob1-sc's full-sized avatar

Simon O'Brien ob1-sc

  • VMware
  • United Kingdom
View GitHub Profile
@laidbackware
laidbackware / get_s3_file.sh
Last active November 25, 2020 17:00 — forked from davidejones/get_s3_file.sh
Test IAM access to AWS s3 bucket from EC2
#!/bin/bash
instance_profile=`curl http://169.254.169.254/latest/meta-data/iam/security-credentials/`
aws_token_response=`curl --silent http://169.254.169.254/latest/meta-data/iam/security-credentials/${instance_profile}`
aws_access_key_id=`echo "${aws_token_response}" | grep AccessKeyId | cut -d':' -f2 | sed 's/[^0-9A-Z]*//g'`
aws_secret_access_key=`echo "${aws_token_response}" | grep SecretAccessKey | cut -d':' -f2 | sed 's/[^0-9A-Za-z/+=]*//g'`
token=`echo "${aws_token_response}" | sed -n '/Token/{p;}' | cut -f4 -d'"'`
echo "${aws_token_response}" | sed -n '/Expiration/{p;}'
file=$2