Skip to content

Commit 625c3a4

Browse files
committed
Move WordPress tasks to Fargate
1 parent fceaf52 commit 625c3a4

File tree

3 files changed

+26
-21
lines changed

3 files changed

+26
-21
lines changed

theworld/terra/templates/apps/wordpress.yml

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,16 @@ Parameters:
3333
RootStackName: { Type: String }
3434
RootStackId: { Type: String }
3535
VpcId: { Type: AWS::EC2::VPC::Id }
36+
VpcPublicSubnet1Id: { Type: AWS::EC2::Subnet::Id }
37+
VpcPublicSubnet2Id: { Type: AWS::EC2::Subnet::Id }
38+
VpcPublicSubnet3Id: { Type: AWS::EC2::Subnet::Id }
3639
EcrImageTag: { Type: AWS::SSM::Parameter::Value<String> }
3740
AlbListenerRulePriorityPrefix: { Type: String }
38-
Aarch64AsgCapacityProviderName: { Type: String }
3941
MysqlHostname: { Type: String }
4042
ValkeyHostname: { Type: String }
4143
ValkeyPort: { Type: String }
4244
AlbAccessToken: { Type: AWS::SSM::Parameter::Value<String> }
45+
SharedEcsAsgInstanceSecurityGroupId: { Type: AWS::EC2::SecurityGroup::Id }
4346

4447
Conditions:
4548
IsProduction: !Equals [!Ref EnvironmentType, Production]
@@ -183,6 +186,7 @@ Resources:
183186
TargetGroupAttributes:
184187
- Key: deregistration_delay.timeout_seconds
185188
Value: "30"
189+
TargetType: ip
186190
Tags:
187191
- { Key: Name, Value: !Sub "${RootStackName}_wordpress" }
188192
- { Key: prx:meta:tagging-version, Value: "2021-04-07" }
@@ -261,24 +265,27 @@ Resources:
261265
WebEcsService:
262266
Type: AWS::ECS::Service
263267
Properties:
264-
CapacityProviderStrategy:
265-
- Base: 0
266-
CapacityProvider: !Ref Aarch64AsgCapacityProviderName
267-
Weight: 1
268268
Cluster: !Ref EcsClusterArn
269269
DeploymentConfiguration:
270270
MaximumPercent: 200
271271
MinimumHealthyPercent: 50
272272
DesiredCount: !If [IsProduction, 5, 1]
273273
EnableECSManagedTags: true
274274
EnableExecuteCommand: true
275+
LaunchType: FARGATE
275276
LoadBalancers:
276277
- ContainerName: !Ref kWebContainerName
277278
ContainerPort: !Ref kWebApplicationPort
278279
TargetGroupArn: !Ref WebTargetGroup
279-
PlacementConstraints:
280-
- Type: memberOf
281-
Expression: attribute:ecs.cpu-architecture == arm64
280+
NetworkConfiguration:
281+
AwsvpcConfiguration:
282+
AssignPublicIp: ENABLED
283+
SecurityGroups:
284+
- !Ref SharedEcsAsgInstanceSecurityGroupId
285+
Subnets:
286+
- !Ref VpcPublicSubnet1Id
287+
- !Ref VpcPublicSubnet2Id
288+
- !Ref VpcPublicSubnet3Id
282289
PropagateTags: TASK_DEFINITION
283290
Tags:
284291
- { Key: prx:meta:tagging-version, Value: "2021-04-07" }
@@ -308,9 +315,10 @@ Resources:
308315
WebTaskDefinition:
309316
Type: AWS::ECS::TaskDefinition
310317
Properties:
318+
Cpu: !If [IsProduction, 2048, 512] # 512 = 0.5 vCPU, 2048 = 2 vCPU, etc
319+
Memory: !If [IsProduction, 8192, 2048]
311320
ContainerDefinitions:
312-
- Cpu: 100 # Currently we don't use CPU reservations for anything meaningful
313-
Environment:
321+
- Environment:
314322
- Name: PRX_ENVIRONMENT
315323
Value: !Ref EnvironmentTypeLowercase
316324
- Name: DB_HOST
@@ -373,17 +381,10 @@ Resources:
373381
awslogs-group: !Ref WebTaskLogGroup
374382
awslogs-region: !Ref AWS::Region
375383
awslogs-stream-prefix: ecs
376-
# Memory and MemoryReservation values are based on current instances
377-
# sizes, ensuring that only 1 WordPress task is running on any
378-
# instance
379-
# Prod: c8g.xlarge => 8 GiB
380-
# Stag: t4g.small => 2 GiB
381-
Memory: !If [IsProduction, 7650, 1800]
382-
MemoryReservation: !If [IsProduction, 4111, 1111]
383384
Name: !Ref kWebContainerName
384385
PortMappings:
385386
- ContainerPort: !Ref kWebApplicationPort
386-
HostPort: 0
387+
Protocol: tcp
387388
Secrets:
388389
- Name: AUTH_KEY
389390
ValueFrom: !Sub /prx/${EnvironmentTypeAbbreviation}/Terra/The_World-WordPress/auth-key
@@ -416,7 +417,9 @@ Resources:
416417
- Name: DB_PASSWORD
417418
ValueFrom: !Sub /prx/${EnvironmentTypeAbbreviation}/Terra/The_World-WordPress/mysql/password
418419
ExecutionRoleArn: !GetAtt ExecutionRole.Arn
419-
NetworkMode: bridge
420+
NetworkMode: awsvpc
421+
RequiresCompatibilities:
422+
- FARGATE
420423
Tags:
421424
- { Key: prx:meta:tagging-version, Value: "2021-04-07" }
422425
- { Key: prx:cloudformation:stack-name, Value: !Ref AWS::StackName }

