Skip to content

Commit 147ca29

Browse files
author
Florian Mair
committed
Change consumer version
1 parent 8740087 commit 147ca29

File tree

10 files changed

+132
-491
lines changed

10 files changed

+132
-491
lines changed

.gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,6 @@ consumer/target/
2222
local.properties
2323

2424
#macOS
25-
.DS_Store
25+
.DS_Store
26+
27+
cdk

cloudformation/deployment.yaml

+1-292
Original file line numberDiff line numberDiff line change
@@ -11,179 +11,10 @@ Parameters:
1111

1212
Resources:
1313

14-
VPC01:
15-
Type: AWS::EC2::VPC
16-
Properties:
17-
CidrBlock: 10.0.0.0/16
18-
DependsOn: KinesisDataStream01
19-
20-
PublicSubnet01:
21-
Type: AWS::EC2::Subnet
22-
Properties:
23-
AvailabilityZone: !Select
24-
- 0
25-
- Fn::GetAZs: !Ref 'AWS::Region'
26-
CidrBlock: 10.0.0.0/24
27-
MapPublicIpOnLaunch: true
28-
VpcId:
29-
Ref: VPC01
30-
31-
PublicSubnet02:
32-
Type: AWS::EC2::Subnet
33-
Properties:
34-
AvailabilityZone: !Select
35-
- 1
36-
- Fn::GetAZs: !Ref 'AWS::Region'
37-
CidrBlock: 10.0.1.0/24
38-
MapPublicIpOnLaunch: true
39-
VpcId:
40-
Ref: VPC01
41-
42-
PrivateSubnet01:
43-
Type: AWS::EC2::Subnet
44-
Properties:
45-
VpcId: !Ref VPC01
46-
AvailabilityZone: !Select
47-
- 0
48-
- Fn::GetAZs: !Ref 'AWS::Region'
49-
CidrBlock: 10.0.10.0/24
50-
MapPublicIpOnLaunch: false
51-
52-
PrivateSubnet02:
53-
Type: AWS::EC2::Subnet
54-
Properties:
55-
VpcId: !Ref VPC01
56-
AvailabilityZone: !Select
57-
- 1
58-
- Fn::GetAZs: !Ref 'AWS::Region'
59-
CidrBlock: 10.0.11.0/24
60-
MapPublicIpOnLaunch: false
61-
62-
InternetGateway01:
63-
Type: AWS::EC2::InternetGateway
6414

65-
InternetGatewayAttachment01:
66-
Type: AWS::EC2::VPCGatewayAttachment
67-
Properties:
68-
InternetGatewayId: !Ref InternetGateway01
69-
VpcId: !Ref VPC01
7015

71-
NatGateway01EIP:
72-
Type: AWS::EC2::EIP
73-
DependsOn: InternetGatewayAttachment01
74-
Properties:
75-
Domain: vpc
7616

77-
NatGateway02EIP:
78-
Type: AWS::EC2::EIP
79-
DependsOn: InternetGatewayAttachment01
80-
Properties:
81-
Domain: vpc
8217

