With go.1x being a deprecated runtime in AWS, we need to start using the PROVIDED_AL2023
runtime. There are quite a few tutorials out there that go over deploying Go lambdas, so I wont cover the extreme detail. (I followed this one by Melkey btw ;)) This is meant to fill in the gap if you are getting this pesky error at runtime:
Error: Couldn't find valid bootstrap(s): [/var/task/bootstrap /opt/bootstrap]
Let's say you have a lambda function defined like this with CDK:
const myTestFunction = new lambda.Function(this, "myTestFunction", {
// This points to where your Go lambda lives
code: lambda.Code.fromAsset("lambdas"),
handler: "main",
runtime: lambda.Runtime.PROVIDED_AL2023 // Because GO_1_X is now deprecated
});
(this is also assuming your file structure follows Melkey's video)
If you were to just build your lambda like this:
GOOS=linux GOARCH=amd64 go build -o main
You will encounter the pesky bootstrap error. This is because AWS lambda looks for a bootstrap in the folder that you defined in your code block.
Simply change the out file to bootstrap
GOOS=linux GOARCH=amd64 go build -o bootstrap
AWS Lambda will now be able to see your built Go function and your function will be invoked properly.
There might be better ways to do this, but currently I'm new to Go and this worked for me! Hopefully this helps someone out!
Top comments (0)