Skip to content

Commit

Permalink
feat: enable circuit breakers by default
Browse files Browse the repository at this point in the history
  • Loading branch information
trymtv committed Nov 11, 2024
1 parent 767522b commit 3382091
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/ecs/__tests__/__snapshots__/fargate-service.test.ts.snap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions src/ecs/fargate-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ export interface FargateServiceProps {
* @default false
*/
skipTargetGroup?: boolean
/**
* @default true
*/
enableCircuitBreaker?: boolean
}

export class FargateService extends constructs.Construct {
Expand All @@ -72,6 +76,16 @@ export class FargateService extends constructs.Construct {
) {
super(scope, id)

/**
* Set this flag to disable this stack creating a completely new service and attempting replace when enabling circuit breakers
* Mitigating the deploytment error: 'a service with the name <...> already exists'
* See: github.com/aws/aws-cdk/pull/22467
*/
this.node.setContext(
"@aws-cdk/aws-ecs:disableExplicitDeploymentControllerForCircuitBreaker",
true,
)

const parameters = new ConfigureParameters(this, {
ssmPrefix: `/liflig-cdk/${cdk.Stack.of(this).stackName}/${
this.node.addr
Expand Down Expand Up @@ -125,6 +139,8 @@ export class FargateService extends constructs.Construct {
hostPort: port,
})

const enableCircuitBreaker = props.enableCircuitBreaker ?? true

this.fargateService = new ecs.FargateService(this, "Service", {
serviceName: props.serviceName,
vpcSubnets: {
Expand All @@ -139,6 +155,12 @@ export class FargateService extends constructs.Construct {
securityGroups: [this.securityGroup],
platformVersion: ecs.FargatePlatformVersion.VERSION1_4,
enableExecuteCommand: true,
circuitBreaker: enableCircuitBreaker
? {
enable: true,
rollback: true,
}
: undefined,
...props.overrideFargateServiceProps,
})

Expand Down

0 comments on commit 3382091

Please sign in to comment.