Skip to content

Instantly share code, notes, and snippets.

@camin-mccluskey
Last active November 20, 2020 18:08
Show Gist options
  • Save camin-mccluskey/e8ac757f80dce44da85e54582e7414ca to your computer and use it in GitHub Desktop.
Save camin-mccluskey/e8ac757f80dce44da85e54582e7414ca to your computer and use it in GitHub Desktop.
Initialise NASA Client
import boto3
from boto3.session import Session
MARS_DATA_ROLE_ARN = "arn:aws:iam::9999999999:role/SecretMarsDataReadOnlyRole" # role ARN shared with us
DEFAULT_ROLE_SESSION_NAME = "mars-data-access-role-session"
def get_nasa_data_client():
client = boto3.client('sts')
response = client.assume_role(RoleArn=MARS_DATA_ROLE_ARN, RoleSessionName=DEFAULT_ROLE_SESSION_NAME)
session = Session(aws_access_key_id=response['Credentials']['AccessKeyId'],
aws_secret_access_key=response['Credentials']['SecretAccessKey'],
aws_session_token=response['Credentials']['SessionToken'])
# client with permission to access NASA's table
return session.client('dynamodb')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment