AWS Golang Lambda
Basic example of an AWS lambda
This example lives in the pulumi/examples repository. Check out just this directory to use it:
git clone --filter=blob:none --sparse https://github.com/pulumi/examples pulumi-examplesgit -C pulumi-examples sparse-checkout set aws-go-lambdacd pulumi-examples/aws-go-lambdaThis example creates an AWS Lambda function that does a simple ToUpper on the string input and returns it.
Deploying the App#
To deploy your infrastructure, follow the below steps.
Prerequisites#
Steps#
After cloning this repo, run these commands from the working directory:
-
Build the handler:
-
For developers on Linux and macOS:
Terminal window make build -
For developers on Windows:
-
Get the
build-lambda-ziptool:Terminal window set GO111MODULE=ongo.exe get -u github.com/aws/aws-lambda-go/cmd/build-lambda-zip -
Use the tool from your GOPATH:
Terminal window set GOOS=linuxset GOARCH=amd64set CGO_ENABLED=0go build -o handler\bootstrap handler\handler.go%USERPROFILE%\Go\bin\build-lambda-zip.exe -o handler\handler.zip handler\bootstrap
-
-
-
Create a new Pulumi stack, which is an isolated deployment target for this example:
Terminal window pulumi stack init -
Set the required configuration variables for this program:
Terminal window pulumi config set aws:region us-east-1 -
Execute the Pulumi program to create our lambda:
Terminal window pulumi up -
Call our Lambda function from the AWS CLI with “foo” as the payload:
Terminal window aws lambda invoke \--function-name $(pulumi stack output lambda) \--region $(pulumi config get aws:region) \--cli-binary-format raw-in-base64-out \--payload '"foo"' \output.jsoncat output.json # view the output file with your tool of choice# "FOO" -
From there, feel free to experiment. Simply making edits, rebuilding your handler, and running
pulumi upwill update your function. -
Afterwards, destroy your stack and remove it:
Terminal window pulumi destroy --yespulumi stack rm --yes