Select Language:
If you’re hitting an out-of-memory error while building Go programs that include the AWS EC2 SDK on CodeBuild’s small build instances, you’re not alone. This issue typically pops up because the small instances only have 3 GB of memory, which isn’t enough for compiling the large EC2 SDK package.
Here’s a simple plan to fix this problem:
First, understand that it’s tough to make the compilation process use less memory for the EC2 package. The size and complexity of the package itself demand a lot of resources, and reducing parallel processing (like lowering GOMAXPROCS) doesn’t usually solve the problem, because the package is just too big.
The main reason for the problem is that the EC2 SDK package is much larger than other AWS service packages. This is because it covers a broad range of features and APIs, making it more demanding when it comes to memory during building.
The best and recommended solution is to upgrade to a medium-sized build instance—specifically, the BUILD_GENERAL1_MEDIUM. This instance has around 7 GB of memory, which is enough to compile the EC2 SDK package without running out of space.
There’s no quick setting change that can reduce the memory footprint enough to run this package on the smaller instances. The reality is, for projects needing the EC2 SDK, using a medium or larger build environment is necessary—even if it costs a little more.
If budgeting is a concern, consider restructuring your project. You could split the EC2-dependent parts into a separate module or repository and build that less frequently. Keep your core code on the smaller instances to keep costs down, but reserve the larger instances for tasks that need more memory.
In summary, upgrading your build environment to a medium instance provides the necessary resources to successfully compile the EC2 SDK. While it might be an extra expense, it’s the most reliable way to avoid build failures related to memory limits.
Sources:
– Troubleshooting AWS CodeBuild: https://docs.aws.amazon.com/codebuild/latest/userguide/troubleshooting.html
– Build environment compute types in AWS CodeBuild: https://docs.aws.amazon.com/codebuild/latest/userguide/build-env-ref-compute-types.html




