diff --git a/samples/cloudformation-cross-account/functions/packages/CfnStackAssumeRole/lambda.zip b/samples/cloudformation-cross-account/functions/packages/CfnStackAssumeRole/lambda.zip index 23f8f13..afc51ce 100644 Binary files a/samples/cloudformation-cross-account/functions/packages/CfnStackAssumeRole/lambda.zip and b/samples/cloudformation-cross-account/functions/packages/CfnStackAssumeRole/lambda.zip differ diff --git a/samples/cloudformation-cross-account/functions/source/CfnStackAssumeRole/lambda_function.py b/samples/cloudformation-cross-account/functions/source/CfnStackAssumeRole/lambda_function.py index cfc81c3..ca94b9d 100644 --- a/samples/cloudformation-cross-account/functions/source/CfnStackAssumeRole/lambda_function.py +++ b/samples/cloudformation-cross-account/functions/source/CfnStackAssumeRole/lambda_function.py @@ -3,7 +3,7 @@ import string import logging import threading -import requests +import urllib3 # Added by EM import json from botocore.credentials import ( AssumeRoleCredentialFetcher, @@ -14,6 +14,8 @@ from botocore.exceptions import ClientError +http = urllib3.PoolManager() # Added by EM + cfn_states = { "failed": ["CREATE_FAILED", "ROLLBACK_IN_PROGRESS", "ROLLBACK_FAILED", "ROLLBACK_COMPLETE", "DELETE_FAILED", "UPDATE_ROLLBACK_IN_PROGRESS", "UPDATE_ROLLBACK_FAILED", "UPDATE_ROLLBACK_COMPLETE_CLEANUP_IN_PROGRESS", @@ -83,9 +85,8 @@ def send(event, context, response_status, response_data, physical_resource_id, l } try: - response = requests.put(response_url, - data=json_response_body, - headers=headers) + response = http.request('PUT', response_url, headers=headers, body=json_response_body) + logger.info("CloudFormation returned status code: " + response.reason) except Exception as e: logger.error("send(..) failed executing requests.put(..): " + str(e)) @@ -304,9 +305,6 @@ def create(event, context): Create a cfn stack using an assumed role """ - cfn_capabilities = [] - if 'capabilities' in event['ResourceProperties'].keys(): - cfn_capabilities = event['ResourceProperties']['Capabilities'] cfn_client = boto3.client("cloudformation") params = get_cfn_parameters(event) prefix = event['ResourceProperties']['ParentStackId'].split("/")[1] @@ -346,17 +344,21 @@ def update(event, context): Update a cfn stack using an assumed role """ stack_id = event["PhysicalResourceId"] - cfn_capabilities = [] + capabilities = [] if 'capabilities' in event['ResourceProperties'].keys(): - cfn_capabilities = event['ResourceProperties']['capabilities'] + capabilities = event['ResourceProperties']['capabilities'] cfn_client = get_client("cloudformation", event, context) physical_resource_id = stack_id + prefix = event['ResourceProperties']['ParentStackId'].split("/")[1] + parent_properties = cfn_client.describe_stacks(StackName=prefix)['Stacks'][0] + if 'Capabilities' in parent_properties.keys(): + capabilities = parent_properties['Capabilities'] try: cfn_client.update_stack( StackName=stack_id, TemplateURL=event['ResourceProperties']['TemplateURL'], Parameters=get_cfn_parameters(event), - Capabilities=cfn_capabilities, + Capabilities=capabilities, Tags=[{ 'Key': 'ParentStackId', 'Value': event['ResourceProperties']['ParentStackId'] diff --git a/samples/cloudformation-cross-account/functions/source/CfnStackAssumeRole/requirements.txt b/samples/cloudformation-cross-account/functions/source/CfnStackAssumeRole/requirements.txt deleted file mode 100644 index f229360..0000000 --- a/samples/cloudformation-cross-account/functions/source/CfnStackAssumeRole/requirements.txt +++ /dev/null @@ -1 +0,0 @@ -requests