Multiple build tools / runtimes on CodeBuild Lambda Compute

0

I'm trying to setup CodeBuild Lambda compute for faster builds vs the regular CodeBuild compute.

I wish there was a AMAZON_LINUX_2_ALL that included all of the different runtimes. I am using AMAZON_LINUX_2_DOTNET_6, but I have the following issues: I need AWS CLI and CDK which installs needs NPM/NodeJS. And I need a java runtime to run DynamoDB Local (on my unit test CodeBuild project) And I need .NET in order to build/test my code.

The documentation says "AWS Lambda doesn't support tools that require root permissions. For tools such as yum or rpm, use the EC2 compute type or other tools that don't require root permissions."

Is there a reason I couldn't install extra runtimes during install phase? Does anyone have an easy way to script installation of other runtimes from CodeBuild in a way that is compatible with the CodeBuild Lambda Compute type?

asked 3 months ago217 views
2 Answers
3

Hi Dan, CodeBuild now supports custom image for Lambda Compute: https://aws.amazon.com/about-aws/whats-new/2024/03/aws-codebuild-custom-images-lambda-compute/. You can pre-install extra runtimes into your custom image and use that in CodeBuild, thanks.

AWS
Zhen Li
answered a month ago
0

It is possible to install multiple runtimes and tools on CodeBuild's Lambda compute type, but it requires some additional scripting and packaging compared to the managed images. Here are a couple options:

  1. Create a custom Lambda layer that contains all the runtimes and tools you need, and reference that layer in your CodeBuild project. The layer can include binaries for Node, Java, .NET, etc. as well as any CLI tools.

  2. Use the CodeBuild pre-build phase to run a script that downloads and installs the required runtimes and tools into the /opt folder. Then zip up the /opt folder and use it as the primary source for the build phase.

  3. Create a Docker image with all the tools and runtimes pre-installed, upload to ECR, and use that for your CodeBuild environment image. More complex but gives you full control.

The key considerations are:

  • Everything must be contained in the /opt folder which persists between builds. Can't install globally.

  • Scripts and binaries have to be packaged up or layered in. Can't rely on yum/apt.

  • Need to be careful of file permissions and access without root.

So it's definitely possible but requires more custom setup than managed images. Let me know if you have any other questions!

AWS
Saad
answered 3 months ago
  • Thanks for the quick response, I've been a bit distracted this week with other fires to put out... Following up, I haven't seen any documentation regarding custom layers on CodeBuild Lambda compute... Last I read, I've seen no mention of layers/custom images being used for CodeBuild's lambda, so both options #1 and #3 are confusing me.

    Regarding #2, is there an example of using CodeBuild buildspec to install tools in this context? I already use CodeBuild to untar DynamoDB local and run it, but I don't have to worry about the "key considerations" list, and I feel like not having done this before it will be a lot of time consuming trial and error to get it right

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions