---
title: AWS Lambda Function in GoLang - Best Software Development Team Extension Partner for Nordics
description: AWS Lambda is a well known and great cloud Function as a Service (FaaS). And Google’s GoLang is a statically typed, compiled programming language. It is
---

[Blog - Trusted Team Extension Partner For Europe & USA](https://www.craftsmensoftware.com/blog)

# [AWS Lambda Function in GoLang - Best Software Development Team Extension Partner for Nordics](https://www.craftsmensoftware.com/blog/aws-lambda-function-in-golang)

 Written by [Mahmood Al Raihan](https://www.craftsmensoftware.com/blog/author/mahmood-al-raihan) | 03/04/2024

AWS **Lambda** is a well known and great cloud **Function as a Service** (FaaS). And Google’s **GoLang** is a statically typed, compiled programming language. It is widely popular for it is being super **fast** and it’s **built-in concurrency**.

In this blog post, we will discuss how we can use **GoLang in the AWS Lambda function**. In this demonstration, I’m using **Go1.15**. Following things are assumed:

- You know how to setup GoLang for development in Unix systems
- You are familiar with AWS Lambda

As **Go** is a compiled language, we cannot use the Lambda Function’s editor to edit the GoLang source code which we can do it in the case of scripting languages like Python, NodeJS, etc. In the case of Go, we will build the **main** function’s (the main function starts the lambda handler) file (cmd/main.go) which will create a **compiled executable** that is to be deployed to AWS Lambda.

Let’s see step by step how a GoLang function can be created and deployed to AWS Lambda. We will use the following **project structure** in this demo, but you can use any structure at your convenience.

```
 
```

## Lambda Handler

Let’s look at how **cmd/main.go** look like:

```
 
```

`github.com/aws/aws-lambda-go/lambda` is the **AWS SDK for GoLang**. `LambdaEvent` is used to store the event and this is a custom event. Instead of using this custom event, different AWS service specific events can be used. For AWS service specific events, `github.com/aws/aws-lambda-go/events` this package can be used. `LambdaResponse` is used to store the response to be returned.

## Some rules regarding the Lambda Handler are as follows:

- The Handler must be a function.
- The handler may take 0 to 2 arguments.
- If there is only one argument, it can be the context. Context, or an event from `github.com/aws/aws-lambda-go/events` this package or any custom event.
- If there are 2 arguments used, the first one must be `context.Context`.
- The handler may return 0 to 2 value.
- If there is only one value, it must implement `error`.
- If there are 2 return values, the second value must implement `error`.

## Valid Lambda Handler function signature:

- func ()
- func () error
- func () (TOut, error)
- func (TIn), error
- func (context.Context) error
- **func (TIn) (TOut, error)**
- func (context.Context) (TOut, error)
- func (context.Context, TIn) error
- func (context.Context, TIn) (TOut, error)

Here, `TIn` and `TOut` represent the **event** and **response** respectively.

**NOTE:** Global variables that are independent of your Lambda function’s handler code can be declared and modified. The handler may declare an `init` a function that is executed when your handler is loaded.

## Create Compiled Executable And Prepare It For AWS Lambda

- To build the executable, run the following command in the project root directory.

```
GOOS=linux go build cmd/main.go
```

 

`GOOS=linux` will ensure that the compiled executable is **Linux environment compatible**, even if it is built/compiled in a non-Linux environment. This command will create a compiled **executable** named **main** in the project root directory.

 

- Zip the compiled executable **main**.

```
zip function.zip main
```

## Create The Function

- Create the lambda function using the following command.

 

Replace `{account-id}` in the above command with your actual account id. You can use your own role ARN too.

 

## Test The Function

- Configure test event as follows

 

 

- Test the function. This will give **{ “message”: “Rayhan is 25 years old.” }** as a response.

## Lambda Layers

You may wonder that external package(s) (AWS GoLang SDK) has been used, but there are no **Lambda Layers** for the external packages. Actually, when the application is **compiled**, the **compiled executable includes all the external packages** used.

To get benefit from the AWS Lambda Layer, **GoLang Plugins** can be used. Golang Plugins is the feature released in the Go1.8. It allows you to dynamically load shared libraries (`.so` files). It gives you an opportunity to export some of your code to a separate library or use the plugin prepared and compiled by someone else.

The full project source code along with the Terraform configuration can be found [HERE](https://github.com/MhmdRyhn/lambda-function-in-golang).

Stay in Peace and Keep Coding!!!

## References

- [Building Lambda functions with Go](https://docs.aws.amazon.com/lambda/latest/dg/lambda-golang.html)
- [AWS Lambda function handler in Go](https://docs.aws.amazon.com/lambda/latest/dg/golang-handler.html)
- [AWS Lambda deployment package in Go](https://docs.aws.amazon.com/lambda/latest/dg/golang-package.html)
- [How to build pluggable Golang application and benefit from AWS Lambda Layers.](https://medium.com/nordcloud-engineering/how-to-build-pluggable-golang-application-and-benefit-from-aws-lambda-layers-154c8117df9b)

[View full post](https://www.craftsmensoftware.com/blog/aws-lambda-function-in-golang)

```json
{
  "@context" : "http://schema.org",
  "@type" : "BlogPosting",
  "author" : {
    "@type" : "Person",
    "name" : "Mahmood Al Raihan"
  },
  "dateModified" : "2026-04-30T08:34:40.201Z",
  "datePublished" : "2024-04-03T22:45:00Z",
  "headline" : "AWS Lambda Function in GoLang",
  "image" : {
    "@type" : "ImageObject",
    "height" : 386,
    "url" : "https://144957314.fs1.hubspotusercontent-eu1.net/hubfs/144957314/Imported_Blog_Media/AWS_Lambda_Function_in_Golang.webp",
    "width" : 687
  },
  "mainEntityOfPage" : "https://www.craftsmensoftware.com/blog/aws-lambda-function-in-golang",
  "publisher" : {
    "@type" : "Organization",
    "logo" : {
      "@type" : "ImageObject",
      "height" : 60,
      "url" : "/hs/hsstatic/content_shared_assets/static-1.4092/img/default-amp-logo.png",
      "width" : 60
    },
    "name" : "Blog"
  }
}
```