Skip to content

Instantly share code, notes, and snippets.

@fiunchinho
Created March 17, 2016 12:06
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save fiunchinho/70a5d53198e25df65ca6 to your computer and use it in GitHub Desktop.
Save fiunchinho/70a5d53198e25df65ca6 to your computer and use it in GitHub Desktop.
Python script to fetch AWS access key and secret key from a running EC2 instance
from botocore.credentials import InstanceMetadataProvider, InstanceMetadataFetcher
provider = InstanceMetadataProvider(iam_role_fetcher=InstanceMetadataFetcher(timeout=1000, num_attempts=2))
credentials = provider.load()
access_key = credentials.access_key
secret_key = credentials.secret_key
print access_key
print secret_key
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment