Movatterモバイル変換


[0]ホーム

URL:


aws-lambda-go

module
v1.49.0Latest Latest
Warning

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

Go to latest
Published: May 23, 2025 License:Apache-2.0

Details

Repository

github.com/aws/aws-lambda-go

Links

README

AWS Lambda for Go

testsbuild-lambda-zipGo ReferenceGoCardcodecov

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

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

Getting Started

// main.gopackage mainimport ("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 Lambdalambda.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 theprovided,provided.al2, orprovided.al2023 runtime, the executable within the .zip file should be namedbootstrap. Lambda's default architecture isx86_64, so when cross compiling from a non-x86 environment, the executable should be built withGOARCH=amd64. Likewise, if the Lambda function will beconfigured to use ARM, the executable should built withGOARCH=arm64.

GOOS=linux GOARCH=amd64 go build -o bootstrap main.gozip 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 theCGO_ENABLED environment variable.

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

SeeUsing 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, thebuild-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 yourGOPATH. If you have a default installation of Go, the tool will be in%USERPROFILE%\Go\bin.

in cmd.exe:

set GOOS=linuxset GOARCH=amd64set CGO_ENABLED=0go 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 runtimeGLIBC version
provided.al20232.34
provided.al22.26
provided andgo1.x2.17

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

Deploying your functions

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

Event Integrations

Theevent models can be used to model AWS event sources. The official documentation hasdetailed walkthroughs.

Directories

PathSynopsis
cmd
handlertrace
Package handlertrace allows middleware authors using lambda.NewHandler to instrument request and response events.
Package handlertrace allows middleware authors using lambda.NewHandler to instrument request and response events.
Package lambdaurl serves requests from Lambda Function URLs using http.Handler.
Package lambdaurl serves requests from Lambda Function URLs using http.Handler.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f orF : Jump to
y orY : Canonical URL
go.dev uses cookies from Google to deliver and enhance the quality of its services and to analyze traffic.Learn more.

[8]ページ先頭

©2009-2025 Movatter.jp