Skip to content

Instantly share code, notes, and snippets.

@allanlei
Created June 10, 2014 09:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save allanlei/39bfd10b03b441b0a20c to your computer and use it in GitHub Desktop.
Save allanlei/39bfd10b03b441b0a20c to your computer and use it in GitHub Desktop.
Retrieves
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import requests
import urlparse
import click
@click.command()
@click.argument('iam_role')
@click.option('--metadata-url', default='http://169.254.169.254/latest/meta-data/iam/security-credentials/')
def run(iam_role, metadata_url):
response = requests.get(urlparse.urljoin(metadata_url, iam_role))
response.raise_for_status()
access_key, secret_key = (lambda x: (x['AccessKeyId'], x['SecretAccessKey']))(response.json())
print '{}:{}'.format(access_key, secret_key)
if __name__ == '__main__':
run()
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import urlparse
import boto.s3.connection
import click
@click.command()
@click.argument('credentials')
@click.argument('bucket_name')
@click.argument('key_name')
def run(credentials, bucket, key_name):
access_key, secret_key = credentials.split(':')
conn = boto.s3.connection.S3Connection(access_key, secret_key)
bucket = conn.get_bucket(bucket_name)
key = bucket.get_key(key_name)
print key.get_contents_as_string()
if __name__ == '__main__':
run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment