in source/helper/website_helper.py [0:0]
def copy_source(event, context):
try:
source_bucket = event["ResourceProperties"]["WebsiteCodeBucket"]
source_key = event["ResourceProperties"]["WebsiteCodePrefix"]
website_bucket = event["ResourceProperties"]["DeploymentBucket"].split('.')[0]
except KeyError as e:
LOGGER.info("Failed to retrieve required values from the CloudFormation event: {e}".format(e=e))
send_response(event, context, "FAILED", {"Message": "Failed to retrieve required values from the CloudFormation event"})
else:
try:
LOGGER.info("Checking if custom environment variables are present")
try:
FileManagerAPIEndpoint = os.environ['FileManagerAPIEndpoint']
region = os.environ['AwsRegion']
user_pool_id = os.environ['UserPoolId']
client_id = os.environ['PoolClientId']
identity_id = os.environ['IdentityPoolId']
except KeyError:
replace_env_variables = False
else:
new_variables = {"fileManagerApiUrl": FileManagerAPIEndpoint, "awsRegion": region,
"userPoolId": user_pool_id, "userPoolIdClientId": client_id, "identityPoolId": identity_id}
replace_env_variables = True
LOGGER.info(
"New variables: {v}".format(v=new_variables))
deployment_bucket = s3.Bucket(website_bucket)
with open('./webapp-manifest.json') as file:
manifest = json.load(file)
print('UPLOADING FILES::')
for key in manifest:
print('s3://'+source_bucket+'/'+source_key+'/'+key)
copy_source = {
'Bucket': source_bucket,
'Key': source_key+'/'+key
}
s3.meta.client.copy(copy_source, website_bucket, key)
if replace_env_variables is True and key == "runtimeConfig.json":
LOGGER.info("updating runtimeConfig.json")
write_to_s3(event, context, website_bucket, key, json.dumps(new_variables))
except Exception as e:
LOGGER.info("Unable to copy website source code into the website bucket: {e}".format(e=e))
send_response(event, context, "FAILED", {"Message": "Unexpected event received from CloudFormation"})
else:
send_response(event, context, "SUCCESS",
{"Message": "Resource creation successful!"})