This is to repro the size and coldstart performance difference between the AWS JavaScript SDK v3.575.0 and v3.577.0
The lambda function does a simple ListTables
call to dynamodb and logs some metadata src/handler.mjs. It is frontend by a Lambda Function url.
The CDK stack uses esbuild to bundle the function and marks a few unnecessary packages as external per my previous investigation on the credentials providers. It doesn't do any minification. lib/sdk-577-thiccc-stack.mjs Enable the metafile option if you want to analyze the bundle which is output in cdk.out/asset.<xxxxx>/index.meta.json
when you do a npx cdk synth
.
I was seeing a larger difference in coldstarts in my app but I was using client-sts, client-iam, client-dynamodb and lib-dynamodb. This output shows a 24 ms increase in coldstart time and a 146435 byte increase in bundle size between 575 and 577. This is a small sample size of 3 runs, but you should be able to replicate this in your own account.
aws sdk | node version | avg(@initDuration) | bundleSize | # runs |
---|---|---|---|---|
3.575.0 | v20.13.1 | 246.79 | 316588 | 3 |
3.577.0 | v20.13.1 | 270.0433 | 463023 | 3 |
Update 6/6/2024
I am now including client-sts, client-iam, client-dynamodb and lib-dynamodb in the benchmark. Version 3.592 is close in performance to 3.575, but is almost 50 ms slower when you include more clients.
aws sdk | node version | avg(@initDuration) | bundleSize | # runs |
---|---|---|---|---|
3.568.0 | v20.13.1 | 213.5387 | 496644 | 8 |
3.575.0 | v20.13.1 | 269.3038 | 504269 | 8 |
3.592.0 | v20.13.1 | 265.4675 | 504954 | 8 |
npm install @aws-sdk/client-dynamodb@3.568.0 @aws-sdk/client-sts@3.568.0 @aws-sdk/client-iam@3.568.0 @aws-sdk/lib-dynamodb@3.568.0 --save-exact && npm update && npm ci && npx cdk deploy;
npm install @aws-sdk/client-dynamodb@3.575.0 @aws-sdk/client-sts@3.575.0 @aws-sdk/client-iam@3.575.0 @aws-sdk/lib-dynamodb@3.575.0 --save-exact && npm update && npm ci && npx cdk deploy;
npm install @aws-sdk/client-dynamodb@3.592.0 @aws-sdk/client-sts@3.592.0 @aws-sdk/client-iam@3.592.0 @aws-sdk/lib-dynamodb@3.592.0 --save-exact && npm update && npm ci && npx cdk deploy;
Once you've deployed the stack you can trigger a coldstart by hitting the url in the stack output. You need to switch between versions and hit the url to force a coldstart, multiple invocations of the same version won't necessarily trigger a coldstart.
Run the following CloudWatch Insights Query on /aws/lambda/ThicccBenchmark
to collate the results:
filter @message like /(Init Duration|"coldstart":true)/
| stats max(@initDuration) as `initDuration`, sortsfirst(sdkVersion) as @awsSdk, sortsFirst(size) as @bundleSize, sortsFirst(runtime), sortsFirst(node) as @node by coalesce(@requestId,requestId)
| display `initDuration`, `@awsSdk`, `@bundleSize`, @node
| stats avg(`initDuration`), max(`@bundleSize`), count(*) as runs by @awsSdk, @node
| order by `@awsSdk` asc
Or log into the console and hit this url and change the region as appropriate.
npx cdk destroy
Start docker then:
sam local invoke -t ./cdk.out/Sdk577ThicccStack.template.json Sdk577ThicccFunction
npx cdk deploy
deploy this stack to your default AWS account/regionnpx cdk diff
compare deployed stack with current statenpx cdk synth
emits the synthesized CloudFormation template