Skip to content

fix(s3-deployment): physical id not set during failure scenario #24428

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/@aws-cdk/aws-s3-deployment/lib/lambda/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ def handler(event, context):

def cfn_error(message=None):
logger.error("| cfn_error: %s" % message)
cfn_send(event, context, CFN_FAILED, reason=message)
cfn_send(event, context, CFN_FAILED, reason=message, physicalResourceId=event.get('PhysicalResourceId', None))


try:
# We are not logging ResponseURL as this is a pre-signed S3 URL, and could be used to tamper
Expand Down
17 changes: 17 additions & 0 deletions packages/@aws-cdk/aws-s3-deployment/test/lambda/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,23 @@ def mock_make_api_call(self, operation_name, kwarg):

self.assertEqual(update_resp['Reason'], "invalid request: request type is 'Delete' but 'PhysicalResourceId' is not defined")

def test_physical_id_on_cloud_front_error(self):
def mock_make_api_call(self, operation_name, kwarg):
if operation_name == 'CreateInvalidation':
raise ClientError({'Error': {'Code': '500', 'Message': 'Invalidation error'}}, operation_name)

with patch('botocore.client.BaseClient._make_api_call', new=mock_make_api_call):
resp = invoke_handler("Update", {
"SourceBucketNames": ["<source-bucket>"],
"SourceObjectKeys": ["<source-object-key>"],
"DestinationBucketName": "<dest-bucket-name>",
"DistributionId": "<cf-dist-id>",
}, old_resource_props={
"DestinationBucketName": "<dest-bucket-name>",
}, physical_id="<physical-id>", expected_status="FAILED")

self.assertEqual(resp["PhysicalResourceId"], "<physical-id>")

# no bucket tags removes content
def test_no_tags_on_bucket(self):
def mock_make_api_call(self, operation_name, kwarg):
Expand Down