Skip to content

Commit

Permalink
fix(integ-tests-alpha): assertions handler is broken (aws#26400)
Browse files Browse the repository at this point in the history
## Summary
Assertions handler is too large and not working. This PR extracts the SDK v2 to v3 features into a separate package.
Reduces bundled size from `25.8mb` to `1.9mb` and restores the handlers functionality.

```bash
$ esbuild --bundle lib/assertions/providers/lambda-handler/index.ts --target=node14 --platform=node --outfile=lib/assertions/providers/lambda-handler.bundle/index.js

  lib/assertions/providers/lambda-handler.bundle/index.js  1.9mb ⚠️
```

## Why need this change?
After merged aws#26271, Assertions lambda function throw error at initialize phase and not working. This reason of problem is maybe to import `aws-cdk-lib/custom-resources` to use aws-sdk v2-v3 translate features. 
`aws-cdk-lib/custom-resources` exports the some constructs, so when import the package, then bundle size is too large and lambda function is not working.

```log
INIT_START Runtime Version: nodejs:18.v8	Runtime Version ARN: arn:aws:lambda:us-east-1::runtime:2755dc322c8dbb64760145d6403d14432af527bf4dd3cf03713aae10e0f8b552
--
2023-07-13T05:49:25.501Z	undefined	ERROR	Uncaught Exception     {
    "errorType": "TypeError",
    "errorMessage": "Class extends value undefined is not a constructor or null",
    "stack": [
        "TypeError: Class extends value undefined is not a constructor or null",
        "    at ../../aws-cdk-lib/core/lib/cfn-condition.ts (/var/task/index.js:796267:5)",
        "    at __init (/var/task/index.js:9:56)",
        "    at ../../aws-cdk-lib/core/lib/private/metadata-resource.ts (/var/task/index.js:807546:5)",
        "    at __init (/var/task/index.js:9:56)",
        "    at ../../aws-cdk-lib/core/lib/private/synthesis.ts (/var/task/index.js:814923:5)",
        "    at __init (/var/task/index.js:9:56)",
        "    at ../../aws-cdk-lib/core/lib/app.ts (/var/task/index.js:814951:5)",
        "    at __init (/var/task/index.js:9:56)",
        "    at ../../aws-cdk-lib/core/lib/stack.ts (/var/task/index.js:816555:5)",
        "    at __init (/var/task/index.js:9:56)"
    ]
}
START RequestId: b6da27f5-d7ff-4f76-807b-c7f5d1f02d1f Version: $LATEST
Unknown application error occurredRuntime.Unknown
END RequestId: b6da27f5-d7ff-4f76-807b-c7f5d1f02d1f
REPORT RequestId: b6da27f5-d7ff-4f76-807b-c7f5d1f02d1f	Duration: 13083.91 ms	Billed Duration: 13084 ms	Memory Size: 128 MB	Max Memory Used: 128 MB
```

## Solution

Extract the SDK v2 to v3 features into a new private package that can be bundled safely.
Also required changes to the `aws-custom-resource` v3 handler so it can used the shared code.
To make sure that the bundled files are free of start-up errors, I have added them into a post build script.

## Additional changes

**Update to Encode/Decode logic**
All parameters passed to a Custom Resource will be converted to string when passed to the Lambda Function handler. 
This is a feature/limitation by CloudFormation.
The previous implementation supported special handling for boolean values via a magic string.
However with the SDK v3 parameter types on API Calls are more strictly enforced, e.g. we can't pass a string anymore when a number is expected.
Therefore the encoding/decoding logic has been updated to indiscriminately encode _all_ parameters with `JSON.stringify()` and reverse the operation inside the assertions provider.

**Lambda Invoke Payload**
Withe the SDK v3, the type of the Payload returned from a Lambda Invoke operation is now a Buffer.
This makes sense from an SDK perspective since the returned payload might be a binary.
However assertions can only deal with JSON payloads, so we attempt to convert and parse the payload into a JSON object.
If that fails it stays unchanged.

## Acknowledgements 

Thanks @WinterYukky  for the initial investigation!

Closes aws#26359
Replaces aws#26360

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
mrgrain authored and bmoffatt committed Jul 28, 2023
1 parent 6d7b692 commit 19eaf43
Show file tree
Hide file tree
Showing 325 changed files with 176,093 additions and 3,516,967 deletions.

Large diffs are not rendered by default.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"version": "32.0.0",
"files": {
"2841832c06c010f8f491de8a2e5357d55f766b91e8f708a0be48f2aec8a8cc59": {
"f7d91914f95030cfcd15f2a885639afee6b7e6905cf2adb596fcaa7ac7f43e82": {
"source": {
"path": "integ-autoscalinghook-queue.template.json",
"packaging": "file"
},
"destinations": {
"current_account-current_region": {
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
"objectKey": "2841832c06c010f8f491de8a2e5357d55f766b91e8f708a0be48f2aec8a8cc59.json",
"objectKey": "f7d91914f95030cfcd15f2a885639afee6b7e6905cf2adb596fcaa7ac7f43e82.json",
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@
"VpcPublicSubnet1Subnet5C2D37C4": {
"Type": "AWS::EC2::Subnet",
"Properties": {
"VpcId": {
"Ref": "Vpc8378EB38"
},
"AvailabilityZone": {
"Fn::Select": [
0,
Expand All @@ -49,21 +46,24 @@
"Key": "Name",
"Value": "integ-autoscalinghook-queue/Vpc/PublicSubnet1"
}
]
],
"VpcId": {
"Ref": "Vpc8378EB38"
}
}
},
"VpcPublicSubnet1RouteTable6C95E38E": {
"Type": "AWS::EC2::RouteTable",
"Properties": {
"VpcId": {
"Ref": "Vpc8378EB38"
},
"Tags": [
{
"Key": "Name",
"Value": "integ-autoscalinghook-queue/Vpc/PublicSubnet1"
}
]
],
"VpcId": {
"Ref": "Vpc8378EB38"
}
}
},
"VpcPublicSubnet1RouteTableAssociation97140677": {
Expand All @@ -80,12 +80,12 @@
"VpcPublicSubnet1DefaultRoute3DA9E72A": {
"Type": "AWS::EC2::Route",
"Properties": {
"RouteTableId": {
"Ref": "VpcPublicSubnet1RouteTable6C95E38E"
},
"DestinationCidrBlock": "0.0.0.0/0",
"GatewayId": {
"Ref": "VpcIGWD7BA715C"
},
"RouteTableId": {
"Ref": "VpcPublicSubnet1RouteTable6C95E38E"
}
},
"DependsOn": [
Expand All @@ -107,15 +107,15 @@
"VpcPublicSubnet1NATGateway4D7517AA": {
"Type": "AWS::EC2::NatGateway",
"Properties": {
"SubnetId": {
"Ref": "VpcPublicSubnet1Subnet5C2D37C4"
},
"AllocationId": {
"Fn::GetAtt": [
"VpcPublicSubnet1EIPD7E02669",
"AllocationId"
]
},
"SubnetId": {
"Ref": "VpcPublicSubnet1Subnet5C2D37C4"
},
"Tags": [
{
"Key": "Name",
Expand All @@ -131,9 +131,6 @@
"VpcPublicSubnet2Subnet691E08A3": {
"Type": "AWS::EC2::Subnet",
"Properties": {
"VpcId": {
"Ref": "Vpc8378EB38"
},
"AvailabilityZone": {
"Fn::Select": [
1,
Expand All @@ -157,21 +154,24 @@
"Key": "Name",
"Value": "integ-autoscalinghook-queue/Vpc/PublicSubnet2"
}
]
],
"VpcId": {
"Ref": "Vpc8378EB38"
}
}
},
"VpcPublicSubnet2RouteTable94F7E489": {
"Type": "AWS::EC2::RouteTable",
"Properties": {
"VpcId": {
"Ref": "Vpc8378EB38"
},
"Tags": [
{
"Key": "Name",
"Value": "integ-autoscalinghook-queue/Vpc/PublicSubnet2"
}
]
],
"VpcId": {
"Ref": "Vpc8378EB38"
}
}
},
"VpcPublicSubnet2RouteTableAssociationDD5762D8": {
Expand All @@ -188,12 +188,12 @@
"VpcPublicSubnet2DefaultRoute97F91067": {
"Type": "AWS::EC2::Route",
"Properties": {
"RouteTableId": {
"Ref": "VpcPublicSubnet2RouteTable94F7E489"
},
"DestinationCidrBlock": "0.0.0.0/0",
"GatewayId": {
"Ref": "VpcIGWD7BA715C"
},
"RouteTableId": {
"Ref": "VpcPublicSubnet2RouteTable94F7E489"
}
},
"DependsOn": [
Expand All @@ -215,15 +215,15 @@
"VpcPublicSubnet2NATGateway9182C01D": {
"Type": "AWS::EC2::NatGateway",
"Properties": {
"SubnetId": {
"Ref": "VpcPublicSubnet2Subnet691E08A3"
},
"AllocationId": {
"Fn::GetAtt": [
"VpcPublicSubnet2EIP3C605A87",
"AllocationId"
]
},
"SubnetId": {
"Ref": "VpcPublicSubnet2Subnet691E08A3"
},
"Tags": [
{
"Key": "Name",
Expand All @@ -239,9 +239,6 @@
"VpcPrivateSubnet1Subnet536B997A": {
"Type": "AWS::EC2::Subnet",
"Properties": {
"VpcId": {
"Ref": "Vpc8378EB38"
},
"AvailabilityZone": {
"Fn::Select": [
0,
Expand All @@ -265,21 +262,24 @@
"Key": "Name",
"Value": "integ-autoscalinghook-queue/Vpc/PrivateSubnet1"
}
]
],
"VpcId": {
"Ref": "Vpc8378EB38"
}
}
},
"VpcPrivateSubnet1RouteTableB2C5B500": {
"Type": "AWS::EC2::RouteTable",
"Properties": {
"VpcId": {
"Ref": "Vpc8378EB38"
},
"Tags": [
{
"Key": "Name",
"Value": "integ-autoscalinghook-queue/Vpc/PrivateSubnet1"
}
]
],
"VpcId": {
"Ref": "Vpc8378EB38"
}
}
},
"VpcPrivateSubnet1RouteTableAssociation70C59FA6": {
Expand All @@ -296,21 +296,18 @@
"VpcPrivateSubnet1DefaultRouteBE02A9ED": {
"Type": "AWS::EC2::Route",
"Properties": {
"RouteTableId": {
"Ref": "VpcPrivateSubnet1RouteTableB2C5B500"
},
"DestinationCidrBlock": "0.0.0.0/0",
"NatGatewayId": {
"Ref": "VpcPublicSubnet1NATGateway4D7517AA"
},
"RouteTableId": {
"Ref": "VpcPrivateSubnet1RouteTableB2C5B500"
}
}
},
"VpcPrivateSubnet2Subnet3788AAA1": {
"Type": "AWS::EC2::Subnet",
"Properties": {
"VpcId": {
"Ref": "Vpc8378EB38"
},
"AvailabilityZone": {
"Fn::Select": [
1,
Expand All @@ -334,21 +331,24 @@
"Key": "Name",
"Value": "integ-autoscalinghook-queue/Vpc/PrivateSubnet2"
}
]
],
"VpcId": {
"Ref": "Vpc8378EB38"
}
}
},
"VpcPrivateSubnet2RouteTableA678073B": {
"Type": "AWS::EC2::RouteTable",
"Properties": {
"VpcId": {
"Ref": "Vpc8378EB38"
},
"Tags": [
{
"Key": "Name",
"Value": "integ-autoscalinghook-queue/Vpc/PrivateSubnet2"
}
]
],
"VpcId": {
"Ref": "Vpc8378EB38"
}
}
},
"VpcPrivateSubnet2RouteTableAssociationA89CAD56": {
Expand All @@ -365,12 +365,12 @@
"VpcPrivateSubnet2DefaultRoute060D2087": {
"Type": "AWS::EC2::Route",
"Properties": {
"RouteTableId": {
"Ref": "VpcPrivateSubnet2RouteTableA678073B"
},
"DestinationCidrBlock": "0.0.0.0/0",
"NatGatewayId": {
"Ref": "VpcPublicSubnet2NATGateway9182C01D"
},
"RouteTableId": {
"Ref": "VpcPrivateSubnet2RouteTableA678073B"
}
}
},
Expand All @@ -388,11 +388,11 @@
"VpcVPCGWBF912B6E": {
"Type": "AWS::EC2::VPCGatewayAttachment",
"Properties": {
"VpcId": {
"Ref": "Vpc8378EB38"
},
"InternetGatewayId": {
"Ref": "VpcIGWD7BA715C"
},
"VpcId": {
"Ref": "Vpc8378EB38"
}
}
},
Expand Down Expand Up @@ -521,8 +521,6 @@
"GroupASG3C6DFE3B": {
"Type": "AWS::AutoScaling::AutoScalingGroup",
"Properties": {
"MaxSize": "1",
"MinSize": "0",
"LaunchTemplate": {
"LaunchTemplateId": {
"Ref": "GroupLaunchTemplate9C55CCE4"
Expand All @@ -534,6 +532,8 @@
]
}
},
"MaxSize": "1",
"MinSize": "0",
"Tags": [
{
"Key": "Name",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"validateOnSynth": false,
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}",
"cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}",
"stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/2841832c06c010f8f491de8a2e5357d55f766b91e8f708a0be48f2aec8a8cc59.json",
"stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/f7d91914f95030cfcd15f2a885639afee6b7e6905cf2adb596fcaa7ac7f43e82.json",
"requiresBootstrapStackVersion": 6,
"bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version",
"additionalDependencies": [
Expand Down Expand Up @@ -260,15 +260,6 @@
"type": "aws:cdk:logicalId",
"data": "CheckBootstrapVersion"
}
],
"GroupLaunchConfigEA6271FF": [
{
"type": "aws:cdk:logicalId",
"data": "GroupLaunchConfigEA6271FF",
"trace": [
"!!DESTRUCTIVE_CHANGES: WILL_DESTROY"
]
}
]
},
"displayName": "integ-autoscalinghook-queue"
Expand All @@ -289,7 +280,7 @@
"validateOnSynth": false,
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}",
"cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}",
"stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/940d95f17af77e9d69bcd9a1d814bb63fb2753cb03fd1511bc6ea493b5f88f4c.json",
"stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/573c30608947fa5f0188c3157cdcb54a5dc5a8a38cff93afc9b9dedbf4bddab3.json",
"requiresBootstrapStackVersion": 6,
"bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version",
"additionalDependencies": [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
{
"version": "32.0.0",
"files": {
"36618132bd37b6b15f9987b57ad1fbf613f1ad937aec72381232b163ed9c44c4": {
"33cc97057bd20e4d2a8b75b52dc72cad7a3b45d78fa06a008ae302ab17b2075f": {
"source": {
"path": "asset.36618132bd37b6b15f9987b57ad1fbf613f1ad937aec72381232b163ed9c44c4.bundle",
"path": "asset.33cc97057bd20e4d2a8b75b52dc72cad7a3b45d78fa06a008ae302ab17b2075f.bundle",
"packaging": "zip"
},
"destinations": {
"current_account-current_region": {
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
"objectKey": "36618132bd37b6b15f9987b57ad1fbf613f1ad937aec72381232b163ed9c44c4.zip",
"objectKey": "33cc97057bd20e4d2a8b75b52dc72cad7a3b45d78fa06a008ae302ab17b2075f.zip",
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
}
}
},
"940d95f17af77e9d69bcd9a1d814bb63fb2753cb03fd1511bc6ea493b5f88f4c": {
"573c30608947fa5f0188c3157cdcb54a5dc5a8a38cff93afc9b9dedbf4bddab3": {
"source": {
"path": "queuehooktestDefaultTestDeployAssertCF5493DF.template.json",
"packaging": "file"
},
"destinations": {
"current_account-current_region": {
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
"objectKey": "940d95f17af77e9d69bcd9a1d814bb63fb2753cb03fd1511bc6ea493b5f88f4c.json",
"objectKey": "573c30608947fa5f0188c3157cdcb54a5dc5a8a38cff93afc9b9dedbf4bddab3.json",
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
}
}
Expand Down
Loading

0 comments on commit 19eaf43

Please sign in to comment.