I’ve been learning a little bit of golang as of late, and I wanted to run it on AWS Lambda. I had a couple errors come up about my libc, and learned that I need to build my applications on Amazon Linux, so they can run on lambda. I didn’t want to set up a CodeBuild just to play with a few toy example programs or setup a couple docker containers. In fact we don’t even need to since AWS provides CloudShell, a complete shell environment available to every user of an AWS account.
If execution is attempted with a go binary not built on Amazon Linux, some of the following errors might look familar. Especially the missing libc versions and the higher than expected billed duration.
There’s a couple problems that must be resolved first though. The home directory in CloudShell is really small with only 1GB available, and golang requires downloading a lot of large packages. Also any package that are installed into the image are blown away afterwards. However the system disk is much bigger at a generous 30GB. This can be resolved by creating a new directory outside of home, and setting the GOPATH to this directory.
So to setup golang the following commands are ran. I recommend putting them into a file to source each time the cloudshell environment is sourced. It’s be sourced not run, as certain environment variables need to be set.
If you have any go binaries you want to include in the
PATH, then it should
also be updated, but I do not have any such utilities. After running the
build should work perfectly with your project. We’ll use the example lambda
function from aws-lambda-go, and my pared down configuration located
It should be pretty self explainatory, but you might run into issues with aws cli v2, as mentioned in this issue.
I hope you’ve found this post informative and useful, and that’s it for now.