forked from HarshGajabi/r-place_clone
-
Notifications
You must be signed in to change notification settings - Fork 0
/
template.yaml
896 lines (831 loc) · 32.2 KB
/
template.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
AWSTemplateFormatVersion: "2010-09-09"
Description: "CloudFormation template for r/place"
Parameters:
S3BucketName:
Type: String
Description: The name of the S3 bucket for r/place static content
Default: "rplace-static"
LoadBalancerName:
Type: String
Description: The name of the load balancer
Default: "wssLoadBalancer"
LoadBalancerSecurityGroupName:
Type: String
Description: The name of the security group for the load balancer
Default: "LoadBalancerSecurityGroup"
ElasticTargetGroupName:
Type: String
Description: The name of the target group for the load balancer
Default: "wssTG"
wssECSServiceSecurityGroupName:
Type: String
Description: The name of the security group for the ECS service
Default: "wssECSServiceSecurityGroup"
RedisSecurityGroupName:
Type: String
Description: The name of the security group for the redis cluster
Default: "RedisElasticache"
ECSClusterName:
Type: String
Description: The name of the ECS cluster
Default: "Place"
ECSServiceName:
Type: String
Description: The name of the ECS service
Default: "wssService"
ECSTaskContainerName:
Type: String
Description: The name of the ECS task container
Default: "webSockerServer"
ECSTaskFamily:
Type: String
Description: The name of the ECS task family
Default: "webSockerServer"
DynamoBoardTableName:
Type: String
Description: The name of the DynamoDB table for the board
Default: "board"
DynamoUserTableName:
Type: String
Description: The name of the DynamoDB table for the users
Default: "user"
ElastiCacheReplicationGroupID:
Type: String
Description: The id of the ElastiCache replication group
Default: "place"
SNSTopicName:
Type: String
Description: The name of the SNS topic
Default: "client-broadcast"
CloudFrontCachePolicyName:
Type: String
Description: The name of the CloudFront cache policy
Default: "apiCloudfrontCache"
ElastiCacheUserID:
Type: String
Description: The id of the ElastiCache user
Default: "default"
EC2KeyPairName:
Type: String
Description: The name of the EC2 key pair
Default: "HarshMac"
EC2KeyPublic:
Type: String
Description: The public key of the EC2 key pair
Default: ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDUYGrSFy8SJxxxIKMNXG/i4MageRQETDMSXz+LVNYNqUzNdzgv3cf6WdUsDJ3A3xafBI1fx4LnGiFVpQaKliFJANOH4kioihKAieJwACF2XvHtfzDehl3WT1ODZ8lGVWDcctUdLuYr8c0vge2cvFKmCYE+WWxyApbmb7YIiTSLIUSNToVddf+7N2d09ToBJ2FwH7A8aheJejectncItUzxSFxUr6rQeNrCDDJR3+4sQGNMvUwHqbKCrF7KnZ3ggxATuX2x2ckDw2a3F1YwfuKgPyRnNbnFMgvNQRJuISDindv7ciNuEsrKAa0rBPmEaNtLlI2F+jTXh65O7SD2IrDD [email protected]
setBoardPixelDynamoDBLambdaFunctionName:
Type: String
Description: The name of the lambda function to set the board pixel in DynamoDB
Default: "setBoardPixelDynamoDB"
setUserTimestampDynamoDBLambdaFunctionName:
Type: String
Description: The name of the lambda function to set the user timestamp in DynamoDB
Default: "setUserTimestampDynamoDB"
Resources:
EC2VPC:
Type: "AWS::EC2::VPC"
Properties:
CidrBlock: "172.31.0.0/16"
EnableDnsSupport: true
EnableDnsHostnames: true
InstanceTenancy: "default"
EC2SecurityGroup:
Type: "AWS::EC2::SecurityGroup"
Properties:
GroupDescription: "The load balancer for the internet-facing security group"
GroupName: !Ref LoadBalancerSecurityGroupName
VpcId: !Ref EC2VPC
SecurityGroupIngress:
-
CidrIp: "0.0.0.0/0"
Description: "Internet facing port 3000"
FromPort: 3000
IpProtocol: "tcp"
ToPort: 3000
SecurityGroupEgress:
-
DestinationSecurityGroupId: !Ref EC2SecurityGroup2
Description: "Allow traffic to the ECS container security group"
FromPort: 3000
IpProtocol: "tcp"
ToPort: 3000
EC2SecurityGroup2:
Type: "AWS::EC2::SecurityGroup"
Properties:
GroupDescription: "SG for wss ECS service"
GroupName: !Ref wssECSServiceSecurityGroupName
VpcId: !Ref EC2VPC
SecurityGroupIngress:
-
SourceSecurityGroupId: !Sub "${ElasticLoadBalancingV2LoadBalancer.SecurityGroups}"
SourceSecurityGroupOwnerId: !Ref AWS::AccountId
Description: "Allow traffic from the loadbalancer sg"
FromPort: 3000
IpProtocol: "tcp"
ToPort: 3000
SecurityGroupEgress:
-
CidrIp: "0.0.0.0/0"
IpProtocol: "-1"
EC2Subnet:
Type: "AWS::EC2::Subnet"
Properties:
AvailabilityZone: !Sub "${AWS::Region}a"
CidrBlock: "172.31.0.0/20"
VpcId: !Ref EC2VPC
MapPublicIpOnLaunch: true
EC2Subnet2:
Type: "AWS::EC2::Subnet"
Properties:
AvailabilityZone: !Sub "${AWS::Region}c"
CidrBlock: "172.31.32.0/20"
VpcId: !Ref EC2VPC
MapPublicIpOnLaunch: true
EC2Subnet3:
Type: "AWS::EC2::Subnet"
Properties:
AvailabilityZone: !Sub "${AWS::Region}b"
CidrBlock: "172.31.16.0/20"
VpcId: !Ref EC2VPC
MapPublicIpOnLaunch: true
ElasticLoadBalancingV2LoadBalancer:
Type: "AWS::ElasticLoadBalancingV2::LoadBalancer"
Properties:
Name: !Ref LoadBalancerName
Scheme: "internet-facing"
Type: "application"
Subnets:
- !Ref EC2Subnet3
- !Ref EC2Subnet2
- !Ref EC2Subnet
SecurityGroups:
- "sg-0bdafb39355b2597f"
IpAddressType: "ipv4"
LoadBalancerAttributes:
-
Key: "access_logs.s3.enabled"
Value: "false"
-
Key: "idle_timeout.timeout_seconds"
Value: "60"
-
Key: "deletion_protection.enabled"
Value: "false"
-
Key: "routing.http2.enabled"
Value: "true"
-
Key: "routing.http.drop_invalid_header_fields.enabled"
Value: "false"
-
Key: "routing.http.xff_client_port.enabled"
Value: "false"
-
Key: "routing.http.preserve_host_header.enabled"
Value: "false"
-
Key: "routing.http.xff_header_processing.mode"
Value: "append"
-
Key: "load_balancing.cross_zone.enabled"
Value: "true"
-
Key: "routing.http.desync_mitigation_mode"
Value: "defensive"
-
Key: "waf.fail_open.enabled"
Value: "false"
-
Key: "routing.http.x_amzn_tls_version_and_cipher_suite.enabled"
Value: "false"
-
Key: "connection_logs.s3.enabled"
Value: "false"
ElasticLoadBalancingV2Listener:
Type: "AWS::ElasticLoadBalancingV2::Listener"
Properties:
LoadBalancerArn: !Ref ElasticLoadBalancingV2LoadBalancer
Port: 3000
Protocol: "HTTP"
DefaultActions:
-
TargetGroupArn: !Ref ElasticLoadBalancingV2TargetGroup
Type: "forward"
EC2SecurityGroup3:
Type: "AWS::EC2::SecurityGroup"
Properties:
GroupDescription: "default VPC security group"
GroupName: "default"
VpcId: !Ref EC2VPC
SecurityGroupIngress:
-
CidrIp: "99.245.113.176/32"
IpProtocol: "-1"
-
SourceSecurityGroupId: "sg-06a3908c1245df706"
SourceSecurityGroupOwnerId: !Ref AWS::AccountId
IpProtocol: "-1"
SecurityGroupEgress:
-
CidrIp: "0.0.0.0/0"
IpProtocol: "-1"
EC2SecurityGroup4:
Type: "AWS::EC2::SecurityGroup"
Properties:
GroupDescription: "Redis SG"
GroupName: !Ref RedisSecurityGroupName
VpcId: !Ref EC2VPC
SecurityGroupIngress:
-
SourceSecurityGroupId: !Ref EC2SecurityGroup3
SourceSecurityGroupOwnerId: !Ref AWS::AccountId
IpProtocol: "-1"
-
SourceSecurityGroupId: !Ref EC2SecurityGroup2
SourceSecurityGroupOwnerId: !Ref AWS::AccountId
IpProtocol: "-1"
ElasticLoadBalancingV2TargetGroup:
Type: "AWS::ElasticLoadBalancingV2::TargetGroup"
Properties:
HealthCheckIntervalSeconds: 30
HealthCheckPath: "/health"
Port: 80
Protocol: "HTTP"
HealthCheckPort: "traffic-port"
HealthCheckProtocol: "HTTP"
HealthCheckTimeoutSeconds: 5
UnhealthyThresholdCount: 2
TargetType: "ip"
Matcher:
HttpCode: "200"
HealthyThresholdCount: 5
VpcId: !Ref EC2VPC
Name: !Ref ElasticTargetGroupName
HealthCheckEnabled: true
TargetGroupAttributes:
-
Key: "target_group_health.unhealthy_state_routing.minimum_healthy_targets.percentage"
Value: "off"
-
Key: "deregistration_delay.timeout_seconds"
Value: "300"
-
Key: "stickiness.type"
Value: "lb_cookie"
-
Key: "stickiness.lb_cookie.duration_seconds"
Value: "86400"
-
Key: "slow_start.duration_seconds"
Value: "0"
-
Key: "stickiness.app_cookie.duration_seconds"
Value: "86400"
-
Key: "target_group_health.dns_failover.minimum_healthy_targets.percentage"
Value: "off"
-
Key: "load_balancing.cross_zone.enabled"
Value: "use_load_balancer_configuration"
-
Key: "load_balancing.algorithm.type"
Value: "round_robin"
-
Key: "target_group_health.unhealthy_state_routing.minimum_healthy_targets.count"
Value: "1"
-
Key: "stickiness.enabled"
Value: "false"
-
Key: "target_group_health.dns_failover.minimum_healthy_targets.count"
Value: "1"
-
Key: "load_balancing.algorithm.anomaly_mitigation"
Value: "off"
-
Key: "stickiness.app_cookie.cookie_name"
Value: ""
Targets:
-
Id: "172.31.43.61"
Port: 3000
AvailabilityZone: !GetAtt EC2Subnet2.AvailabilityZone
EC2KeyPair:
Type: "AWS::EC2::KeyPair"
Properties:
KeyName: !Ref EC2KeyPairName
KeyType: "rsa"
PublicKeyMaterial: !Ref EC2KeyPublic
ECSCluster:
Type: "AWS::ECS::Cluster"
Properties:
ClusterName: !Ref ECSClusterName
CapacityProviders:
- "FARGATE"
- "FARGATE_SPOT"
ECSService:
Type: "AWS::ECS::Service"
Properties:
ServiceName: !Ref ECSServiceName
Cluster: !GetAtt ECSCluster.Arn
LoadBalancers:
-
TargetGroupArn: !Ref ElasticLoadBalancingV2TargetGroup
ContainerName: "websocketServer"
ContainerPort: 3000
DesiredCount: 1
LaunchType: "FARGATE"
PlatformVersion: "LATEST"
TaskDefinition: !Ref ECSTaskDefinition
DeploymentConfiguration:
MaximumPercent: 200
MinimumHealthyPercent: 100
DeploymentCircuitBreaker:
Enable: true
Rollback: true
Role: !Sub "arn:aws:iam::${AWS::AccountId}:role/aws-service-role/ecs.amazonaws.com/AWSServiceRoleForECS"
NetworkConfiguration:
AwsvpcConfiguration:
AssignPublicIp: "ENABLED"
SecurityGroups:
- !Ref EC2SecurityGroup2
Subnets:
- !Ref EC2Subnet
- !Ref EC2Subnet3
- !Ref EC2Subnet2
HealthCheckGracePeriodSeconds: 0
SchedulingStrategy: "REPLICA"
DeploymentController:
Type: "ECS"
ECSTaskDefinition:
Type: "AWS::ECS::TaskDefinition"
Properties:
ContainerDefinitions:
-
Cpu: 512
Environment:
-
Name: "REDIS_PORT"
Value: !GetAtt ElastiCacheReplicationGroup.ConfigurationEndPoint.Port
-
Name: "REDIS_HOST"
Value: !GetAtt ElastiCacheReplicationGroup.ConfigurationEndPoint.Address
Essential: true
HealthCheck:
Command:
- "CMD-SHELL"
- "curl -f http://localhost:3000/health || exit 1"
Interval: 30
Timeout: 5
Retries: 3
StartPeriod: 5
Image: !Sub "${AWS::AccountId}.dkr.ecr.${AWS::Region}.amazonaws.com/place"
LogConfiguration:
LogDriver: "awslogs"
Options:
awslogs-create-group: "true"
awslogs-group: "/ecs/webSockerServer"
awslogs-region: !Ref AWS::Region
awslogs-stream-prefix: "ecs"
Name: !Ref ECSTaskContainerName
PortMappings:
-
ContainerPort: 3000
HostPort: 3000
Protocol: "tcp"
Family: !Ref ECSTaskFamily
TaskRoleArn: !Sub "arn:aws:iam::${AWS::AccountId}:role/ecsTaskExecutionRole"
ExecutionRoleArn: !Sub "arn:aws:iam::${AWS::AccountId}:role/ecsTaskExecutionRole"
NetworkMode: "awsvpc"
RequiresCompatibilities:
- "FARGATE"
Cpu: "512"
Memory: "2048"
S3Bucket:
Type: "AWS::S3::Bucket"
Properties:
BucketName: !Ref S3BucketName
BucketEncryption:
ServerSideEncryptionConfiguration:
-
ServerSideEncryptionByDefault:
SSEAlgorithm: "AES256"
BucketKeyEnabled: true
VersioningConfiguration:
Status: "Enabled"
OwnershipControls:
Rules:
-
ObjectOwnership: "BucketOwnerEnforced"
PublicAccessBlockConfiguration:
BlockPublicAcls: true
BlockPublicPolicy: true
IgnorePublicAcls: true
RestrictPublicBuckets: true
S3BucketPolicy:
Type: "AWS::S3::BucketPolicy"
Properties:
Bucket: !Ref S3Bucket
PolicyDocument:
Version: "2008-10-17"
Id: "PolicyForCloudFrontPrivateContent"
Statement:
-
Sid: "AllowCloudFrontServicePrincipal"
Effect: "Allow"
Principal:
Service: "cloudfront.amazonaws.com"
Action: "s3:GetObject"
Resource: !Sub "arn:aws:s3:::${S3Bucket}/*"
Condition:
StringEquals:
"AWS:SourceArn": !Sub "arn:aws:cloudfront::${AWS::AccountId}:distribution/${CloudFrontDistribution}"
DynamoDBTable:
Type: "AWS::DynamoDB::Table"
Properties:
AttributeDefinitions:
-
AttributeName: "x"
AttributeType: "N"
-
AttributeName: "y"
AttributeType: "N"
TableName: !Ref DynamoBoardTableName
KeySchema:
-
AttributeName: "x"
KeyType: "HASH"
-
AttributeName: "y"
KeyType: "RANGE"
ProvisionedThroughput:
ReadCapacityUnits: 1
WriteCapacityUnits: 1
DynamoDBTable2:
Type: "AWS::DynamoDB::Table"
Properties:
AttributeDefinitions:
-
AttributeName: "id"
AttributeType: "S"
TableName: !Ref DynamoUserTableName
KeySchema:
-
AttributeName: "id"
KeyType: "HASH"
ProvisionedThroughput:
ReadCapacityUnits: 1
WriteCapacityUnits: 1
ApplicationAutoScalingScalableTarget:
Type: "AWS::ApplicationAutoScaling::ScalableTarget"
Properties:
MaxCapacity: 10
MinCapacity: 1
ResourceId: !Sub "table/${DynamoDBTable2}"
RoleARN: !Sub "arn:aws:iam::${AWS::AccountId}:role/aws-service-role/dynamodb.application-autoscaling.amazonaws.com/AWSServiceRoleForApplicationAutoScaling_DynamoDBTable"
ScalableDimension: "dynamodb:table:WriteCapacityUnits"
ServiceNamespace: "dynamodb"
SuspendedState:
DynamicScalingInSuspended: false
DynamicScalingOutSuspended: false
ScheduledScalingSuspended: false
ApplicationAutoScalingScalableTarget2:
Type: "AWS::ApplicationAutoScaling::ScalableTarget"
Properties:
MaxCapacity: 10
MinCapacity: 1
ResourceId: !Sub "table/${DynamoDBTable}"
RoleARN: !Sub "arn:aws:iam::${AWS::AccountId}:role/aws-service-role/dynamodb.application-autoscaling.amazonaws.com/AWSServiceRoleForApplicationAutoScaling_DynamoDBTable"
ScalableDimension: "dynamodb:table:WriteCapacityUnits"
ServiceNamespace: "dynamodb"
SuspendedState:
DynamicScalingInSuspended: false
DynamicScalingOutSuspended: false
ScheduledScalingSuspended: false
ElastiCacheReplicationGroup:
Type: "AWS::ElastiCache::ReplicationGroup"
Properties:
AutoMinorVersionUpgrade: true
ReplicationGroupId: !Ref ElastiCacheReplicationGroupID
ReplicationGroupDescription: "r/place in memory"
Engine: redis
EngineVersion: 5.0.4
NumNodeGroups: 1
ReplicasPerNodeGroup: 1
AutomaticFailoverEnabled: true
CacheSubnetGroupName: !Ref ElastiCacheSubnetGroup
CacheParameterGroupName: default.redis5.0.cluster.on
SecurityGroupIds:
- !Ref EC2SecurityGroup4
Port: 6379
SnapshotRetentionLimit: 1
SnapshotWindow: "06:00-07:00"
CacheNodeType: "cache.t3.micro"
TransitEncryptionEnabled: false
AtRestEncryptionEnabled: false
MultiAZEnabled: true
ElastiCacheSubnetGroup:
Type: "AWS::ElastiCache::SubnetGroup"
Properties:
Description: "Subnet group for ElastiCache"
CacheSubnetGroupName: "reddit-place"
SubnetIds:
- !Ref EC2Subnet
- !Ref EC2Subnet3
- !Ref EC2Subnet2
ElastiCacheUser:
Type: "AWS::ElastiCache::User"
Properties:
UserId: !Ref ElastiCacheUserID
UserName: !Ref ElastiCacheUserID
Engine: "redis"
AccessString: "on ~* +@all"
NoPasswordRequired: true
EC2VPCGatewayAttachment:
Type: "AWS::EC2::VPCGatewayAttachment"
Properties:
InternetGatewayId: !Ref EC2InternetGateway
VpcId: !Ref EC2VPC
EC2InternetGateway:
Type: "AWS::EC2::InternetGateway"
EC2Route:
Type: "AWS::EC2::Route"
Properties:
DestinationCidrBlock: "0.0.0.0/0"
GatewayId: !Ref EC2InternetGateway
RouteTableId: !Ref EC2RouteTable
EC2SubnetNetworkAclAssociation:
Type: "AWS::EC2::SubnetNetworkAclAssociation"
Properties:
SubnetId: !Ref EC2Subnet3
NetworkAclId: !Ref EC2NetworkAcl
EC2SubnetNetworkAclAssociation2:
Type: "AWS::EC2::SubnetNetworkAclAssociation"
Properties:
SubnetId: !Ref EC2Subnet
NetworkAclId: !Ref EC2NetworkAcl
EC2SubnetNetworkAclAssociation3:
Type: "AWS::EC2::SubnetNetworkAclAssociation"
Properties:
SubnetId: !Ref EC2Subnet2
NetworkAclId: !Ref EC2NetworkAcl
LambdaFunction:
Type: "AWS::Lambda::Function"
Properties:
Description: "Lambda to initialize the redis board"
Environment:
Variables:
REDIS_HOST: !GetAtt ElastiCacheReplicationGroup.ConfigurationEndPoint.Address
REDIS_PORT: !GetAtt ElastiCacheReplicationGroup.ConfigurationEndPoint.Port
AWS_APPCONFIG_EXTENSION_PREFETCH_LIST: "/applications/place/environments/dev/configurations/place"
FunctionName: "initializeRedisBoard"
Handler: "lambda_function.lambda_handler"
Architectures:
- "x86_64"
Code:
S3Bucket: !Sub "awslambda-${AWS::Region}-tasks"
S3Key: !Sub "/snapshots/${AWS::AccountId}/initializeRedisBoard-8ab844a9-a9cc-4006-9f9c-bead633b5b66"
S3ObjectVersion: "auvwK4sLWU_k8PsApWZcvA2.nWhJDFhv"
MemorySize: 128
Role: !Sub "arn:aws:iam::${AWS::AccountId}:role/lambdaVPC"
Runtime: "python3.11"
Timeout: 3
TracingConfig:
Mode: "PassThrough"
VpcConfig:
SubnetIds:
- !Ref EC2Subnet
- !Ref EC2Subnet3
- !Ref EC2Subnet2
SecurityGroupIds:
- !Ref EC2SecurityGroup3
Layers:
- !Sub "arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:layer:redis:3"
- !Sub "arn:aws:lambda:${AWS::Region}:728743619870:layer:AWS-AppConfig-Extension:81"
EphemeralStorage:
Size: 512
EC2DHCPOptions:
Type: "AWS::EC2::DHCPOptions"
Properties:
DomainName: !Sub "${AWS::Region}.compute.internal"
EC2VPCDHCPOptionsAssociation:
Type: "AWS::EC2::VPCDHCPOptionsAssociation"
Properties:
DhcpOptionsId: !Ref EC2DHCPOptions
VpcId: !Ref EC2VPC
EC2NetworkAcl:
Type: "AWS::EC2::NetworkAcl"
Properties:
VpcId: !Ref EC2VPC
EC2NetworkAclEntry:
Type: "AWS::EC2::NetworkAclEntry"
Properties:
CidrBlock: "0.0.0.0/0"
Egress: true
NetworkAclId: !Ref EC2NetworkAcl
Protocol: -1
RuleAction: "allow"
RuleNumber: 100
EC2NetworkAclEntry2:
Type: "AWS::EC2::NetworkAclEntry"
Properties:
CidrBlock: "0.0.0.0/0"
Egress: false
NetworkAclId: !Ref EC2NetworkAcl
Protocol: -1
RuleAction: "allow"
RuleNumber: 100
EC2RouteTable:
Type: "AWS::EC2::RouteTable"
Properties:
VpcId: !Ref EC2VPC
CloudFrontDistribution:
Type: "AWS::CloudFront::Distribution"
Properties:
DistributionConfig:
Origins:
-
ConnectionAttempts: 3
ConnectionTimeout: 10
DomainName: !Sub "${S3Bucket}.s3.${AWS::Region}.amazonaws.com"
Id: !Sub "${S3Bucket}.s3.${AWS::Region}.amazonaws.com"
OriginPath: "/static"
S3OriginConfig:
OriginAccessIdentity: ""
-
ConnectionAttempts: 3
ConnectionTimeout: 10
CustomOriginConfig:
HTTPPort: 3000
HTTPSPort: 443
OriginKeepaliveTimeout: 5
OriginProtocolPolicy: "http-only"
OriginReadTimeout: 30
OriginSSLProtocols:
- "TLSv1.2"
DomainName: !GetAtt ElasticLoadBalancingV2LoadBalancer.DNSName
Id: !GetAtt ElasticLoadBalancingV2LoadBalancer.DNSName
OriginPath: ""
DefaultCacheBehavior:
AllowedMethods:
- "HEAD"
- "DELETE"
- "POST"
- "GET"
- "OPTIONS"
- "PUT"
- "PATCH"
CachedMethods:
- "HEAD"
- "GET"
Compress: true
CachePolicyId: "33ca6483-c564-4447-9d1a-c6e32d1d670f"
OriginRequestPolicyId: "33f36d7e-f396-46d9-90e0-52428a34d9dc"
SmoothStreaming: false
TargetOriginId: !GetAtt ElasticLoadBalancingV2LoadBalancer.DNSName
ViewerProtocolPolicy: "allow-all"
CacheBehaviors:
-
AllowedMethods:
- "HEAD"
- "GET"
Compress: true
CachePolicyId: "4135ea2d-6df8-44a3-9df3-4b5a84be39ad"
PathPattern: "/app/*"
SmoothStreaming: false
TargetOriginId: !Sub "${S3Bucket}.s3.${AWS::Region}.amazonaws.com"
ViewerProtocolPolicy: "allow-all"
Comment: "rplace Cloudfront distribution"
PriceClass: "PriceClass_All"
Enabled: true
ViewerCertificate:
CloudFrontDefaultCertificate: true
MinimumProtocolVersion: "TLSv1"
SslSupportMethod: "vip"
Restrictions:
GeoRestriction:
RestrictionType: "none"
HttpVersion: "http2and3"
DefaultRootObject: ""
IPV6Enabled: true
CloudFrontOriginAccessControl:
Type: "AWS::CloudFront::OriginAccessControl"
Properties:
OriginAccessControlConfig:
Name: !Sub "${S3Bucket}.s3.${AWS::Region}.amazonaws.com"
OriginAccessControlOriginType: "s3"
SigningBehavior: "always"
SigningProtocol: "sigv4"
CloudFrontCachePolicy:
Type: "AWS::CloudFront::CachePolicy"
Properties:
CachePolicyConfig:
Name: !Ref CloudFrontCachePolicyName
Comment: "Caching policy for API calls at the CDN level"
DefaultTTL: 5
MaxTTL: 5
MinTTL: 1
ParametersInCacheKeyAndForwardedToOrigin:
EnableAcceptEncodingGzip: true
EnableAcceptEncodingBrotli: true
CookiesConfig:
CookieBehavior: "none"
HeadersConfig:
HeaderBehavior: "none"
QueryStringsConfig:
QueryStringBehavior: "none"
SNSTopic:
Type: "AWS::SNS::Topic"
Properties:
DisplayName: !Ref SNSTopicName
TopicName: !Ref SNSTopicName
SNSTopicPolicy:
Type: "AWS::SNS::TopicPolicy"
Properties:
PolicyDocument: !Sub "{\"Version\":\"2008-10-17\",\"Id\":\"__default_policy_ID\",\"Statement\":[{\"Sid\":\"__default_statement_ID\",\"Effect\":\"Allow\",\"Principal\":{\"AWS\":\"*\"},\"Action\":[\"SNS:GetTopicAttributes\",\"SNS:SetTopicAttributes\",\"SNS:AddPermission\",\"SNS:RemovePermission\",\"SNS:DeleteTopic\",\"SNS:Subscribe\",\"SNS:ListSubscriptionsByTopic\",\"SNS:Publish\"],\"Resource\":\"${SNSTopic}\",\"Condition\":{\"StringEquals\":{\"AWS:SourceOwner\":\"${AWS::AccountId}\"}}}]}"
Topics:
- !Ref SNSTopic
LambdaFunction2:
Type: "AWS::Lambda::Function"
Properties:
Description: "Lambda to set user timestamp in DynamoDB"
FunctionName: !Ref setBoardPixelDynamoDBLambdaFunctionName
Handler: "lambda_function.lambda_handler"
Architectures:
- "x86_64"
Code:
S3Bucket: !Sub "awslambda-${AWS::Region}-tasks"
S3Key: !Sub "/snapshots/${AWS::AccountId}/setBoardPixelDynamoDB-6a017d99-e4ee-4e35-97b0-455daf018f7c"
S3ObjectVersion: "tgM25pBxcJe3jfHEQk9Nm.bNi5YR8wOd"
MemorySize: 128
Role: !Sub "arn:aws:iam::${AWS::AccountId}:role/lambdaVPC"
Runtime: "python3.11"
Timeout: 3
TracingConfig:
Mode: "PassThrough"
EphemeralStorage:
Size: 512
LambdaFunction3:
Type: "AWS::Lambda::Function"
Properties:
Description: "Lambda to broadcast to all clients"
Environment:
Variables:
SNS_TOPIC_ARN: !Ref SNSTopic
FunctionName: !Sub "${DynamoDBTable}castClients"
Handler: "lambda_function.lambda_handler"
Architectures:
- "x86_64"
Code:
S3Bucket: !Sub "awslambda-${AWS::Region}-tasks"
S3Key: !Sub "/snapshots/${AWS::AccountId}/boardcastClients-a145bc26-e280-4aa3-9f63-6340b904f346"
S3ObjectVersion: "J8IuR2yp5MRhhtM0DvgYW36n8hmM8eSp"
MemorySize: 128
Role: !Sub "arn:aws:iam::${AWS::AccountId}:role/lambdaVPC"
Runtime: "python3.11"
Timeout: 3
TracingConfig:
Mode: "PassThrough"
EphemeralStorage:
Size: 512
LambdaFunction4:
Type: "AWS::Lambda::Function"
Properties:
Description: "Lambda to set user timestamp in DynamoDB"
FunctionName: !Ref setUserTimestampDynamoDBLambdaFunctionName
Handler: "lambda_function.lambda_handler"
Architectures:
- "x86_64"
Code:
S3Bucket: !Sub "awslambda-${AWS::Region}-tasks"
S3Key: !Sub "/snapshots/${AWS::AccountId}/setUserTimestampDynamoDB-d49143de-a390-437b-86c2-8a0adb46126a"
S3ObjectVersion: "TGeGSXyItpsR7QOMPIeVLPcDN.KteCpZ"
MemorySize: 128
Role: !Sub "arn:aws:iam::${AWS::AccountId}:role/lambdaVPC"
Runtime: "python3.11"
Timeout: 3
TracingConfig:
Mode: "PassThrough"
EphemeralStorage:
Size: 512
Outputs:
CloudFrontURL:
Description: "The URL of the CloudFront distribution"
Value: !GetAtt CloudFrontDistribution.DomainName
Export:
Name: !Sub "${AWS::StackName}-CloudFrontURL"
LoadBalancerURL:
Description: "The URL of the load balancer"
Value: !GetAtt ElasticLoadBalancingV2LoadBalancer.DNSName
Export:
Name: !Sub "${AWS::StackName}-LoadBalancerURL"
ElastiCacheReplicationGroupHost:
Description: "The host of the ElastiCache replication group"
Value: !GetAtt ElastiCacheReplicationGroup.ConfigurationEndPoint.Address
Export:
Name: !Sub "${AWS::StackName}-ElastiCacheReplicationGroupHost"
ElastiCacheReplicationGroupPort:
Description: "The port of the ElastiCache replication group"
Value: !GetAtt ElastiCacheReplicationGroup.ConfigurationEndPoint.Port
Export:
Name: !Sub "${AWS::StackName}-ElastiCacheReplicationGroupPort"