简体   繁体   English

编译静态链接 GO 可执行文件以在 AWS 中使用 Lambda

[英]Compile Statically Linked GO Executable for use in 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. 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到这篇文章。)并通过向规则引擎程序发出 shell/os 命令的 Python Lambda function 包含/执行它。

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.问题:这个程序依赖于许多依赖项,为了尽可能少地处理问题,我想在上传到 AWS Lambda 之前静态链接程序并编译,以便所有必要的依赖项都包含在可执行文件本身中。

Question: How do I statically link then compile a program in Go such that I target the AWS Lambda OS?问题:我如何静态链接然后在 Go 中编译一个程序,以便我以 AWS Lambda 操作系统为目标?

This can be done via GOOS=linux go build.这可以通过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. Go 默认构建静态链接的可执行文件,因此只要针对正确的操作系统,您将获得在 AWS Lambda 上运行良好的二进制文件,而无需在部署 ZEFE90A8E604A7C840E88D03A67F6 中包含任何特定库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM