Skip to content
This repository has been archived by the owner on Jan 14, 2020. It is now read-only.

Deployment Package

Farzad Senart edited this page Nov 1, 2016 · 1 revision

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:

  1. Setup Go Environment.
  2. Setup Docker Engine.

Project

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:

  1. Create a project directory lambda.

  2. In the lambda directory, create a file handler.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() {}
  1. Change directory to the project directory lambda.

  2. Read below section to build and package the project.

Package

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.

Overview

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

Default

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

HelloWorld - Configure access

HelloWorld - Upload package

Custom

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.

Welcome

[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)

Contact

Clone this wiki locally