83-
NatGateway01:
84-
Type: AWS::EC2::NatGateway
85-
Properties:
86-
AllocationId: !GetAtt NatGateway01EIP.AllocationId
87-
SubnetId: !Ref PublicSubnet01
88-
89-
NatGateway02:
90-
Type: AWS::EC2::NatGateway
91-
Properties:
92-
AllocationId: !GetAtt NatGateway02EIP.AllocationId
93-
SubnetId: !Ref PublicSubnet02
94-
95-
PublicRouteTable01:
96-
Type: AWS::EC2::RouteTable
97-
Properties:
98-
VpcId: !Ref VPC01
99-
100-
DefaultPublicRoute01:
101-
Type: AWS::EC2::Route
102-
DependsOn: InternetGatewayAttachment01
103-
Properties:
104-
RouteTableId: !Ref PublicRouteTable01
105-
DestinationCidrBlock: 0.0.0.0/0
106-
GatewayId: !Ref InternetGateway01
107-
108-
PublicSubnet01RouteTableAssociation:
109-
Type: AWS::EC2::SubnetRouteTableAssociation
110-
Properties:
111-
RouteTableId: !Ref PublicRouteTable01
112-
SubnetId: !Ref PublicSubnet01
113-
114-
PublicSubnet02RouteTableAssociation:
115-
Type: AWS::EC2::SubnetRouteTableAssociation
116-
Properties:
117-
RouteTableId: !Ref PublicRouteTable01
118-
SubnetId: !Ref PublicSubnet02
119-
120-
PrivateRouteTable01:
121-
Type: AWS::EC2::RouteTable
122-
Properties:
123-
VpcId: !Ref VPC01
124-
125-
DefaultPrivateRoute01:
126-
Type: AWS::EC2::Route
127-
Properties:
128-
RouteTableId: !Ref PrivateRouteTable01
129-
DestinationCidrBlock: 0.0.0.0/0
130-
NatGatewayId: !Ref NatGateway01
131-
132-
PrivateSubnet01RouteTableAssociation:
133-
Type: AWS::EC2::SubnetRouteTableAssociation
134-
Properties:
135-
RouteTableId: !Ref PrivateRouteTable01
136-
SubnetId: !Ref PrivateSubnet01
137-
138-
PrivateRouteTable02:
139-
Type: AWS::EC2::RouteTable
140-
Properties:
141-
VpcId: !Ref VPC01
142-
143-
DefaultPrivateRoute02:
144-
Type: AWS::EC2::Route
145-
Properties:
146-
RouteTableId: !Ref PrivateRouteTable02
147-
DestinationCidrBlock: 0.0.0.0/0
148-
NatGatewayId: !Ref NatGateway02
149-
150-
PrivateSubnet02RouteTableAssociation:
151-
Type: AWS::EC2::SubnetRouteTableAssociation
152-
Properties:
153-
RouteTableId: !Ref PrivateRouteTable02
154-
SubnetId: !Ref PrivateSubnet02
155-
156-
KinesisDataStream01:
157-
Type: AWS::Kinesis::Stream
158-
Properties:
159-
Name: data-processing-stream
160-
ShardCount: 1
161-
DependsOn: CodeBuildTriggerRule01
162-
163-
ECSCluster01:
164-
Type: AWS::ECS::Cluster
165-
Properties:
166-
ClusterName: dataprocessor-cluster
167-
168-
ProducerRepository01:
169-
Type: AWS::ECR::Repository
170-
Properties:
171-
RepositoryName: kinesis-data-processor/producer
172-
173-
ConsumerRepository01:
174-
Type: AWS::ECR::Repository
175-
Properties:
176-
RepositoryName: kinesis-data-processor/producer
177-
178-
ConsumerRepository01:
179-
Type: AWS::ECR::Repository
180-
Properties:
181-
RepositoryName: kinesis-data-processor/consumer
182-
183-
KinesisAutoscalerRepository01:
184-
Type: AWS::ECR::Repository
185-
Properties:
186-
RepositoryName: kinesis-data-processor/kinesisautoscaler
18718

18819

18920
ECSTaskExecutionRole01:
@@ -215,134 +46,12 @@ Resources:
21546
SourceSecurityGroupId: !Ref ALBSecurityGroup01
21647
DependsOn: ALBSecurityGroup01
21748

218-
ECSTaskProducerDefinition01:
219-
Type: AWS::ECS::TaskDefinition
220-
Properties:
221-
Family: Producer
222-
NetworkMode: awsvpc
223-
Cpu: 2048
224-
Memory: 4096
225-
ContainerDefinitions:
226-
- Cpu: 2048
227-
Image: !Sub '${AWS::AccountId}.dkr.ecr.${AWS::Region}.amazonaws.com/kinesis-data-processor/producer'
228-
Memory: 4096
229-
Name: Producer
230-
PortMappings:
231-
- ContainerPort: 8080
232-
LogConfiguration:
233-
LogDriver: awslogs
234-
Options:
235-
awslogs-group: ecs/kinesis-data-processor-producer
236-
awslogs-region: !Ref 'AWS::Region'
237-
awslogs-stream-prefix: producer
238-
Environment:
239-
- Name: REGION
240-
Value: !Ref 'AWS::Region'
241-
- Name: STREAM_NAME
242-
Value: data-processing-stream
243-
ExecutionRoleArn: !Ref ECSTaskExecutionRole01
244-
TaskRoleArn: !Ref ECSTaskProducerRole01
245-
RequiresCompatibilities:
246-
- FARGATE
247-
DependsOn: ECSTaskLogGroup01
248-
249-
ECSTaskProducerRole01:
250-
Type: AWS::IAM::Role
251-
Properties:
252-
AssumeRolePolicyDocument:
253-
Statement:
254-
- Effect: Allow
255-
Principal:
256-
Service: ecs-tasks.amazonaws.com
257-
Action: 'sts:AssumeRole'
258-
259-
ECSServiceProducer01:
260-
Type: AWS::ECS::Service
261-
Properties:
262-
Cluster: !GetAtt ECSCluster01.Arn
263-
DesiredCount: 1
264-
LaunchType: FARGATE
265-
LoadBalancers:
266-
- ContainerName: Producer
267-
ContainerPort: 8080
268-
TargetGroupArn: !Ref ALBTargetGroup01
269-
ServiceName: dataProcessor-producerservice
270-
NetworkConfiguration:
271-
AwsvpcConfiguration:
272-
AssignPublicIp: DISABLED
273-
SecurityGroups:
274-
- !Ref ECSProducerServiceSecurityGroup01
275-
Subnets:
276-
- !Ref PrivateSubnet01
277-
- !Ref PrivateSubnet02
278-
SchedulingStrategy: REPLICA
279-
TaskDefinition: !Ref ECSTaskProducerDefinition01
280-
DependsOn: ALBListener01
281-
282-
ECSServiceRoleProducer01:
283-
Type: AWS::IAM::Role
284-
Properties:
285-
AssumeRolePolicyDocument:
286-
Version: 2008-10-17
287-
Statement:
288-
- Sid: ''
289-
Effect: Allow
290-
Principal:
291-
Service: ecs.amazonaws.com
292-
Action: 'sts:AssumeRole'
293-
ManagedPolicyArns:
294-
- 'arn:aws:iam::aws:policy/service-role/AmazonEC2ContainerServiceRole'
29549

296-
KPLPolicy01:
297-
Type: AWS::IAM::ManagedPolicy
298-
Properties:
299-
ManagedPolicyName: KinesisProducerLibraryPolicy
300-
Roles:
301-
- !Ref ECSTaskProducerRole01
302-
PolicyDocument:
303-
Version: "2012-10-17"
304-
Statement:
305-
-
306-
Effect: "Allow"
307-
Action:
308-
- kinesis:ListStreams
309-
- kinesis:ListShards
310-
- kinesis:PutRecords
311-
- kinesis:PutRecord
312-
Resource: !GetAtt KinesisDataStream01.Arn
313-
-
314-
Effect: "Allow"
315-
Action:
316-
- cloudwatch:PutMetricData
317-
Resource: "*"
318-
DependsOn: ECSTaskProducerRole01
31950

320-
ECSAutoScalingTargetProducer01:
321-
Type: AWS::ApplicationAutoScaling::ScalableTarget
322-
Properties:
323-
MinCapacity: 1
324-
MaxCapacity: 15
325-
ResourceId: !Join ['/', [service, !Ref ECSCluster01, !GetAtt ECSServiceProducer01.Name]]
326-
ScalableDimension: ecs:service:DesiredCount
327-
ServiceNamespace: ecs
328-
RoleARN: !Sub 'arn:aws:iam::${AWS::AccountId}:role/aws-service-role/ecs.application-autoscaling.amazonaws.com/AWSServiceRoleForApplicationAutoScaling_ECSService'
329-
330-
ECSAutoScalingProducerPolicy:
331-
Type: AWS::ApplicationAutoScaling::ScalingPolicy
332-
Properties:
333-
PolicyType: TargetTrackingScaling
334-
PolicyName: KinesisProducerScalingPolicy
335-
ScalingTargetId: !Ref ECSAutoScalingTargetProducer01
336-
TargetTrackingScalingPolicyConfiguration:
337-
PredefinedMetricSpecification:
338-
PredefinedMetricType: ECSServiceAverageCPUUtilization
339-
ScaleInCooldown: 60
340-
ScaleOutCooldown: 60
341-
TargetValue: 65
34251

