|
1 | 1 | {
|
2 | 2 | "Resources": {
|
| 3 | + "FServiceRole3AC82EE1": { |
| 4 | + "Type": "AWS::IAM::Role", |
| 5 | + "Properties": { |
| 6 | + "AssumeRolePolicyDocument": { |
| 7 | + "Statement": [ |
| 8 | + { |
| 9 | + "Action": "sts:AssumeRole", |
| 10 | + "Effect": "Allow", |
| 11 | + "Principal": { |
| 12 | + "Service": "lambda.amazonaws.com" |
| 13 | + } |
| 14 | + } |
| 15 | + ], |
| 16 | + "Version": "2012-10-17" |
| 17 | + }, |
| 18 | + "ManagedPolicyArns": [ |
| 19 | + { |
| 20 | + "Fn::Join": [ |
| 21 | + "", |
| 22 | + [ |
| 23 | + "arn:", |
| 24 | + { |
| 25 | + "Ref": "AWS::Partition" |
| 26 | + }, |
| 27 | + ":iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" |
| 28 | + ] |
| 29 | + ] |
| 30 | + } |
| 31 | + ] |
| 32 | + } |
| 33 | + }, |
| 34 | + "FC4345940": { |
| 35 | + "Type": "AWS::Lambda::Function", |
| 36 | + "Properties": { |
| 37 | + "Code": { |
| 38 | + "ZipFile": "exports.handler = async function handler(event) {\n console.log('event:', JSON.stringify(event, undefined, 2));\n return { event };\n}" |
| 39 | + }, |
| 40 | + "Handler": "index.handler", |
| 41 | + "Role": { |
| 42 | + "Fn::GetAtt": [ |
| 43 | + "FServiceRole3AC82EE1", |
| 44 | + "Arn" |
| 45 | + ] |
| 46 | + }, |
| 47 | + "Runtime": "nodejs18.x" |
| 48 | + }, |
| 49 | + "DependsOn": [ |
| 50 | + "FServiceRole3AC82EE1" |
| 51 | + ] |
| 52 | + }, |
3 | 53 | "ImportedNotificationsDB5DE386": {
|
4 | 54 | "Type": "Custom::S3BucketNotifications",
|
5 | 55 | "Properties": {
|
|
9 | 59 | "Arn"
|
10 | 60 | ]
|
11 | 61 | },
|
12 |
| - "BucketName": "cdk-integration-test-s3-imported-bucket-name", |
| 62 | + "BucketName": { |
| 63 | + "Fn::ImportValue": "TestStack1:ExportsOutputRefbucket43879C716CF1CFA3" |
| 64 | + }, |
13 | 65 | "NotificationConfiguration": {
|
14 | 66 | "LambdaFunctionConfigurations": [
|
15 | 67 | {
|
|
25 | 77 | }
|
26 | 78 | ]
|
27 | 79 | },
|
28 |
| - "Managed": false |
| 80 | + "Managed": false, |
| 81 | + "SkipDestinationValidation": false |
29 | 82 | },
|
30 | 83 | "DependsOn": [
|
31 |
| - "ImportedAllowBucketNotificationsToTestStackF6B9A922242C13EDE" |
| 84 | + "ImportedAllowBucketNotificationsToTestStack2F56424633CA7CA6E4" |
32 | 85 | ]
|
33 | 86 | },
|
34 |
| - "ImportedAllowBucketNotificationsToTestStackF6B9A922242C13EDE": { |
| 87 | + "ImportedAllowBucketNotificationsToTestStack2F56424633CA7CA6E4": { |
35 | 88 | "Type": "AWS::Lambda::Permission",
|
36 | 89 | "Properties": {
|
37 | 90 | "Action": "lambda:InvokeFunction",
|
|
53 | 106 | {
|
54 | 107 | "Ref": "AWS::Partition"
|
55 | 108 | },
|
56 |
| - ":s3:::cdk-integration-test-s3-imported-bucket-name" |
| 109 | + ":s3:::", |
| 110 | + { |
| 111 | + "Fn::ImportValue": "TestStack1:ExportsOutputRefbucket43879C716CF1CFA3" |
| 112 | + } |
57 | 113 | ]
|
58 | 114 | ]
|
59 | 115 | }
|
60 | 116 | }
|
61 | 117 | },
|
62 |
| - "FServiceRole3AC82EE1": { |
63 |
| - "Type": "AWS::IAM::Role", |
64 |
| - "Properties": { |
65 |
| - "AssumeRolePolicyDocument": { |
66 |
| - "Statement": [ |
67 |
| - { |
68 |
| - "Action": "sts:AssumeRole", |
69 |
| - "Effect": "Allow", |
70 |
| - "Principal": { |
71 |
| - "Service": "lambda.amazonaws.com" |
72 |
| - } |
73 |
| - } |
74 |
| - ], |
75 |
| - "Version": "2012-10-17" |
76 |
| - }, |
77 |
| - "ManagedPolicyArns": [ |
78 |
| - { |
79 |
| - "Fn::Join": [ |
80 |
| - "", |
81 |
| - [ |
82 |
| - "arn:", |
83 |
| - { |
84 |
| - "Ref": "AWS::Partition" |
85 |
| - }, |
86 |
| - ":iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" |
87 |
| - ] |
88 |
| - ] |
89 |
| - } |
90 |
| - ] |
91 |
| - } |
92 |
| - }, |
93 |
| - "FC4345940": { |
94 |
| - "Type": "AWS::Lambda::Function", |
95 |
| - "Properties": { |
96 |
| - "Code": { |
97 |
| - "ZipFile": "exports.handler = async function handler(event) {\n console.log('event:', JSON.stringify(event, undefined, 2));\n return { event };\n}" |
98 |
| - }, |
99 |
| - "Handler": "index.handler", |
100 |
| - "Role": { |
101 |
| - "Fn::GetAtt": [ |
102 |
| - "FServiceRole3AC82EE1", |
103 |
| - "Arn" |
104 |
| - ] |
105 |
| - }, |
106 |
| - "Runtime": "nodejs18.x" |
107 |
| - }, |
108 |
| - "DependsOn": [ |
109 |
| - "FServiceRole3AC82EE1" |
110 |
| - ] |
111 |
| - }, |
112 | 118 | "BucketNotificationsHandler050a0587b7544547bf325f094a3db834RoleB6FB88EC": {
|
113 | 119 | "Type": "AWS::IAM::Role",
|
114 | 120 | "Properties": {
|
|
169 | 175 | "Properties": {
|
170 | 176 | "Description": "AWS CloudFormation handler for \"Custom::S3BucketNotifications\" resources (@aws-cdk/aws-s3)",
|
171 | 177 | "Code": {
|
172 |
| - "ZipFile": "import boto3 # type: ignore\nimport json\nimport logging\nimport urllib.request\n\ns3 = boto3.client(\"s3\")\n\nEVENTBRIDGE_CONFIGURATION = 'EventBridgeConfiguration'\nCONFIGURATION_TYPES = [\"TopicConfigurations\", \"QueueConfigurations\", \"LambdaFunctionConfigurations\"]\n\ndef handler(event: dict, context):\n response_status = \"SUCCESS\"\n error_message = \"\"\n try:\n props = event[\"ResourceProperties\"]\n notification_configuration = props[\"NotificationConfiguration\"]\n managed = props.get('Managed', 'true').lower() == 'true'\n stack_id = event['StackId']\n old = event.get(\"OldResourceProperties\", {}).get(\"NotificationConfiguration\", {})\n if managed:\n config = handle_managed(event[\"RequestType\"], notification_configuration)\n else:\n config = handle_unmanaged(props[\"BucketName\"], stack_id, event[\"RequestType\"], notification_configuration, old)\n s3.put_bucket_notification_configuration(Bucket=props[\"BucketName\"], NotificationConfiguration=config)\n except Exception as e:\n logging.exception(\"Failed to put bucket notification configuration\")\n response_status = \"FAILED\"\n error_message = f\"Error: {str(e)}. \"\n finally:\n submit_response(event, context, response_status, error_message)\n\ndef handle_managed(request_type, notification_configuration):\n if request_type == 'Delete':\n return {}\n return notification_configuration\n\ndef handle_unmanaged(bucket, stack_id, request_type, notification_configuration, old):\n def get_id(n):\n n['Id'] = ''\n strToHash=json.dumps(n, sort_keys=True).replace('\"Name\": \"prefix\"', '\"Name\": \"Prefix\"').replace('\"Name\": \"suffix\"', '\"Name\": \"Suffix\"')\n return f\"{stack_id}-{hash(strToHash)}\"\n def with_id(n):\n n['Id'] = get_id(n)\n return n\n\n external_notifications = {}\n existing_notifications = s3.get_bucket_notification_configuration(Bucket=bucket)\n for t in CONFIGURATION_TYPES:\n if request_type == 'Update':\n old_incoming_ids = [get_id(n) for n in old.get(t, [])]\n external_notifications[t] = [n for n in existing_notifications.get(t, []) if not get_id(n) in old_incoming_ids] \n elif request_type == 'Delete':\n external_notifications[t] = [n for n in existing_notifications.get(t, []) if not n['Id'].startswith(f\"{stack_id}-\")]\n elif request_type == 'Create':\n external_notifications[t] = [n for n in existing_notifications.get(t, [])]\n if EVENTBRIDGE_CONFIGURATION in existing_notifications:\n external_notifications[EVENTBRIDGE_CONFIGURATION] = existing_notifications[EVENTBRIDGE_CONFIGURATION]\n\n if request_type == 'Delete':\n return external_notifications\n\n notifications = {}\n for t in CONFIGURATION_TYPES:\n external = external_notifications.get(t, [])\n incoming = [with_id(n) for n in notification_configuration.get(t, [])]\n notifications[t] = external + incoming\n\n if EVENTBRIDGE_CONFIGURATION in notification_configuration:\n notifications[EVENTBRIDGE_CONFIGURATION] = notification_configuration[EVENTBRIDGE_CONFIGURATION]\n elif EVENTBRIDGE_CONFIGURATION in external_notifications:\n notifications[EVENTBRIDGE_CONFIGURATION] = external_notifications[EVENTBRIDGE_CONFIGURATION]\n\n return notifications\n\ndef submit_response(event: dict, context, response_status: str, error_message: str):\n response_body = json.dumps(\n {\n \"Status\": response_status,\n \"Reason\": f\"{error_message}See the details in CloudWatch Log Stream: {context.log_stream_name}\",\n \"PhysicalResourceId\": event.get(\"PhysicalResourceId\") or event[\"LogicalResourceId\"],\n \"StackId\": event[\"StackId\"],\n \"RequestId\": event[\"RequestId\"],\n \"LogicalResourceId\": event[\"LogicalResourceId\"],\n \"NoEcho\": False,\n }\n ).encode(\"utf-8\")\n headers = {\"content-type\": \"\", \"content-length\": str(len(response_body))}\n try:\n req = urllib.request.Request(url=event[\"ResponseURL\"], headers=headers, data=response_body, method=\"PUT\")\n with urllib.request.urlopen(req) as response:\n print(response.read().decode(\"utf-8\"))\n print(\"Status code: \" + response.reason)\n except Exception as e:\n print(\"send(..) failed executing request.urlopen(..): \" + str(e))" |
| 178 | + "ZipFile": "import boto3 # type: ignore\nimport json\nimport logging\nimport urllib.request\n\ns3 = boto3.client(\"s3\")\n\nEVENTBRIDGE_CONFIGURATION = 'EventBridgeConfiguration'\nCONFIGURATION_TYPES = [\"TopicConfigurations\", \"QueueConfigurations\", \"LambdaFunctionConfigurations\"]\n\ndef handler(event: dict, context):\n response_status = \"SUCCESS\"\n error_message = \"\"\n try:\n props = event[\"ResourceProperties\"]\n notification_configuration = props[\"NotificationConfiguration\"]\n managed = props.get('Managed', 'true').lower() == 'true'\n skipDestinationValidation = props.get('SkipDestinationValidation', 'false').lower() == 'true'\n stack_id = event['StackId']\n old = event.get(\"OldResourceProperties\", {}).get(\"NotificationConfiguration\", {})\n if managed:\n config = handle_managed(event[\"RequestType\"], notification_configuration)\n else:\n config = handle_unmanaged(props[\"BucketName\"], stack_id, event[\"RequestType\"], notification_configuration, old)\n s3.put_bucket_notification_configuration(Bucket=props[\"BucketName\"], NotificationConfiguration=config, SkipDestinationValidation=skipDestinationValidation)\n except Exception as e:\n logging.exception(\"Failed to put bucket notification configuration\")\n response_status = \"FAILED\"\n error_message = f\"Error: {str(e)}. \"\n finally:\n submit_response(event, context, response_status, error_message)\n\ndef handle_managed(request_type, notification_configuration):\n if request_type == 'Delete':\n return {}\n return notification_configuration\n\ndef handle_unmanaged(bucket, stack_id, request_type, notification_configuration, old):\n def get_id(n):\n n['Id'] = ''\n strToHash=json.dumps(n, sort_keys=True).replace('\"Name\": \"prefix\"', '\"Name\": \"Prefix\"').replace('\"Name\": \"suffix\"', '\"Name\": \"Suffix\"')\n return f\"{stack_id}-{hash(strToHash)}\"\n def with_id(n):\n n['Id'] = get_id(n)\n return n\n\n external_notifications = {}\n existing_notifications = s3.get_bucket_notification_configuration(Bucket=bucket)\n for t in CONFIGURATION_TYPES:\n if request_type == 'Update':\n old_incoming_ids = [get_id(n) for n in old.get(t, [])]\n external_notifications[t] = [n for n in existing_notifications.get(t, []) if not get_id(n) in old_incoming_ids] \n elif request_type == 'Delete':\n external_notifications[t] = [n for n in existing_notifications.get(t, []) if not n['Id'].startswith(f\"{stack_id}-\")]\n elif request_type == 'Create':\n external_notifications[t] = [n for n in existing_notifications.get(t, [])]\n if EVENTBRIDGE_CONFIGURATION in existing_notifications:\n external_notifications[EVENTBRIDGE_CONFIGURATION] = existing_notifications[EVENTBRIDGE_CONFIGURATION]\n\n if request_type == 'Delete':\n return external_notifications\n\n notifications = {}\n for t in CONFIGURATION_TYPES:\n external = external_notifications.get(t, [])\n incoming = [with_id(n) for n in notification_configuration.get(t, [])]\n notifications[t] = external + incoming\n\n if EVENTBRIDGE_CONFIGURATION in notification_configuration:\n notifications[EVENTBRIDGE_CONFIGURATION] = notification_configuration[EVENTBRIDGE_CONFIGURATION]\n elif EVENTBRIDGE_CONFIGURATION in external_notifications:\n notifications[EVENTBRIDGE_CONFIGURATION] = external_notifications[EVENTBRIDGE_CONFIGURATION]\n\n return notifications\n\ndef submit_response(event: dict, context, response_status: str, error_message: str):\n response_body = json.dumps(\n {\n \"Status\": response_status,\n \"Reason\": f\"{error_message}See the details in CloudWatch Log Stream: {context.log_stream_name}\",\n \"PhysicalResourceId\": event.get(\"PhysicalResourceId\") or event[\"LogicalResourceId\"],\n \"StackId\": event[\"StackId\"],\n \"RequestId\": event[\"RequestId\"],\n \"LogicalResourceId\": event[\"LogicalResourceId\"],\n \"NoEcho\": False,\n }\n ).encode(\"utf-8\")\n headers = {\"content-type\": \"\", \"content-length\": str(len(response_body))}\n try:\n req = urllib.request.Request(url=event[\"ResponseURL\"], headers=headers, data=response_body, method=\"PUT\")\n with urllib.request.urlopen(req) as response:\n print(response.read().decode(\"utf-8\"))\n print(\"Status code: \" + response.reason)\n except Exception as e:\n print(\"send(..) failed executing request.urlopen(..): \" + str(e))" |
173 | 179 | },
|
174 | 180 | "Handler": "index.handler",
|
175 | 181 | "Role": {
|
|
0 commit comments