Home > Mobile >  Compile Statically Linked GO Executable for use in AWS Lambda
Compile Statically Linked GO Executable for use in AWS Lambda

Time:12-17

Context: I am trying to compile a Go program (Specifically, the go-sigma-rule-engine by Markus Kont) to an executable so that I can upload it to AWS Lambda (which is Amazon Linux 2 under the hood I believe, according to this post.) and include/execute it via a Python Lambda function that issues shell/os commands to the rule engine program.

Problem: This program relies on many dependencies and for it to work with as few issues as possible I would like to statically link the program and compile, before uploading to AWS Lambda, so that all necessary dependencies are included within the executable itself.

Question: How do I statically link then compile a program in Go such that I target the AWS Lambda OS?

CodePudding user response:

This can be done via GOOS=linux go build .

Go builds statically linked executables by default so as long as the correct OS is targeted, you will get a binary that runs fine on AWS Lambda without having to include any specific libraries in the deployment package.

  • Related