diff --git a/.gitignore b/.gitignore index f0e680fa..73c7e7c4 100644 --- a/.gitignore +++ b/.gitignore @@ -15,4 +15,5 @@ sdk/dotnet/version.txt rsa* password.txt password2.txt -private_ip.txt \ No newline at end of file +private_ip.txt +out.txt \ No newline at end of file diff --git a/examples/examples_nodejs_test.go b/examples/examples_nodejs_test.go index d037869f..2ae6c973 100644 --- a/examples/examples_nodejs_test.go +++ b/examples/examples_nodejs_test.go @@ -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{ diff --git a/examples/lambda/Pulumi.yaml b/examples/lambda/Pulumi.yaml new file mode 100644 index 00000000..238a2ea6 --- /dev/null +++ b/examples/lambda/Pulumi.yaml @@ -0,0 +1,3 @@ +name: command-lambda +runtime: nodejs +description: A simple command example diff --git a/examples/lambda/index.ts b/examples/lambda/index.ts new file mode 100644 index 00000000..ca12f98c --- /dev/null +++ b/examples/lambda/index.ts @@ -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; diff --git a/examples/lambda/package.json b/examples/lambda/package.json new file mode 100644 index 00000000..3e8cad9d --- /dev/null +++ b/examples/lambda/package.json @@ -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" + } +} diff --git a/examples/lambda/tsconfig.json b/examples/lambda/tsconfig.json new file mode 100644 index 00000000..2666e28e --- /dev/null +++ b/examples/lambda/tsconfig.json @@ -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" + ] +} \ No newline at end of file