34352
ECSTaskLogGroup03:
34453
Type: AWS::Logs::LogGroup
345-
Properties:
54+
Properties:
34655
LogGroupName: ecs/kinesis-data-processor-kinesisAutoscaler
34756

34857
ECSAutoScalerServiceSecurityGroup01:

consumer/Dockerfile

+9-16
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,13 @@
11
FROM public.ecr.aws/amazonlinux/amazonlinux:2
2-
3-
RUN yum install -y java-1.8.0-openjdk.x86_64 &&\
4-
yum install -y python3.x86_64 &&\
5-
yum install -y git &&\
6-
python3 -m pip install amazon_kclpy
7-
8-
RUN git clone --depth 1 --branch v2.0.1 https://github.com/awslabs/amazon-kinesis-client-python /kclpy &&\
9-
mv /kclpy/amazon_kclpy / &&\
10-
mkdir -p app/logs &&\
11-
mv /kclpy/samples/amazon_kclpy_helper.py /usr/bin &&\
12-
rm -rf /kclpy
13-
14-
COPY record_processor.properties record_processor.py setup.py logback.xml run.sh set_properties.py /usr/bin/
15-
16-
RUN python3 /usr/bin/setup.py install &&\
2+
RUN yum install python3 git java-11-amazon-corretto-headless -y
3+
RUN git clone --depth 1 --branch v2.1.1 https://github.com/awslabs/amazon-kinesis-client-python
4+
RUN cd amazon-kinesis-client-python &&\
5+
python3 setup.py download_jars &&\
6+
python3 setup.py install &&\
177
chmod 777 /usr/bin
188

19-
9+
COPY record_processor.py logback.xml run.sh set_properties.py sample.properties /usr/bin/
10+
RUN python3 /usr/bin/set_properties.py
2011
ENTRYPOINT ["sh", "/usr/bin/run.sh"]
12+
13+

consumer/run.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/sh
22
python3 /usr/bin/set_properties.py
33
chmod 777 /usr/bin/record_processor.py
4-
`python3 /usr/bin/amazon_kclpy_helper.py --print_command --java /usr/bin/java --properties /usr/bin/record_processor.properties --log-configuration /usr/bin/logback.xml` &
4+
`python3 /usr/bin/amazon_kclpy_helper.py --print_command --java /usr/bin/java --properties /usr/bin/sample.properties --log-configuration /usr/bin/logback.xml` &
55
touch /app/logs/record_processor.log
66
exec tail -F /app/logs/record_processor.log
File renamed without changes.

consumer/set_properties.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@
66

77
import os
88

9-
with open('/usr/bin/record_processor.properties', 'r') as file :
9+
with open('/usr/bin/sample.properties', 'r') as file :
1010
filedata = file.read()
11-
filedata = filedata.replace('AWS_REGION', os.environ['REGION'])
12-
filedata = filedata.replace('STREAM_NAME', os.environ['STREAM_NAME'])
13-
filedata = filedata.replace('APPLICATION_NAME', os.environ['APPLICATION_NAME'])
11+
filedata = filedata.replace('sample_kclpy_app.py', 'record_processor.py')
12+
filedata = filedata.replace('us-east-1', os.environ['REGION'])
13+
filedata = filedata.replace('kclpysample', os.environ['STREAM_NAME'])
14+
filedata = filedata.replace('PythonKCLSample', os.environ['APPLICATION_NAME'])
1415

1516
with open('/usr/bin/record_processor.properties', 'w') as file:
1617
file.write(filedata)

0 commit comments

Comments
 (0)