为在AWS Lambda中使用的静态链接的GO可执行文件进行编译。

huangapple go评论75阅读模式
英文:

Compile Statically Linked GO Executable for use in AWS Lambda

问题

我正在尝试将一个Go程序(具体来说是Markus Kont的go-sigma-rule-engine)编译为可执行文件,以便我可以将其上传到AWS Lambda,并通过一个Python Lambda函数包含/执行它,该函数向规则引擎程序发出shell/os命令。

问题是,该程序依赖于许多依赖项,为了使其尽可能少出问题,我希望在上传到AWS Lambda之前静态链接并编译程序,以便所有必要的依赖项都包含在可执行文件本身中。

我的问题是,如何在Go中静态链接并编译程序,以便目标是AWS Lambda操作系统?

英文:

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?

答案1

得分: 1

这可以通过GOOS=linux go build .来完成。

Go默认会构建静态链接的可执行文件,只要正确地针对操作系统进行目标设置,你将获得一个在AWS Lambda上正常运行的二进制文件,而无需在部署包中包含任何特定的库。

英文:

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.

huangapple
  • 本文由 发表于 2021年12月14日 14:21:30
  • 转载请务必保留本文链接:https://go.coder-hub.com/70344544.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定