BT

AWS Lambda Now Supports Go for Serverless Applications

| by Sergio De Simone Follow 14 Followers on Jan 21, 2018. Estimated reading time: 1 minute |

Amazon has announced Go support for AWS Lambda, which opens the way to writing Go serverless applications running on AWS.

Go is the latest language Amazon is adding support for in AWS Lambda, along with Node.js, Python, Java, and C#.

To make your Go code ready for AWS deployment, it must reside in a handler function which is then passed to lambda.Start(). lambda.Start() does not return after being called and communicates with an internal Lambda endpoint to pass Invoke requests to the handler. The handler function must take between 0 and 2 arguments, which include the request object, and may return between 0 and 2 values, including an error object, e.g.:

// main.go
package main

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

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

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

AWS requires to compile Go code to be used in AWS Lambda for Linux and then zip it to make it ready for AWS Lambda deployment. This can be done, for example, running:

GOOS=linux go build -o main main.go
zip main.zip main

The name used for the zip file must match the Handler configuration property of the deployed Lambda function.

Once the code is packaged as a zip file, it can be deployed using the AWS CLI:

$ aws lambda create-function \
--region us-west-1 \
--function-name HelloFunction \
--zip-file fileb://./main.zip \
--runtime go1.x \
--tracing-config Mode=Active
--role arn:aws:iam::<account-id>:role/<role> \
--handler main

Additionally, AWS provides AWS X-Ray for Go, a set of libraries that enable the generation of trace data for the X-Ray daemon to analyze and debug your Go functions.

To make it easier for developers to use Go to develop AWS Lambda functions, Amazon has published a GitHub repository containing libraries, samples, and tools. You can get more details about testing, building, and deploying Go code to AWS Lambda here.

Rate this Article

Adoption Stage
Style

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Tell us what you think

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread
Community comments

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Discuss

Login to InfoQ to interact with what matters most to you.


Recover your password...

Follow

Follow your favorite topics and editors

Quick overview of most important highlights in the industry and on the site.

Like

More signal, less noise

Build your own feed by choosing topics you want to read about and editors you want to hear from.

Notifications

Stay up-to-date

Set up your notifications and don't miss out on content that matters to you

BT