-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtemplate.yaml
104 lines (93 loc) · 3.1 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
AWSTemplateFormatVersion: 2010-09-09
Transform: AWS::Serverless-2016-10-31
Description: SAM template for the Lambda Protobuf Decoding
Parameters:
KinesisProtobufStreamName:
Description: "Name of the kinesis stream containing the protobuf messages"
Type: String
MinLength: 1
TargetS3BucketName:
Description: "Name of the S3 bucket where to store the decoded messages"
Type: String
MinLength: 1
ProtobufLayerName:
Description: "Name and version in the format: 'name:version' of the Lambda Layer containing the protobuf library"
Default: "protobuf-lambda:1"
Type: String
MinLength: 1
Resources:
ProtoLambdaIAMRole:
Type: "AWS::IAM::Role"
Properties:
RoleName: proto-demo-lambda-role
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Action:
- "sts:AssumeRole"
Effect: "Allow"
Principal:
Service:
- "lambda.amazonaws.com"
ManagedPolicyArns:
- arn:aws:iam::aws:policy/service-role/AWSLambdaKinesisExecutionRole
Policies:
- PolicyName: "cw-demo-protobuf-lambda"
PolicyDocument:
Version: "2012-10-17"
Statement:
- Action:
- "logs:CreateLogGroup"
- "logs:CreateLogStream"
- "logs:PutLogEvents"
Effect: "Allow"
Resource:
- !Sub "arn:aws:logs:${AWS::Region}:${AWS::AccountId}:log-group:/aws/lambda/protobuf-decoder-lambda:*"
- PolicyName: "s3-demo-protobuf-lambda"
PolicyDocument:
Version: "2012-10-17"
Statement:
- Action:
- "s3:*"
Effect: "Allow"
Resource:
- !Sub "arn:aws:s3:::${TargetS3BucketName}"
- !Sub "arn:aws:s3:::${TargetS3BucketName}/*"
- PolicyName:
Fn::Sub: ${AWS::StackName}-KMS
PolicyDocument:
Statement:
- Effect: Allow
Action:
- kms:Encrypt
- kms:Decrypt
- kms:ReEncrypt*
- kms:DescribeKey
Resource: '*'
LambdaFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: functions/protodecode
Handler: app.lambda_handler
Role: !GetAtt ProtoLambdaIAMRole.Arn
Timeout: 60
Runtime: python3.9
FunctionName: "protobuf-decoder-lambda"
MemorySize: 512
Environment:
Variables:
BUCKET_NAME: !Ref 'TargetS3BucketName'
Layers:
- !Sub "arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:layer:${ProtobufLayerName}"
Events:
KinesisEvent:
Type: Kinesis
Properties:
Stream: !Sub "arn:aws:kinesis:${AWS::Region}:${AWS::AccountId}:stream/${KinesisProtobufStreamName}"
StartingPosition: LATEST
BatchSize: 100
Enabled: true
Outputs:
LambdaFunction:
Value: !Ref 'LambdaFunction'
Description: Lambda Function for Protobuf Decoding