|
| 1 | +###################################################################################################################### |
| 2 | +# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # |
| 3 | +# # |
| 4 | +# Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance # |
| 5 | +# with the License. A copy of the License is located at # |
| 6 | +# # |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 # |
| 8 | +# # |
| 9 | +# or in the 'license' file accompanying this file. This file is distributed on an 'AS IS' BASIS, WITHOUT WARRANTIES # |
| 10 | +# OR CONDITIONS OF ANY KIND, express or implied. See the License for the specific language governing permissions # |
| 11 | +# and limitations under the License. # |
| 12 | +###################################################################################################################### |
| 13 | + |
1 | 14 | import boto3
|
2 | 15 | import json
|
3 | 16 | import logging
|
@@ -101,22 +114,20 @@ def copy_source(event, context):
|
101 | 114 |
|
102 | 115 | deployment_bucket = s3.Bucket(website_bucket)
|
103 | 116 |
|
104 |
| - objects = s3.Bucket(name=source_bucket).objects.filter(Prefix='{k}/'.format(k=source_key)) |
105 |
| - |
106 |
| - for s3_object in objects: |
107 |
| - old_key = s3_object.key |
108 |
| - LOGGER.info(old_key) |
109 |
| - try: |
110 |
| - new_key = old_key.split('website/')[1] |
111 |
| - # Only pickup items under the "website" prefix |
112 |
| - except IndexError: |
113 |
| - pass |
114 |
| - else: |
115 |
| - source = {"Bucket": source_bucket, "Key": old_key} |
116 |
| - deployment_bucket.copy(source, '{key}'.format(key=new_key)) |
117 |
| - if replace_env_variables is True and new_key == "runtimeConfig.json": |
| 117 | + with open('./webapp-manifest.json') as file: |
| 118 | + manifest = json.load(file) |
| 119 | + print('UPLOADING FILES::') |
| 120 | + for key in manifest: |
| 121 | + print('s3://'+source_bucket+'/'+source_key+'/'+key) |
| 122 | + copy_source = { |
| 123 | + 'Bucket': source_bucket, |
| 124 | + 'Key': source_key+'/'+key |
| 125 | + } |
| 126 | + s3.meta.client.copy(copy_source, website_bucket, key) |
| 127 | + if replace_env_variables is True and key == "runtimeConfig.json": |
118 | 128 | LOGGER.info("updating runtimeConfig.json")
|
119 |
| - write_to_s3(event, context, website_bucket, new_key, json.dumps(new_variables)) |
| 129 | + write_to_s3(event, context, website_bucket, key, json.dumps(new_variables)) |
| 130 | + |
120 | 131 | except Exception as e:
|
121 | 132 | LOGGER.info("Unable to copy website source code into the website bucket: {e}".format(e=e))
|
122 | 133 | send_response(event, context, "FAILED", {"Message": "Unexpected event received from CloudFormation"})
|
|
0 commit comments