MCPcopy
hub / github.com/aws/aws-lambda-go

github.com/aws/aws-lambda-go @v1.54.0 sqlite

repository ↗ · DeepWiki ↗ · release v1.54.0 ↗
917 symbols 2,253 edges 166 files 330 documented · 36%
README

AWS Lambda for Go

tests Go Reference GoCard codecov

Libraries, samples, and tools to help Go developers develop AWS Lambda functions.

To learn more about writing AWS Lambda functions in Go, go to the official documentation

Getting Started

// main.go
package main

import (
    "github.com/aws/aws-lambda-go/lambda"
)

func hello() (string, error) {
    return "Hello λ!", nil
}

func main() {
    // Make the handler available for Remote Procedure Call by AWS Lambda
    lambda.Start(hello)
}

Building your function

Preparing a binary to deploy to AWS Lambda requires that it is compiled for Linux and placed into a .zip file. When using the provided, provided.al2, or provided.al2023 runtime, the executable within the .zip file should be named bootstrap. Lambda's default architecture is x86_64, so when cross compiling from a non-x86 environment, the executable should be built with GOARCH=amd64. Likewise, if the Lambda function will be configured to use ARM, the executable should built with GOARCH=arm64.

GOOS=linux GOARCH=amd64 go build -o bootstrap main.go
zip lambda-handler.zip bootstrap

For developers on Linux

On Linux, the Go compiler's default behavior is to link the output executable to the system libc for some standard library functionality (for example, DNS lookups). If the build environment is using a Linux distribution with a GNU libc version newer than the deployment environment, the application when deployed to Lambda may fail with an error like /lib64/libc.so.6: version `GLIBC_X.YZ' not found.

Most Go applications do not require linking to the system libc. This behavior can be disabled by using the CGO_ENABLED environment variable.

CGO_ENABLED=0 go build -o bootstrap main.go
zip lambda-handler.zip bootstrap

See Using CGO

For developers on Windows

Windows developers may have trouble producing a zip file that marks the binary as executable on Linux. To create a .zip that will work on AWS Lambda, the build-lambda-zip tool may be helpful.

Get the tool

go.exe install github.com/aws/aws-lambda-go/cmd/build-lambda-zip@latest

Use the tool from your GOPATH. If you have a default installation of Go, the tool will be in %USERPROFILE%\Go\bin.

in cmd.exe:

set GOOS=linux
set GOARCH=amd64
set CGO_ENABLED=0
go build -o bootstrap main.go
%USERPROFILE%\Go\bin\build-lambda-zip.exe -o lambda-handler.zip bootstrap

in Powershell:

$env:GOOS = "linux"
$env:GOARCH = "amd64"
$env:CGO_ENABLED = "0"
go build -o bootstrap main.go
~\Go\Bin\build-lambda-zip.exe -o lambda-handler.zip bootstrap

Using CGO

For applications that require CGO, the build environment must be using a GNU libc version installed compatible with the target Lambda runtime. Otherwise, execution may fail with errors like /lib64/libc.so.6: version `GLIBC_X.YZ' not found.

Lambda runtime GLIBC version
provided.al2023 2.34
provided.al2 2.26
provided and go1.x 2.17

Alternatively, Lambda supports container images as a deployment package alternative to .zip files. For more information, refer to the official documentation for working with with container images.

Deploying your functions

To deploy your function, refer to the official documentation for deploying using the AWS CLI, AWS Cloudformation, and AWS SAM.

Event Integrations

events package

The events package provides type definitions for common AWS event sources. The official documentation has detailed walkthroughs.

Extension points exported contracts — how you extend this code

Handler (Interface)
(no doc) [3 implementers]
lambda/handler.go
ContentType (Interface)
(no doc) [3 implementers]
lambda/invoke_loop.go
CustomResourceLambdaFunction (FuncType)
CustomResourceLambdaFunction is a standard form Lambda for a Custom Resource.
cfn/wrap.go
HandlerFunc (Interface)
HandlerFunc represents a valid input with two arguments and two returns as described by Start
lambda/entry_generic.go
LogOption (FuncType)
LogOption is a functional option for configuring the Lambda log handler.
lambdacontext/logger.go
BinaryHandler (FuncType)
(no doc)
cmd/build-lambda-zip/testdata/noop.go
Option (FuncType)
(no doc)
lambda/handler.go
SNSCustomResourceLambdaFunction (FuncType)
SNSCustomResourceLambdaFunction is a standard form Lambda for a Custom Resource that is triggered via a SNS topic.
cfn/wrap.go

Core symbols most depended-on inside this repo

Start
called by 38
lambda/entry.go
ReadJSONFromFile
called by 35
events/test/readjson.go
String
called by 26
events/code_commit.go
Write
called by 24
lambdaurl/http_handler.go
DataType
called by 24
events/attributevalue.go
Close
called by 22
lambda/handler.go
NewHandler
called by 16
lambda/handler.go
Number
called by 16
events/attributevalue.go

Shape

Function 417
Struct 345
Method 104
TypeAlias 35
FuncType 8
Interface 8

Languages

Go100%

Modules by API surface

events/cognito.go55 symbols
events/attributevalue.go47 symbols
events/apigw.go36 symbols
events/cognito_test.go25 symbols
events/apigw_test.go24 symbols
lambda/handler.go23 symbols
lambda/invoke_loop_test.go21 symbols
lambda/rpc_function_test.go20 symbols
lambda/handler_test.go18 symbols
events/codebuild.go17 symbols
events/attributevalue_test.go17 symbols
events/s3.go16 symbols

Dependencies from manifests, versioned

github.com/davecgh/go-spewv1.1.1 · 1×
github.com/pmezard/go-difflibv1.0.0 · 1×
gopkg.in/yaml.v3v3.0.1 · 1×

For agents

$ claude mcp add aws-lambda-go \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact