aws-go-lambda-gateway

command module
v0.0.0-...-925d7de Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 5, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

README

Deploy this example with Pulumi Deploy this example with Pulumi

AWS Golang Lambda with API Gateway

This example creates a lambda that does a simple ToUpper on the path input of an API request and returns it.

Prerequisites

  1. Install Pulumi
  2. Configure AWS credentials
  3. Install Go

Deploying the example

  1. Build the handler:

    • For developers on Linux and macOS:

      make build
      
    • For developers on Windows:

      • Get the build-lambda-zip tool:

        set GO111MODULE=on
        go.exe get -u github.com/aws/aws-lambda-go/cmd/build-lambda-zip
        
      • Use the tool from your GOPATH:

        set GOOS=linux
        set GOARCH=amd64
        set CGO_ENABLED=0
        go build -o handler\handler handler\handler.go
        %USERPROFILE%\Go\bin\build-lambda-zip.exe -o handler\handler.zip handler\handler
        
  2. Create a new stack, which is an isolated deployment target for this example:

    pulumi stack init
    
  3. Install dependencies:

    go mod download
    
  4. Set the AWS region to deploy into:

    pulumi config set aws:region us-west-2
    
  5. Deploy the stack:

    pulumi up
    
    Updating (dev):
        Type                           Name               Status
    +   pulumi:pulumi:Stack            go-lambda-dev      created
    +   ├─ aws:apigateway:RestApi      UpperCaseGateway   created
    +   ├─ aws:iam:Role                task-exec-role     created
    +   ├─ aws:apigateway:Resource     UpperAPI           created
    +   ├─ aws:iam:RolePolicy          lambda-log-policy  created
    +   ├─ aws:apigateway:Method       AnyMethod          created
    +   ├─ aws:lambda:Function         basicLambda        created
    +   ├─ aws:apigateway:Integration  LambdaIntegration  created
    +   ├─ aws:lambda:Permission       APIPermission      created
    +   └─ aws:apigateway:Deployment   APIDeployment      created
    
    Outputs:
        invocation URL: "https://<gateway-id>.execute-api.us-west-2.amazonaws.com/prod/{message}"
    
    Resources:
        + 10 created
    
    Duration: 29s
    
  6. Call the Lambda function from the CLI:

    curl https://<gateway-id>.execute-api.us-west-2.amazonaws.com/prod/helloworld
    
    HELLOWORLD
    

    From there, feel free to experiment. Simply making edits, rebuilding your handler, and running pulumi up will update your lambda.

Cleaning up

Once you're finished experimenting, tear down your stack's resources by destroying and removing it:

pulumi destroy
pulumi stack rm

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL