AWS Service Higher Order Functions
"""AWS Service Higher Order Functions | |
This module defines higher order operations that use AWS S3 and Secrets Manager to | |
perform operations required by Akamai Configuration Deployment. | |
""" | |
import logging | |
import os | |
import json | |
import boto3 | |
LOGGER = logging.getLogger(__name__) | |
def get_json_from_s3(bucket, key): | |
""" Parses a file stored in s3 as a json document and returns it. | |
Args: | |
bucket: The name of the bucket in the account that stores the asset. | |
key: the s3 object key that stores the asset. | |
Returns: | |
A parsed representation of the json document using python builtins (dict, list, etc.) | |
""" | |
LOGGER.info(f"Getting Object: {key} in bucket: {bucket}") | |
s3 = boto3.resource("s3") | |
obj = s3.Object(bucket, key) | |
return json.loads(obj.get()["Body"].read().decode("utf-8")) | |
def get_json_secret(key): | |
""" Gets the a secret stored in secrets manager as a json document. | |
Args: | |
key: the secret id in secrets manager of the document to fetch. | |
Returns: | |
A parsed representation of the json document using python builtins (dict, list, etc.) | |
""" | |
LOGGER.info(f"Getting Secret with Id: {key}") | |
secrets = boto3.client("secretsmanager") | |
secret = secrets.get_secret_value(SecretId=key) | |
return json.loads(secret["SecretString"]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment