diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 3c14e41..3db3b8c 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -51,13 +51,11 @@ jobs: draft: false prerelease: false # Package and Upload Archive - - name: Pre-Package Macro - run: cd source/s3objects && zip -r ../../macro.zip macro.py resource.py && cd ../../ - name: Pre-Package Function run: cd source/secured-headers/ && zip -r ../../s-headers.zip index.js && cd ../../ - name: Package Release run: zip -r packaged.zip -@ < ci/include.lst - - name: Upload Release - run: aws s3 cp packaged.zip s3://$CFN_BUCKET/amazon-cloudfront-secure-static-site/v${{ env.THIS_VERSION }}/amazon-cloudfront-secure-static-site.zip + - name: Upload Release + run: aws s3 cp packaged.zip s3://$CFN_BUCKET/amazon-cloudfront-secure-static-site/v${{ env.THIS_VERSION }}/amazon-cloudfront-secure-static-site.zip env: CFN_BUCKET: ${{ secrets.CFN_BUCKET }} diff --git a/cfn-publish.config b/cfn-publish.config index 1e43c58..ae3187e 100644 --- a/cfn-publish.config +++ b/cfn-publish.config @@ -1,5 +1,5 @@ template=templates/main.yaml acl="public-read" -extra_files="macro.zip s-headers.zip source/website/index.html source/website/css/style.css source/website/404.html source/website/other.html" +extra_files="s-headers.zip source/website/index.html source/website/css/style.css source/website/404.html source/website/other.html" bucket_name_prefix="solution-builders" regions="us-east-1" diff --git a/source/s3objects/macro.py b/source/s3objects/macro.py deleted file mode 100644 index 884e53c..0000000 --- a/source/s3objects/macro.py +++ /dev/null @@ -1,75 +0,0 @@ -# Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"). You -# may not use this file except in compliance with the License. A copy of -# the License is located at -# -# http://aws.amazon.com/apache2.0/ -# -# or in the "license" file accompanying this file. This file is -# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF -# ANY KIND, either express or implied. See the License for the specific -# language governing permissions and limitations under the License. - -import boto3 -import os - -LAMBDA_ARN = os.environ["LAMBDA_ARN"] - -s3_client = boto3.client("s3") - -def handle_template(request_id, template): - new_resources = {} - - for name, resource in template.get("Resources", {}).items(): - if resource["Type"] == "AWS::S3::Object": - props = resource["Properties"] - - if len([prop for prop in resource["Properties"] if prop in ["Body", "Base64Body", "Source"]]) != 1: - raise Exception("You must specify exactly one of: Body, Base64Body, Source") - - target = props["Target"] - - if "ACL" not in target: - target["ACL"] = "private" - - resource_props = { - "ServiceToken": LAMBDA_ARN, - "Target": target, - } - - if "Body" in props: - resource_props["Body"] = props["Body"] - - elif "Base64Body" in props: - resource_props["Base64Body"] = props["Base64Body"] - - elif "Source" in props: - resource_props["Source"] = props["Source"] - - new_resources[name] = { - "Type": "Custom::S3Object", - "Version": "1.0", - "Properties": resource_props, - } - - for name, resource in new_resources.items(): - template["Resources"][name] = resource - - return template - -def handler(event, context): - try: - template = handle_template(event["requestId"], event["fragment"]) - except Exception as e: - return { - "requestId": event["requestId"], - "status": "failure", - "fragment": event["fragment"], - } - - return { - "requestId": event["requestId"], - "status": "success", - "fragment": template, - } diff --git a/source/s3objects/resource.py b/source/s3objects/resource.py deleted file mode 100644 index 5d246fe..0000000 --- a/source/s3objects/resource.py +++ /dev/null @@ -1,103 +0,0 @@ -# Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"). You -# may not use this file except in compliance with the License. A copy of -# the License is located at -# -# http://aws.amazon.com/apache2.0/ -# -# or in the "license" file accompanying this file. This file is -# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF -# ANY KIND, either express or implied. See the License for the specific -# language governing permissions and limitations under the License. - -from urllib2 import build_opener, HTTPHandler, Request -import base64 -import boto3 -import httplib -import json - -s3_client = boto3.client("s3") - -def sendResponse(event, context, status, message): - bucket = event["ResourceProperties"].get("Target", {}).get("Bucket") - key = event["ResourceProperties"].get("Target", {}).get("Key") - - body = json.dumps({ - "Status": status, - "Reason": message, - "StackId": event['StackId'], - "RequestId": event['RequestId'], - "LogicalResourceId": event['LogicalResourceId'], - "PhysicalResourceId": "s3://{}/{}".format(bucket, key), - "Data": { - "Bucket": bucket, - "Key": key, - }, - }) - - request = Request(event['ResponseURL'], data=body) - request.add_header('Content-Type', '') - request.add_header('Content-Length', len(body)) - request.get_method = lambda: 'PUT' - - opener = build_opener(HTTPHandler) - response = opener.open(request) - -def handler(event, context): - print("Received request:", json.dumps(event, indent=4)) - - request = event["RequestType"] - properties = event["ResourceProperties"] - - if "Target" not in properties or all(prop not in properties for prop in ["Body", "Base64Body", "Source"]): - return sendResponse(event, context, "FAILED", "Missing required parameters") - - target = properties["Target"] - - if request in ("Create", "Update"): - if "Body" in properties: - target.update({ - "Body": properties["Body"], - }) - - s3_client.put_object(**target) - - elif "Base64Body" in properties: - try: - body = base64.b64decode(properties["Base64Body"]) - except: - return sendResponse(event, context, "FAILED", "Malformed Base64Body") - - target.update({ - "Body": body - }) - - s3_client.put_object(**target) - - elif "Source" in properties: - source = properties["Source"] - - s3_client.copy_object( - CopySource=source, - Bucket=target["Bucket"], - Key=target["Key"], - MetadataDirective="COPY", - TaggingDirective="COPY", - ACL=target["ACL"], - ) - - else: - return sendResponse(event, context, "FAILED", "Malformed body") - - return sendResponse(event, context, "SUCCESS", "Created") - - if request == "Delete": - s3_client.delete_object( - Bucket=target["Bucket"], - Key=target["Key"], - ) - - return sendResponse(event, context, "SUCCESS", "Deleted") - - return sendResponse(event, context, "FAILED", "Unexpected: {}".format(request))