- Newest
- Most votes
- Most comments
Based on your description, you're encountering an out-of-memory (OOM) issue when compiling Go programs that import the AWS EC2 SDK on CodeBuild's BUILD_GENERAL1_SMALL instances.
The issue you're experiencing is likely due to the limited disk space and memory available in the BUILD_GENERAL1_SMALL compute type. This compute type provides only 3 GB of memory, which appears insufficient for compiling the particularly large EC2 service package in the AWS SDK for Go.
To address your questions:
-
There isn't a straightforward way to significantly reduce memory usage when compiling the aws-sdk-go-v2/service/ec2 package, as the memory requirements are largely determined by the package's size and complexity.
-
While you've already tried reducing GOMAXPROCS, which was a good approach, the EC2 package is likely too large for the available memory regardless of parallelism settings.
-
The EC2 service package is indeed exceptionally large compared to other AWS service packages due to the comprehensive API surface area of EC2. This makes it more memory-intensive during compilation.
-
Your current workaround of using BUILD_GENERAL1_MEDIUM is the recommended solution. This compute type provides 7 GB of memory, which is sufficient for compiling the EC2 service package.
Unfortunately, there's no magic configuration that will allow the EC2 SDK to compile in the smaller environment. The recommended solution is to continue using the BUILD_GENERAL1_MEDIUM compute type for projects that require the EC2 service package. While this does increase costs, it's necessary to provide the resources required for compilation.
If cost is a significant concern, you might consider structuring your project to separate EC2-dependent code into a separate module or repository that's built less frequently, while keeping your main codebase on the smaller compute type.
Sources
Troubleshooting AWS CodeBuild - AWS CodeBuild
Build environment compute modes and types - AWS CodeBuild
Relevant content
- AWS OFFICIALUpdated a year ago
