-
Notifications
You must be signed in to change notification settings - Fork 156
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for replicating lambda serialization problems
- Loading branch information
1 parent
ba250f3
commit d815227
Showing
10 changed files
with
233 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
name: kms-alias | ||
runtime: nodejs | ||
description: Parallel Lambdas example |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#!/bin/bash | ||
|
||
set -euo pipefail | ||
|
||
temp_dir=$(mktemp -d) | ||
trap "rm -rf $temp_dir" EXIT | ||
pushd $temp_dir | ||
|
||
printf "const { version } = require(\"@aws-sdk/client-s3/package.json\");\n\nexports.handler = async () => ({ version });\n" > index.js | ||
dd if=/dev/urandom of=example.txt bs=25m count=1 | ||
zip lambda.zip index.js example.txt | ||
|
||
# Check the size of lambda.zip | ||
zip_size=$(stat -f %z lambda.zip) | ||
|
||
# Compare the size with 25MB (25 * 1024 * 1024 bytes) | ||
if [[ $zip_size -lt $((25 * 1024 * 1024)) ]]; then | ||
echo "lambda.zip is smaller than 25MB. Actual size $zip_size." | ||
exit 1 | ||
fi | ||
|
||
popd | ||
mv $temp_dir/lambda.zip . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// Copyright 2016-2018, Pulumi Corporation. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
import * as pulumi from "@pulumi/pulumi"; | ||
import * as aws from "@pulumi/aws"; | ||
import * as std from "@pulumi/std"; | ||
|
||
const config = new pulumi.Config("aws"); | ||
const providerOpts = { provider: new aws.Provider("prov", { region: <aws.Region>config.require("envRegion") }) }; | ||
|
||
const assumeRole = aws.iam.getPolicyDocument({ | ||
statements: [{ | ||
effect: "Allow", | ||
principals: [{ | ||
type: "Service", | ||
identifiers: ["lambda.amazonaws.com"], | ||
}], | ||
actions: ["sts:AssumeRole"], | ||
}], | ||
}, providerOpts); | ||
const role = new aws.iam.Role("parallel-iam-role", { | ||
assumeRolePolicy: assumeRole.then(assumeRole => assumeRole.json) | ||
}, providerOpts); | ||
|
||
const bucket = new aws.s3.BucketV2("lambda-code-storage", { | ||
forceDestroy: true, | ||
}, providerOpts); | ||
|
||
const versioning = new aws.s3.BucketVersioningV2("lambda-code-storage", { | ||
bucket: bucket.id, | ||
versioningConfiguration: { | ||
status: "Enabled", | ||
}, | ||
}, providerOpts); | ||
|
||
for (let i = 0; i < 50; i++) { | ||
const lambdaCode = new aws.s3.BucketObjectv2(`lambda-zip-${i}`, { | ||
bucket: bucket.bucket, | ||
key: `lambda-${i}.zip`, | ||
source: new pulumi.asset.FileAsset("lambda.zip"), | ||
sourceHash: std.filesha256({ | ||
input: "lambda.zip", | ||
}).then(invoke => invoke.result), | ||
}, {...providerOpts, dependsOn: [versioning]}); | ||
|
||
new aws.lambda.Function(`lambda-${i}`, { | ||
role: role.arn, | ||
handler: "index.handler", | ||
runtime: "nodejs20.x", | ||
s3Bucket: bucket.bucket, | ||
s3Key: lambdaCode.key, | ||
s3ObjectVersion: lambdaCode.versionId, | ||
}, { | ||
...providerOpts, | ||
ignoreChanges: ["replacementSecurityGroupIds"], | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"name": "parallel-lambdas-s3", | ||
"version": "0.0.1", | ||
"license": "Apache-2.0", | ||
"scripts": { | ||
"build": "tsc" | ||
}, | ||
"dependencies": { | ||
"@pulumi/pulumi": "^3.0.0", | ||
"@pulumi/aws": "^6.0.0", | ||
"@pulumi/std": "^1.6.2" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^8.0.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"compilerOptions": { | ||
"strict": true, | ||
"outDir": "bin", | ||
"target": "es2016", | ||
"module": "commonjs", | ||
"moduleResolution": "node", | ||
"sourceMap": true, | ||
"experimentalDecorators": true, | ||
"pretty": true, | ||
"noFallthroughCasesInSwitch": true, | ||
"noImplicitReturns": true, | ||
"forceConsistentCasingInFileNames": true | ||
}, | ||
"files": [ | ||
"index.ts" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
name: kms-alias | ||
runtime: nodejs | ||
description: Parallel Lambdas example |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#!/bin/bash | ||
|
||
set -euo pipefail | ||
|
||
temp_dir=$(mktemp -d) | ||
trap "rm -rf $temp_dir" EXIT | ||
pushd $temp_dir | ||
|
||
printf "const { version } = require(\"@aws-sdk/client-s3/package.json\");\n\nexports.handler = async () => ({ version });\n" > index.js | ||
dd if=/dev/urandom of=example.txt bs=25m count=1 | ||
zip lambda.zip index.js example.txt | ||
|
||
# Check the size of lambda.zip | ||
zip_size=$(stat -f %z lambda.zip) | ||
|
||
# Compare the size with 25MB (25 * 1024 * 1024 bytes) | ||
if [[ $zip_size -lt $((25 * 1024 * 1024)) ]]; then | ||
echo "lambda.zip is smaller than 25MB. Actual size $zip_size." | ||
exit 1 | ||
fi | ||
|
||
popd | ||
mv $temp_dir/lambda.zip . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Copyright 2016-2018, Pulumi Corporation. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
import * as pulumi from "@pulumi/pulumi"; | ||
import * as aws from "@pulumi/aws"; | ||
|
||
const config = new pulumi.Config("aws"); | ||
const providerOpts = { provider: new aws.Provider("prov", { region: <aws.Region>config.require("envRegion") }) }; | ||
|
||
const assumeRole = aws.iam.getPolicyDocument({ | ||
statements: [{ | ||
effect: "Allow", | ||
principals: [{ | ||
type: "Service", | ||
identifiers: ["lambda.amazonaws.com"], | ||
}], | ||
actions: ["sts:AssumeRole"], | ||
}], | ||
}, providerOpts); | ||
const role = new aws.iam.Role("parallel-iam-role", { | ||
assumeRolePolicy: assumeRole.then(assumeRole => assumeRole.json) | ||
}, providerOpts); | ||
|
||
for (let i = 0; i < 50; i++) { | ||
new aws.lambda.Function(`lambda-${i}`, { | ||
code: new pulumi.asset.FileArchive("lambda.zip"), | ||
role: role.arn, | ||
handler: "index.handler", | ||
runtime: "nodejs20.x", | ||
}, { | ||
...providerOpts, | ||
ignoreChanges: ["replacementSecurityGroupIds"], | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"name": "parallel-lambdas", | ||
"version": "0.0.1", | ||
"license": "Apache-2.0", | ||
"scripts": { | ||
"build": "tsc" | ||
}, | ||
"dependencies": { | ||
"@pulumi/pulumi": "^3.0.0", | ||
"@pulumi/aws": "^6.0.0", | ||
"@pulumi/std": "^1.6.2" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^8.0.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"compilerOptions": { | ||
"strict": true, | ||
"outDir": "bin", | ||
"target": "es2016", | ||
"module": "commonjs", | ||
"moduleResolution": "node", | ||
"sourceMap": true, | ||
"experimentalDecorators": true, | ||
"pretty": true, | ||
"noFallthroughCasesInSwitch": true, | ||
"noImplicitReturns": true, | ||
"forceConsistentCasingInFileNames": true | ||
}, | ||
"files": [ | ||
"index.ts" | ||
] | ||
} |