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

Add Lambda invocation example/test #26

Merged
merged 1 commit into from
Dec 17, 2021
Merged
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ sdk/dotnet/version.txt
rsa*
password.txt
password2.txt
private_ip.txt
private_ip.txt
out.txt
13 changes: 13 additions & 0 deletions examples/examples_nodejs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,19 @@ func TestEc2RemoteTs(t *testing.T) {
integration.ProgramTest(t, &test)
}

func TestLambda(t *testing.T) {
test := getJSBaseOptions(t).
With(integration.ProgramTestOptions{
Dir: filepath.Join(getCwd(t), "lambda"),
ExtraRuntimeValidation: func(t *testing.T, stack integration.RuntimeValidationStackInfo) {
out, ok := stack.Outputs["output"].(string)
assert.True(t, ok)
assert.Len(t, out, 10)
},
})
integration.ProgramTest(t, &test)
}

func getJSBaseOptions(t *testing.T) integration.ProgramTestOptions {
base := getBaseOptions(t)
baseJS := base.With(integration.ProgramTestOptions{
Expand Down
3 changes: 3 additions & 0 deletions examples/lambda/Pulumi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
name: command-lambda
runtime: nodejs
description: A simple command example
21 changes: 21 additions & 0 deletions examples/lambda/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { local } from "@pulumi/command";
import * as aws from "@pulumi/aws";
import * as crypto from "crypto";

const f = new aws.lambda.CallbackFunction("f", {
publish: true,
callback: async (ev: any) => {
return crypto.randomBytes(ev.len/2).toString('hex');
}
});

const rand = new local.Command("execf", {
create: `aws lambda invoke --function-name "$FN" --payload '{"len": 10}' --cli-binary-format raw-in-base64-out out.txt >/dev/null && cat out.txt | tr -d '"' && rm out.txt`,
environment: {
FN: f.qualifiedArn,
AWS_REGION: aws.config.region!,
AWS_PAGER: "",
},
})

export const output = rand.stdout;
12 changes: 12 additions & 0 deletions examples/lambda/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "command-lambda",
"version": "0.1.0",
"devDependencies": {
"@types/node": "latest"
},
"dependencies": {
"@pulumi/aws": "^4.32.0",
"@pulumi/pulumi": "latest",
"@pulumi/random": "^4.2.0"
}
}
18 changes: 18 additions & 0 deletions examples/lambda/tsconfig.json
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"
]
}