Skip to content

Commit

Permalink
Add Lambda invocation example/test
Browse files Browse the repository at this point in the history
Part of #11.
  • Loading branch information
lukehoban committed Dec 17, 2021
1 parent cb10cd8 commit 2c13b9f
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 1 deletion.
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"
]
}

0 comments on commit 2c13b9f

Please sign in to comment.