Skip to content

Commit

Permalink
[v15] AWS OIDC - Deploy ECS Service: increase number of replicas to 2 (
Browse files Browse the repository at this point in the history
…#37805)

* AWS OIDC - Deploy ECS Service: increase number of replicas to 2

This PR sets the number of replicas to 2 when starting a Database
Service using Amazon ECS.

This increases the availability of the service.

* Add task placement strategy note for fargate compute
  • Loading branch information
marcoandredinis committed Feb 7, 2024
1 parent 7b99f8d commit c408723
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions lib/integrations/awsoidc/deployservice.go
Expand Up @@ -43,8 +43,14 @@ var (
// requiredCapacityProviders contains the FARGATE type which is required to deploy a Teleport Service.
requiredCapacityProviders = []string{launchTypeFargateString}

// oneAgent is used to define the desired agent count when creating a service.
oneAgent = int32(1)
// twoAgents is used to define the desired agent count when creating a service.
// Deploying two agents in a FARGATE LaunchType Service, will most likely deploy
// each one in a different AZ, as long as the Subnets include mustiple AZs.
// From AWS Docs:
// > Task placement strategies and constraints aren't supported for tasks using the Fargate launch type.
// > Fargate will try its best to spread tasks across accessible Availability Zones.
// > https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task-placement.html#fargate-launch-type
twoAgents = int32(2)
)

const (
Expand Down Expand Up @@ -725,7 +731,7 @@ func upsertService(ctx context.Context, clt DeployServiceClient, req upsertServi

updateServiceResp, err := clt.UpdateService(ctx, &ecs.UpdateServiceInput{
Service: aws.String(req.ServiceName),
DesiredCount: &oneAgent,
DesiredCount: &twoAgents,
TaskDefinition: &taskARN,
Cluster: aws.String(req.ClusterName),
NetworkConfiguration: deployServiceNetworkConfiguration(req.SubnetIDs, req.SecurityGroups),
Expand All @@ -742,7 +748,7 @@ func upsertService(ctx context.Context, clt DeployServiceClient, req upsertServi

createServiceOut, err := clt.CreateService(ctx, &ecs.CreateServiceInput{
ServiceName: aws.String(req.ServiceName),
DesiredCount: &oneAgent,
DesiredCount: &twoAgents,
LaunchType: ecsTypes.LaunchTypeFargate,
TaskDefinition: &taskARN,
Cluster: aws.String(req.ClusterName),
Expand Down

0 comments on commit c408723

Please sign in to comment.