@@ -10,11 +10,169 @@ Parameters:
1010 AllowedPattern : ^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(\/(3[0-2]|[1-2][0-9]|[0-9]))$
1111
1212Resources :
13+ VPC01 :
14+ Type : AWS::EC2::VPC
15+ Properties :
16+ CidrBlock : 10.0.0.0/16
17+ DependsOn : KinesisDataStream01
18+
19+ PublicSubnet01 :
20+ Type : AWS::EC2::Subnet
21+ Properties :
22+ AvailabilityZone : !Select
23+ - 0
24+ - Fn::GetAZs : !Ref 'AWS::Region'
25+ CidrBlock : 10.0.0.0/24
26+ MapPublicIpOnLaunch : true
27+ VpcId :
28+ Ref : VPC01
29+
30+ PublicSubnet02 :
31+ Type : AWS::EC2::Subnet
32+ Properties :
33+ AvailabilityZone : !Select
34+ - 1
35+ - Fn::GetAZs : !Ref 'AWS::Region'
36+ CidrBlock : 10.0.1.0/24
37+ MapPublicIpOnLaunch : true
38+ VpcId :
39+ Ref : VPC01
40+
41+ PrivateSubnet01 :
42+ Type : AWS::EC2::Subnet
43+ Properties :
44+ VpcId : !Ref VPC01
45+ AvailabilityZone : !Select
46+ - 0
47+ - Fn::GetAZs : !Ref 'AWS::Region'
48+ CidrBlock : 10.0.10.0/24
49+ MapPublicIpOnLaunch : false
50+
51+ PrivateSubnet02 :
52+ Type : AWS::EC2::Subnet
53+ Properties :
54+ VpcId : !Ref VPC01
55+ AvailabilityZone : !Select
56+ - 1
57+ - Fn::GetAZs : !Ref 'AWS::Region'
58+ CidrBlock : 10.0.11.0/24
59+ MapPublicIpOnLaunch : false
60+
61+ InternetGateway01 :
62+ Type : AWS::EC2::InternetGateway
63+
64+ InternetGatewayAttachment01 :
65+ Type : AWS::EC2::VPCGatewayAttachment
66+ Properties :
67+ InternetGatewayId : !Ref InternetGateway01
68+ VpcId : !Ref VPC01
69+
70+ NatGateway01EIP :
71+ Type : AWS::EC2::EIP
72+ DependsOn : InternetGatewayAttachment01
73+ Properties :
74+ Domain : vpc
75+
76+ NatGateway02EIP :
77+ Type : AWS::EC2::EIP
78+ DependsOn : InternetGatewayAttachment01
79+ Properties :
80+ Domain : vpc
81+
82+ NatGateway01 :
83+ Type : AWS::EC2::NatGateway
84+ Properties :
85+ AllocationId : !GetAtt NatGateway01EIP.AllocationId
86+ SubnetId : !Ref PublicSubnet01
87+
88+ NatGateway02 :
89+ Type : AWS::EC2::NatGateway
90+ Properties :
91+ AllocationId : !GetAtt NatGateway02EIP.AllocationId
92+ SubnetId : !Ref PublicSubnet02
93+
94+ PublicRouteTable01 :
95+ Type : AWS::EC2::RouteTable
96+ Properties :
97+ VpcId : !Ref VPC01
98+
99+ DefaultPublicRoute01 :
100+ Type : AWS::EC2::Route
101+ DependsOn : InternetGatewayAttachment01
102+ Properties :
103+ RouteTableId : !Ref PublicRouteTable01
104+ DestinationCidrBlock : 0.0.0.0/0
105+ GatewayId : !Ref InternetGateway01
106+
107+ PublicSubnet01RouteTableAssociation :
108+ Type : AWS::EC2::SubnetRouteTableAssociation
109+ Properties :
110+ RouteTableId : !Ref PublicRouteTable01
111+ SubnetId : !Ref PublicSubnet01
112+
113+ PublicSubnet02RouteTableAssociation :
114+ Type : AWS::EC2::SubnetRouteTableAssociation
115+ Properties :
116+ RouteTableId : !Ref PublicRouteTable01
117+ SubnetId : !Ref PublicSubnet02
118+
119+ PrivateRouteTable01 :
120+ Type : AWS::EC2::RouteTable
121+ Properties :
122+ VpcId : !Ref VPC01
123+
124+ DefaultPrivateRoute01 :
125+ Type : AWS::EC2::Route
126+ Properties :
127+ RouteTableId : !Ref PrivateRouteTable01
128+ DestinationCidrBlock : 0.0.0.0/0
129+ NatGatewayId : !Ref NatGateway01
13130
131+ PrivateSubnet01RouteTableAssociation :
132+ Type : AWS::EC2::SubnetRouteTableAssociation
133+ Properties :
134+ RouteTableId : !Ref PrivateRouteTable01
135+ SubnetId : !Ref PrivateSubnet01
14136
137+ PrivateRouteTable02 :
138+ Type : AWS::EC2::RouteTable
139+ Properties :
140+ VpcId : !Ref VPC01
15141
142+ DefaultPrivateRoute02 :
143+ Type : AWS::EC2::Route
144+ Properties :
145+ RouteTableId : !Ref PrivateRouteTable02
146+ DestinationCidrBlock : 0.0.0.0/0
147+ NatGatewayId : !Ref NatGateway02
16148
149+ PrivateSubnet02RouteTableAssociation :
150+ Type : AWS::EC2::SubnetRouteTableAssociation
151+ Properties :
152+ RouteTableId : !Ref PrivateRouteTable02
153+ SubnetId : !Ref PrivateSubnet02
17154
155+ KinesisDataStream01 :
156+ Type : AWS::Kinesis::Stream
157+ Properties :
158+ Name : data-processing-stream
159+ ShardCount : 1
160+ DependsOn : CodeBuildTriggerRule01
161+
162+ ECSCluster01 :
163+ Type : AWS::ECS::Cluster
164+ Properties :
165+ ClusterName : dataprocessor-cluster
166+
167+ ProducerRepository01 :
168+ Type : AWS::ECR::Repository
169+ Properties :
170+ RepositoryName : kinesis-data-processor/producer
171+
172+ KinesisAutoscalerRepository01 :
173+ Type : AWS::ECR::Repository
174+ Properties :
175+ RepositoryName : kinesis-data-processor/kinesisautoscaler
18176
19177
20178 ECSTaskExecutionRole01 :
@@ -46,7 +204,130 @@ Resources:
46204 SourceSecurityGroupId : !Ref ALBSecurityGroup01
47205 DependsOn : ALBSecurityGroup01
48206
207+ ECSTaskProducerDefinition01 :
208+ Type : AWS::ECS::TaskDefinition
209+ Properties :
210+ Family : Producer
211+ NetworkMode : awsvpc
212+ Cpu : 2048
213+ Memory : 4096
214+ ContainerDefinitions :
215+ - Cpu : 2048
216+ Image : !Sub '${AWS::AccountId}.dkr.ecr.${AWS::Region}.amazonaws.com/kinesis-data-processor/producer'
217+ Memory : 4096
218+ Name : Producer
219+ PortMappings :
220+ - ContainerPort : 8080
221+ LogConfiguration :
222+ LogDriver : awslogs
223+ Options :
224+ awslogs-group : ecs/kinesis-data-processor-producer
225+ awslogs-region : !Ref 'AWS::Region'
226+ awslogs-stream-prefix : producer
227+ Environment :
228+ - Name : REGION
229+ Value : !Ref 'AWS::Region'
230+ - Name : STREAM_NAME
231+ Value : data-processing-stream
232+ ExecutionRoleArn : !Ref ECSTaskExecutionRole01
233+ TaskRoleArn : !Ref ECSTaskProducerRole01
234+ RequiresCompatibilities :
235+ - FARGATE
236+ DependsOn : ECSTaskLogGroup01
237+
238+ ECSTaskProducerRole01 :
239+ Type : AWS::IAM::Role
240+ Properties :
241+ AssumeRolePolicyDocument :
242+ Statement :
243+ - Effect : Allow
244+ Principal :
245+ Service : ecs-tasks.amazonaws.com
246+ Action : ' sts:AssumeRole'
247+
248+ ECSServiceProducer01 :
249+ Type : AWS::ECS::Service
250+ Properties :
251+ Cluster : !GetAtt ECSCluster01.Arn
252+ DesiredCount : 1
253+ LaunchType : FARGATE
254+ LoadBalancers :
255+ - ContainerName : Producer
256+ ContainerPort : 8080
257+ TargetGroupArn : !Ref ALBTargetGroup01
258+ ServiceName : dataProcessor-producerservice
259+ NetworkConfiguration :
260+ AwsvpcConfiguration :
261+ AssignPublicIp : DISABLED
262+ SecurityGroups :
263+ - !Ref ECSProducerServiceSecurityGroup01
264+ Subnets :
265+ - !Ref PrivateSubnet01
266+ - !Ref PrivateSubnet02
267+ SchedulingStrategy : REPLICA
268+ TaskDefinition : !Ref ECSTaskProducerDefinition01
269+ DependsOn : ALBListener01
270+
271+ ECSServiceRoleProducer01 :
272+ Type : AWS::IAM::Role
273+ Properties :
274+ AssumeRolePolicyDocument :
275+ Version : 2008-10-17
276+ Statement :
277+ - Sid : ' '
278+ Effect : Allow
279+ Principal :
280+ Service : ecs.amazonaws.com
281+ Action : ' sts:AssumeRole'
282+ ManagedPolicyArns :
283+ - ' arn:aws:iam::aws:policy/service-role/AmazonEC2ContainerServiceRole'
284+
285+ KPLPolicy01 :
286+ Type : AWS::IAM::ManagedPolicy
287+ Properties :
288+ ManagedPolicyName : KinesisProducerLibraryPolicy
289+ Roles :
290+ - !Ref ECSTaskProducerRole01
291+ PolicyDocument :
292+ Version : " 2012-10-17"
293+ Statement :
294+ -
295+ Effect : " Allow"
296+ Action :
297+ - kinesis:ListStreams
298+ - kinesis:ListShards
299+ - kinesis:PutRecords
300+ - kinesis:PutRecord
301+ Resource : !GetAtt KinesisDataStream01.Arn
302+ -
303+ Effect : " Allow"
304+ Action :
305+ - cloudwatch:PutMetricData
306+ Resource : " *"
307+ DependsOn : ECSTaskProducerRole01
308+
309+ ECSAutoScalingTargetProducer01 :
310+ Type : AWS::ApplicationAutoScaling::ScalableTarget
311+ Properties :
312+ MinCapacity : 1
313+ MaxCapacity : 15
314+ ResourceId : !Join ['/', [service, !Ref ECSCluster01, !GetAtt ECSServiceProducer01.Name]]
315+ ScalableDimension : ecs:service:DesiredCount
316+ ServiceNamespace : ecs
317+ RoleARN : !Sub 'arn:aws:iam::${AWS::AccountId}:role/aws-service-role/ecs.application-autoscaling.amazonaws.com/AWSServiceRoleForApplicationAutoScaling_ECSService'
49318
319+ ECSAutoScalingProducerPolicy :
320+ Type : AWS::ApplicationAutoScaling::ScalingPolicy
321+ Properties :
322+ PolicyType : TargetTrackingScaling
323+ PolicyName : KinesisProducerScalingPolicy
324+ ScalingTargetId : !Ref ECSAutoScalingTargetProducer01
325+ TargetTrackingScalingPolicyConfiguration :
326+ PredefinedMetricSpecification :
327+ PredefinedMetricType : ECSServiceAverageCPUUtilization
328+ ScaleInCooldown : 60
329+ ScaleOutCooldown : 60
330+ TargetValue : 65
50331
51332
52333 ECSTaskLogGroup03 :
0 commit comments