Skip to content

Support ECS managed instances capacity provider. - #2971

Open
connoromalleyatwork wants to merge 2 commits into
mainfrom
cdk-managed-instances
Open

connoromalleyatwork wants to merge 2 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.

GuLoadBalancedAppExperimental can also provision Fargate constructs and the instance role + profile for managed instances by passing provisionManagedSecurityRole: true in ecsProps. This means that in the case of a rollback from Managed Instances -> Fargate the rollback completes successfully. When the role is provisioned with fargate it is unused, and can be deleted later.

Amiable PR to prepare to move to managed instances: guardian/amiable#1013

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

  • First commit adds the code to optionally use managed instances, and causes no meaningful changes to the snapshot tests.
  • Second commit adds tests to ensure managed instances has no regressions from fargate.

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: db427b9

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
@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

Note

The following canaries were published to NPM:

🐥

@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

Note

The following canaries were published to NPM:

🐥

@connoromalleyatwork
connoromalleyatwork marked this pull request as ready for review November 2, 2026 14:34

@akash1810 akash1810 left a comment

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.

Summarising our IRL discussion: We're not planning on supporting Fargate and managed instances long term. We could refactor to make it easier to remove one of them once we've concluded which forms the paved road. For example:

  • Replace the multiple if/then branches with a single one. Its likely to result in an amount of code duplication though.
  • Adding TODO comments to remind ourselves which parts would be removed once we've come to a conclusion. For example, a comment on the aforementioned if/then branch and also around the IAM Role being created to facilitate rollback from managed to Fargate.

These refactors could be performed in this or a future PR - the tests will guide us through it.

@connoromalleyatwork
connoromalleyatwork force-pushed the cdk-managed-instances branch 4 times, most recently from 8de0f33 to e8dbf22 Compare November 6, 2026 10:25
@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

Note

The following canaries were published to NPM:

🐥

streamPrefix: [scope.stack, scope.stage, app, "devx-logs-sidecar"].join("/"),
logRetention: RetentionDays.ONE_DAY,
}),
if (!ecsProps.managedInstancesProps) {

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.

Either we

  • provision Fargate resources
  • provision Managed instances resource

The if statement is negated as i thought it would make the diff easier to read, but it hardly worked :(

logRetention: RetentionDays.ONE_DAY,
}),
if (!ecsProps.managedInstancesProps) {
// Fargate infrastructure

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.

The fargate infrastructure is unchanged, hence the first commit shows this because the test snapshot does not change with this code

// Other resources obtain this tag by extending `GuAppAwareConstruct`.
[cluster, taskDefinition, ecsService].forEach((_) => AppIdentity.taggedConstruct(props, _));
} else {
// Managed Instances infrastructure

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.

Managed instances infra starts here!

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.

5 participants