Last active
November 20, 2020 18:08
-
-
Save camin-mccluskey/e8ac757f80dce44da85e54582e7414ca to your computer and use it in GitHub Desktop.
Initialise NASA Client
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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