-
Notifications
You must be signed in to change notification settings - Fork 36
Deployment Package
Although not required, we recommand you review AWS Lambda Developer Guide first.
This document explains how to build your Go code into a single binary for the Lambda Execution Environment and create a zipped package ready for deployment.
Prerequisites:
It's worth noting that files and folders names are customizable at your convenience.
To create a standard project layout for a Lambda function in Go:
-
Create a project directory
lambda
. -
In the
lambda
directory, create a filehandler.go
with the following content:
package main
import (
"encoding/json"
"github.com/eawsy/aws-lambda-go/service/lambda/runtime"
)
func handle(evt json.RawMessage, ctx *runtime.Context) (interface{}, error) {
// Put your logic here
return nil, nil
}
func init() {
runtime.HandleFunc(handle)
}
func main() {}
-
Change directory to the project directory
lambda
. -
Read below section to build and package the project.
As the Lambda execution environment may differ from your development environment, the easiest way to build and package
your Lambda function in Go is to use eawsy/aws-lambda-go
Docker image.
docker run --rm eawsy/aws-lambda-go -help
# Usage of /usr/local/bin/entrypoint:
# -function string
# AWS Lambda function name (default "handler")
# -handler string
# AWS Lambda handler name (default "handle")
# -package string
# AWS Lambda package name (default "handler.zip")
# -nopackage
# Only build and do not create AWS Lambda package
The following command builds and packages your Lambda function with default options.
docker run --rm -v $GOPATH:/go -v $PWD:/tmp eawsy/aws-lambda-go
- Lambda function name:
handler
- Lambda handler name:
handle
- Lambda binary:
handler.so
- Lambda package:
handler.zip
You are free to use any combinations of the -function
, -handler
and -package
options to customize above defaults.
Be aware that any changes will affect the Lambda configuration. Also, if you alter Lambda function name (-function
)
and/or Lambda handler name (-handler
), you must update the Lambda configuration accordingly.
You can also prevent the automatic creation of the final zipped package by using the -nopackage
option. It then only
builds the Go code, creating a single binary called handler.so
. Then, you can create a custom zipped package.
Copyright 2016 Alsanium, SAS. or its affiliates. All rights reserved.
Source code licensed under the Apache License, Version 2.0.
Documentation licensed under the Creative Commons Attribution 4.0 International Public License.
[Getting Started](Getting Started)
- [Create](Getting Started#create-a-hello-world-lambda-function)
- [Invoke](Getting Started#invoke-the-lambda-function-manually)
- [Verify](Getting Started#verify-execution-results-and-logs)
[Programming Model](Programming Model)
- [Handler](Programming Model#handler)
- [Context](Programming Model#context)
- [Logging](Programming Model#logging)
- [Errors](Programming Model#errors)
[Deployment Package](Deployment Package)
- [Project](Deployment Package#project)
- [Package](Deployment Package#package)