theworld/terra/templates/root.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,9 @@ Resources:
440440
EcsClusterName: !GetAtt SharedEcsClusterStack.Outputs.EcsClusterName
441441
EcsClusterArn: !GetAtt SharedEcsClusterStack.Outputs.EcsClusterArn
442442
VpcId: !GetAtt SharedVpcStack.Outputs.VpcId
443+
VpcPublicSubnet1Id: !GetAtt SharedVpcStack.Outputs.PublicSubnet1Id
444+
VpcPublicSubnet2Id: !GetAtt SharedVpcStack.Outputs.PublicSubnet2Id
445+
VpcPublicSubnet3Id: !GetAtt SharedVpcStack.Outputs.PublicSubnet3Id
443446
EcrImageTag: !Sub /prx/${EnvironmentTypeAbbreviation}/Terra/The_World-WordPress/pkg/docker-image-tag
444447
AlbListenerRulePriorityPrefix: !FindInMap [SharedAlbListenerRulePriorityMap, WordPress, prefix]
445448
EnvironmentType: !Ref EnvironmentType
@@ -448,11 +451,11 @@ Resources:
448451
RegionMode: !FindInMap [RegionModeMap, !Ref "AWS::Region", !Ref EnvironmentType]
449452
RootStackName: !Ref AWS::StackName
450453
RootStackId: !Ref AWS::StackId
451-
Aarch64AsgCapacityProviderName: !GetAtt SharedEcsAsgAarch64Stack.Outputs.CapacityProviderName
452454
MysqlHostname: !GetAtt SharedAuroraMysqlStack.Outputs.DbHostname
453455
ValkeyHostname: !GetAtt SharedValkeyStack.Outputs.CacheEndpointAddress
454456
ValkeyPort: !GetAtt SharedValkeyStack.Outputs.CacheEndpointPort
455457
AlbAccessToken: !Sub /prx/${EnvironmentTypeAbbreviation}/Terra/The_World-WordPress/alb-access-token
458+
SharedEcsAsgInstanceSecurityGroupId: !GetAtt SharedEcsAsgSecurityGroupStack.Outputs.InstanceSecurityGroupId
456459
Tags:
457460
"prx:meta:tagging-version": "2021-04-07"
458461
"prx:cloudformation:stack-name": !Ref AWS::StackName

theworld/terra/templates/shared-alb.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ Parameters:
2525
CertificateArn: { Type: String }
2626
MaintenanceMode: { Type: String, Default: "Off" }
2727

28-
2928
Conditions:
3029
IsProduction: !Equals [!Ref EnvironmentType, Production]
3130
IsMaintenanceMode: !Equals [!Ref MaintenanceMode, "On"]

0 commit comments

Comments
 (0)