Skip to content

feat(codebuild): add custom instance type and VPC to Fleets #34572

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

isker
Copy link
Contributor

@isker isker commented May 29, 2025

https://aws.amazon.com/about-aws/whats-new/2025/04/aws-codebuild-ec2-instance-type-configurable-storage-size/

CodeBuild now supports specifying specific EC2 instance types to serve as fleet compute.

Add this support to the Fleet construct by way of adding CUSTOM_INSTANCE_TYPE to the FleetComputeType enum, and instanceType to ComputeConfiguration.

Also, add VPC support to Fleet. This mirrors the VPC support in Project. When using Fleets, the VPC configured on the Project does nothing. Only the VPC on the Fleet applies. This required adding a Role to the Fleet to handle provisioning EC2 network interfaces in the configured VPC.

Describe any new or updated permissions being added

When configuring a VPC on a Fleet, IAM permissions are granted to a CodeBuild Role as described here.

Description of how you validated changes

Unit and integration tests.

Checklist


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@aws-cdk-automation aws-cdk-automation requested a review from a team May 29, 2025 01:13
@github-actions github-actions bot added p2 repeat-contributor [Pilot] contributed between 3-5 PRs to the CDK labels May 29, 2025
@@ -38,6 +89,7 @@ class FleetStack extends cdk.Stack {
}),
environment: {
buildImage: codebuild.LinuxBuildImage.STANDARD_7_0,
fleet: this.fleet,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@badmintoncryer when you added this integration test earlier this year, you weren't actually using the fleet in the test 🥲. It works now!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @isker
I had no idea that the configuration was wrong...

Comment on lines +541 to +542
However, when a build runs on a Fleet reserved instance, any VPC configuration
on the Project is not used - only the VPC configured on the Fleet has an effect.
Copy link
Contributor Author

@isker isker May 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docs are not very clear about this, but this is my understanding. I am trying to verify this experimentally but my CodeBuild access got suspended 🥲, I guess because I was creating and destroying so many Fleets without really using them. I am waiting for support to restore access... (case 174848040600299)

I am similarly trying to verify what the Fleet Role is used for. It's not clear whether it's used during builds instead of the Role on the Project, or whether it's just used by CodeBuild to attach network interfaces... if it's only the latter, maybe there's no point in exposing it from Fleet?

Comment on lines +40 to +44
// Incredibly, if you pass a SubnetSelection that produces more than 1
// subnet, you currently get this error:
// > Resource handler returned message: "Invalid vpc config: the maximum number of subnets is 1
// This seems like a terrible limitation from the CodeBuild team.
// maxAzs: 2,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is bad. If anyone at AWS can talk to the CodeBuild team... I've never seen another service that demands a single subnet like this. The CloudFormation types claim you can use "up to 16" but anything more than 1 fails at deploy time.

https://aws.amazon.com/about-aws/whats-new/2025/04/aws-codebuild-ec2-instance-type-configurable-storage-size/

CodeBuild now supports specifying specific EC2 instance types to serve
as fleet compute.

Add this support to the Fleet construct by way of adding
CUSTOM_INSTANCE_TYPE to the FleetComputeType enum, and `instanceType` to
`ComputeConfiguration`.

Also, add VPC support to Fleet. This mirrors the VPC support in Project.
When using Fleets, the VPC configured on the Project does nothing. Only
the VPC on the Fleet applies. This required adding a Role to the Fleet
to handle provisioning EC2 network interfaces in the configured VPC.
@isker isker force-pushed the codebuild-fleet-custom-instance-type-vpc branch from 28828ff to d7ab2f0 Compare May 29, 2025 02:13
@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv
  • Commit ID: d7ab2f0
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@aws-cdk-automation aws-cdk-automation added the pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. label May 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p2 pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. repeat-contributor [Pilot] contributed between 3-5 PRs to the CDK
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants