Skip to content


Switch branches/tags

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time

GitHub version npm version NuGet version PyPI version

Amazon Lambda Golang Construct

This library provides constructs for Golang (Go 1.11 and 1.12 because of go modules) Lambda functions.

Why? Read this blogpost


In Typescript:

npm i aws-lambda-golang --save
# or using yarn
yarn add aws-lambda-golang

In .NET:

dotnet add package rwilinski.GolangFunction --version 0.1.0

In Python using Pip:

pip install

In Java using Maven, add this to pom.xml:



In Typescript:

import * as golang from 'aws-lambda-golang'; // Import aws-lambda-golang module
import * as cdk from '@aws-cdk/core';
import * as apigateway from '@aws-cdk/aws-apigateway';

export class TestStackStack extends cdk.Stack {
  constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
    super(scope, id, props);

    // Define function. Source code should be located in ./test-function/main.go
    const backend = new golang.GolangFunction(this, 'test-function');
    const api = new apigateway.LambdaRestApi(this, 'myapi', {
      handler: backend,
      proxy: false,

    const items = api.root.addResource('items');

By default, the construct will use the name of the defining file and the construct's id to look up the entry file:

├── stack.ts # defines a 'GolangFunction' with 'my-handler' as id
├── stack/my-handler/main.go 
├── stack/my-handler/go.mod 
├── stack/my-handler/go.sum 

The simplest Golang function (stack/my-handler/main.go):

package main

import (

func handler(req events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) {
	fmt.Println("Received body: ", req.Body)

	return events.APIGatewayProxyResponse{
        StatusCode: http.StatusOK,
        Body:       "Hello from CDK GolangFunction!",
    }, nil

func main() {

Configuring build

The GolangFunction construct exposes some options via properties: buildCmd, buildDir, entry and handler, extraEnv.

By default, your Golang code is compiled using go build -ldflags="-s -w" command with GOOS=linux env variable.

🤝 Contributing

Contributions, issues and feature requests are welcome!
Feel free to check issues page.

Project sponsored by Dynobase