Skip to content

Support ECS managed instances capacity provider. - #2971

Draft
connoromalleyatwork wants to merge 4 commits into
mainfrom
cdk-managed-instances
Draft

connoromalleyatwork wants to merge 4 commits into
mainfrom
cdk-managed-instances

Conversation

@connoromalleyatwork

@connoromalleyatwork connoromalleyatwork commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

What does this change?

Before: GuLoadBalancedAppExperimental provisions only Fargate constructs for ECS (Elastic Container Service).
After: GuLoadBalancedAppExperimental can provision ECS Managed Instances to run ECS tasks and services instead of Fargate by passing managedInstancesProps: {}, in the ecsProps.

Why this change?

When investigating potentially using ECS Managed Instances instead of Fargate as part of ADR for ECS Managed Instances, it became clear that we need to learn more about Managed Instances by trying it out with an actual service.

Managed Instances can optimise the provisioned infrastructure over time for a given ECS cluster, and so the only way to understand the potential cost benefits for a given service is to try it in production.

How to Review

Tip

I recommend reviewing each commit in turn.

  • The first commit shows clearly what changes are required to switch from Fargate to managed instances.
  • The second commit adds the managedInstancesProps: {}, to ecsProps and pulls out the managed instance modifications into functions that are applied where needed. Instance

How to test

Check for regressions: Use the latest canary published from this branch in your project that uses theGuLoadBalancedAppExperimental construct causes no changes to the cloud formation templates created by cdk synth.

Check Managed Instances constructs are synthed: add managedInstancesProps: {}, in the ecsProps of GuLoadBalancedAppExperimental.

Checklist

  • I have updated the documentation as required for the described changes 1
  • I have listed any breaking changes, along with a migration path 2

Footnotes

  1. If you are adding a new construct or pattern, has new documentation been added? If you are amending defaults or changing behaviour, are the existing docs still valid? ↩

  2. Consider whether this is something that will mean changes to projects that have already been migrated, or to the CDK CLI tool. If changes are required, consider adding a checklist here and/or linking to related PRs. ↩

@changeset-bot

changeset-bot Bot commented Sep 22, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: ca37337

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@guardian/cdk Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@connoromalleyatwork connoromalleyatwork added feature Departmental tracking: work on a new feature 🐥 Canaries labels Sep 22, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Note

The following canaries were published to NPM:

🐥

@github-actions

Copy link
Copy Markdown
Contributor

Note

The following canaries were published to NPM:

🐥

@github-actions

Copy link
Copy Markdown
Contributor

Note

The following canaries were published to NPM:

🐥

@github-actions

Copy link
Copy Markdown
Contributor

Note

The following canaries were published to NPM:

🐥

@github-actions

Copy link
Copy Markdown
Contributor

Note

The following canaries were published to NPM:

🐥

@github-actions

Copy link
Copy Markdown
Contributor

Note

The following canaries were published to NPM:

🐥

@github-actions

Copy link
Copy Markdown
Contributor

Note

The following canaries were published to NPM:

🐥

@connoromalleyatwork
connoromalleyatwork force-pushed the cdk-managed-instances branch 3 times, most recently from 1887a5c to f6c2871 Compare September 28, 2026 08:49
@connoromalleyatwork
connoromalleyatwork force-pushed the cdk-managed-instances branch 6 times, most recently from a0c1473 to 3caf4b4 Compare October 9, 2026 09:12
@connoromalleyatwork
connoromalleyatwork marked this pull request as ready for review October 9, 2026 09:14
@connoromalleyatwork
connoromalleyatwork requested a review from a team as a code owner October 9, 2026 09:14
@github-actions

github-actions Bot commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

Note

The following canaries were published to NPM:

🐥

/**
* Use ECS Manages Instances instead of Fargate to run the app.
*/
useManagedInstances?: boolean;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Would it be more direct to provide the necessary configuration here, and use its presence/absence to decide whether to defer to Fargate?

At the moment we're hard-coding the instanceRequirements, but I think one of the benefits of this approach is the ability to specify an instance class. If so, perhaps we'd encourage teams to make an informed decision here, up front?

Equally, maybe we're happy to take charge of this for most teams - in which case offering a boolean for now might make sense if we imagine extending this in the future with something like boolean | specificConfigRequirements.

No dramas here, whatever you think is best.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Makes sense! I've opted for exposing the instanceRequirements as part of a new property managedInstancesProps whose presence means managed instances will be used for the app. The default instanceRequirements is the same as what was hard coded before.

I went for managedInstancesProps as we may want to expose some other settings in future.

@connoromalleyatwork connoromalleyatwork changed the title Switch to ECS managed instances capacity provider. Support ECS managed instances capacity provider. Oct 9, 2026
Comment thread src/experimental/patterns/gu-load-balanced-app.ts Outdated

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Default Fargate services regress to unrestricted egress, and new IAM roles lack required App tags.

1 open finding
What changed in this PR

Adds optional ECS Managed Instances support while retaining Fargate as the default.

Changes:

  • Adds useManagedInstances configuration and supporting ECS/IAM resources.
  • Runs existing ECS tests against both modes.
  • Adds snapshots and a minor changeset.
File Description
gu-load-balanced-app.ts Implements Managed Instances support.
gu-load-balanced-app.test.ts Exercises Fargate and Managed Instances.
gu-load-balanced-app.test.ts.snap Captures synthesized templates.
lovely-falcons-occur.md Records the feature release.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/experimental/patterns/gu-load-balanced-app.ts Outdated
@connoromalleyatwork
connoromalleyatwork force-pushed the cdk-managed-instances branch 2 times, most recently from ee81faa to aa90552 Compare October 20, 2026 09:05
Comment thread src/experimental/patterns/gu-load-balanced-app.ts Outdated
const ecsInstanceRolePolicy = ManagedPolicy.fromManagedPolicyArn(
scope,
"ECSInstanceRole",
"arn:aws:iam::aws:policy/AmazonECSInstanceRolePolicyForManagedInstances",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This role does seem somewhat broad, seemingly let the instance register with any cluster and submit task change events?

Non blocking, but the policy looks fairly basic, might be worth making a more explicit one.

@connoromalleyatwork connoromalleyatwork Oct 20, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

My thinking is we probably want the simplicity of using this policy since it is managed by AWS.

Capacity providers are cluster scoped according to this doc https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_CapacityProvider.html. This doesn't seam like it is reflected in the managed policy, so I'm not sure where this gets enforced.

I'll have a look into understanding how this is enforced by AWS.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

To enforce a capacity providers ec2 instances being scoped to a cluster i re created the policy and now it is scoped it only allows actions to a specific cluster, this means its a bit more secure now. 🔐

@connoromalleyatwork
connoromalleyatwork force-pushed the cdk-managed-instances branch 2 times, most recently from eb53f86 to 5b6b647 Compare October 20, 2026 10:43
@connoromalleyatwork
connoromalleyatwork marked this pull request as draft October 22, 2026 16:34

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature Departmental tracking: work on a new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants