Skip to content
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

fix(integ-tests-alpha): optimize assertions handler size #26360

Closed
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

Large diffs are not rendered by default.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
{
"version": "32.0.0",
"files": {
"939278de4f3903a6b4bdb449b0e6f69208d04d53be21684b360f6410e8416231": {
"618fc075b4931b5a1dd4d257a0604152ada8eae3cad6807905d6901ec179f677": {
"source": {
"path": "asset.939278de4f3903a6b4bdb449b0e6f69208d04d53be21684b360f6410e8416231.bundle",
"path": "asset.618fc075b4931b5a1dd4d257a0604152ada8eae3cad6807905d6901ec179f677.bundle",
"packaging": "zip"
},
"destinations": {
"current_account-current_region": {
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
"objectKey": "939278de4f3903a6b4bdb449b0e6f69208d04d53be21684b360f6410e8416231.zip",
"objectKey": "618fc075b4931b5a1dd4d257a0604152ada8eae3cad6807905d6901ec179f677.zip",
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
}
}
},
"04f640bbe2d03b033525be6dbfd8cf75729dbf9720bc91e37045a300847a8104": {
"97ceceb47d60bd8b1fdf97533201dffd346e8c0830ece372061638cdd56d32fd": {
"source": {
"path": "lambdaintegrationDefaultTestDeployAssertAC2ED705.template.json",
"packaging": "file"
},
"destinations": {
"current_account-current_region": {
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
"objectKey": "04f640bbe2d03b033525be6dbfd8cf75729dbf9720bc91e37045a300847a8104.json",
"objectKey": "97ceceb47d60bd8b1fdf97533201dffd346e8c0830ece372061638cdd56d32fd.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 @@ -36,7 +36,7 @@
}
},
"expected": "{\"$ObjectLike\":{\"body\":{\"message\":\"Hello\"}}}",
"salt": "1687520682509"
"salt": "1689327791749"
},
"UpdateReplacePolicy": "Delete",
"DeletionPolicy": "Delete"
Expand Down Expand Up @@ -66,12 +66,12 @@
"SingletonFunction1488541a7b23466481b69b4408076b81HandlerCD40AE9F": {
"Type": "AWS::Lambda::Function",
"Properties": {
"Runtime": "nodejs14.x",
"Runtime": "nodejs18.x",
"Code": {
"S3Bucket": {
"Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}"
},
"S3Key": "939278de4f3903a6b4bdb449b0e6f69208d04d53be21684b360f6410e8416231.zip"
"S3Key": "618fc075b4931b5a1dd4d257a0604152ada8eae3cad6807905d6901ec179f677.zip"
},
"Timeout": 120,
"Handler": "index.handler",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,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}/04f640bbe2d03b033525be6dbfd8cf75729dbf9720bc91e37045a300847a8104.json",
"stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/97ceceb47d60bd8b1fdf97533201dffd346e8c0830ece372061638cdd56d32fd.json",
"requiresBootstrapStackVersion": 6,
"bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version",
"additionalDependencies": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -702,8 +702,8 @@
}
},
"constructInfo": {
"fqn": "constructs.Construct",
"version": "10.2.55"
"fqn": "@aws-cdk/integ-tests-alpha.AssertionsProvider",
"version": "0.0.0"
}
},
"Default": {
Expand Down Expand Up @@ -734,8 +734,8 @@
}
},
"constructInfo": {
"fqn": "constructs.Construct",
"version": "10.2.55"
"fqn": "@aws-cdk/integ-tests-alpha.HttpApiCall",
"version": "0.0.0"
}
},
"SingletonFunction1488541a7b23466481b69b4408076b81": {
Expand Down Expand Up @@ -796,14 +796,14 @@
}
},
"constructInfo": {
"fqn": "constructs.Construct",
"version": "10.2.55"
"fqn": "@aws-cdk/integ-tests-alpha.IntegTestCase",
"version": "0.0.0"
}
}
},
"constructInfo": {
"fqn": "constructs.Construct",
"version": "10.2.55"
"fqn": "@aws-cdk/integ-tests-alpha.IntegTest",
"version": "0.0.0"
}
},
"Tree": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,16 @@
import { CustomResourceHandler } from './base';
import { AwsApiCallRequest, AwsApiCallResult } from './types';
import { decode } from './utils';
import { getV3ClientPackageName, findV3ClientConstructor } from 'aws-cdk-lib/custom-resources';

// These functions defined at 'aws-cdk-lib/custom-resources'.
// However, '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.
// To avoid this issue, we using inject of esbuild (https://esbuild.github.io/api/#inject)
declare const getV3ClientPackageName: (clientName: string) => string;
declare const findV3ClientConstructor: (pkg: Object) => new (config: any) => {
send: (command: any) => Promise<any>;
config: any;
};

/**
* Flattens a nested object
Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/integ-tests-alpha/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
},
"scripts": {
"build": "cdk-build",
"bundle": "esbuild --bundle lib/assertions/providers/lambda-handler/index.ts --target=node14 --platform=node --outfile=lib/assertions/providers/lambda-handler.bundle/index.js",
"bundle": "esbuild --bundle lib/assertions/providers/lambda-handler/index.ts --target=node18 --platform=node --inject:../../aws-cdk-lib/custom-resources/lib/aws-custom-resource/runtime/utils.ts --outfile=lib/assertions/providers/lambda-handler.bundle/index.js",
"lint": "cdk-lint",
"package": "cdk-package",
"awslint": "cdk-awslint",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { AssertionRequest, AssertionResult, ExpectedResult } from '../../../../lib/assertions';
import { Match } from '../../../../lib/assertions/match';
import { getV3ClientPackageName, findV3ClientConstructor } from 'aws-cdk-lib/custom-resources';
import { AssertionHandler } from '../../../../lib/assertions/providers/lambda-handler/assertion';

function assertionHandler() {
Expand All @@ -9,6 +10,10 @@ function assertionHandler() {
return new AssertionHandler({} as any, context); // as any to ignore all type checks
}

// @ts-ignore
global.getV3ClientPackageName = getV3ClientPackageName;
// @ts-ignore
global.findV3ClientConstructor = findV3ClientConstructor;
beforeAll(() => {
jest.useFakeTimers();
jest.spyOn(console, 'log').mockImplementation(() => { return true; });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { CustomResourceHandler } from '../../../../lib/assertions/providers/lamb
import { mockClient } from 'aws-sdk-client-mock';
import { ListBucketsCommand, ListBucketsOutput, S3Client } from '@aws-sdk/client-s3';
import { SFNClient, StartExecutionCommand } from '@aws-sdk/client-sfn';
import { getV3ClientPackageName, findV3ClientConstructor } from 'aws-cdk-lib/custom-resources';
import 'aws-sdk-client-mock-jest';

interface MyHandlerRequest {
Expand All @@ -19,6 +20,10 @@ interface CloudFormationResponse extends Omit<AWSLambda.CloudFormationCustomReso
readonly Data: any;
}

// @ts-ignore
global.getV3ClientPackageName = getV3ClientPackageName;
// @ts-ignore
global.findV3ClientConstructor = findV3ClientConstructor;
const s3Mock = mockClient(S3Client);
const sfnMock = mockClient(SFNClient);
describe('CustomResourceHandler', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { DescribeInstancesCommand, EC2Client } from '@aws-sdk/client-ec2';
import { mockClient } from 'aws-sdk-client-mock';
import { AwsApiCallRequest, AwsApiCallResult } from '../../../../lib/assertions';
import { AwsApiCallHandler } from '../../../../lib/assertions/providers/lambda-handler/sdk';
import { getV3ClientPackageName, findV3ClientConstructor } from 'aws-cdk-lib/custom-resources';
import 'aws-sdk-client-mock-jest';

function sdkHandler() {
Expand All @@ -12,6 +13,10 @@ function sdkHandler() {
};
return new AwsApiCallHandler({} as any, context); // as any to ignore all type checks
}
// @ts-ignore
global.getV3ClientPackageName = getV3ClientPackageName;
// @ts-ignore
global.findV3ClientConstructor = findV3ClientConstructor;
beforeAll(() => {
jest.useFakeTimers();
jest.spyOn(console, 'log').mockImplementation(() => { return true; });
Expand Down