in source/shared/custom_resources/cfn_bucket_loader.py [0:0]
def put_web_contents(bucket_name):
"""
This function is responsible for removing any existing contents
from the specified bucket, and adding contents to the bucket
from the packaged contents.
"""
client = boto3.client("s3", config=user_config)
# upload each local file to the bucket, preserve folders
for dirpath, _, filenames in os.walk(CONTENTS_LOCAL):
for name in filenames:
local = f"{dirpath}/{name}"
remote = local.replace(f"{CONTENTS_LOCAL}/", "")
print(f'put {local}')
content_type = None
if remote.endswith(".js"):
content_type = "application/javascript"
elif remote.endswith(".html"):
content_type = "text/html"
elif remote.endswith(".css"):
content_type = "text/css"
else:
content_type = "binary/octet-stream"
with open(local, 'rb') as data:
client.put_object(Bucket=bucket_name,
Key=remote,
Body=data,
ContentType=content_type)