in functions/source/lambda_function.py [0:0]
def get_meraki_key():
secret_name = 'MerakiAPIKey'
region = os.environ['AWS_REGION']
session = boto3.session.Session()
client = session.client(
service_name='secretsmanager',
region_name=region,
)
try:
get_secret_value_response = client.get_secret_value(
SecretId=secret_name
)
except ClientError as e:
if e.response['Error']['Code'] == 'ResourceNotFoundException':
logger.info('The requested secret ' + secret_name + ' was not found')
elif e.response['Error']['Code'] == 'InvalidRequestException':
logger.info('The request was invalid due to {}:'.format(e))
elif e.response['Error']['Code'] == 'InvalidParameterException':
logger.info('The request had invalid params: {}'.format(e))
else:
# Secrets Manager decrypts the secret value using the associated KMS CMK
# Depending on whether the secret was a string or binary, only one of these fields will be populated
if 'SecretString' in get_secret_value_response:
text_secret_data = json.loads(get_secret_value_response['SecretString'])
merakiapikey = text_secret_data['merakiapikey']
return merakiapikey
else:
binary_secret_data = get_secret_value_response['SecretBinary']
return binary_secret_data