DEV Community

Caleb Frieze
Caleb Frieze

Posted on • Updated on

Deploying Go To AWS using CDK in 2024

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]
Enter fullscreen mode Exit fullscreen mode

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
    });
Enter fullscreen mode Exit fullscreen mode

(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
Enter fullscreen mode Exit fullscreen mode

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 
Enter fullscreen mode Exit fullscreen mode

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)