1
- AWSTemplateFormatVersion : ' 2010-09-09'
1
+ AWSTemplateFormatVersion : " 2010-09-09"
2
2
Transform : AWS::Serverless-2016-10-31
3
- Description : partial batch response sample
3
+ Description : Example project demoing Kinesis Data Streams processing using the Batch Processing Utility in Powertools for AWS Lambda (.NET)
4
4
5
5
Globals :
6
6
Function :
7
- Timeout : 5
8
- MemorySize : 256
9
- Runtime : nodejs18.x
10
- Tracing : Active
7
+ Timeout : 20
8
+ Runtime : dotnet8
9
+ MemorySize : 1024
11
10
Environment :
12
11
Variables :
13
- POWERTOOLS_SERVICE_NAME : powertools-dotnet-sample-batch-processing
12
+ POWERTOOLS_SERVICE_NAME : powertools-dotnet-sample-batch-kinesis
14
13
POWERTOOLS_LOG_LEVEL : Debug
15
- POWERTOOLS_LOGGER_CASE : PascalCase # Allowed values are: CamelCase, PascalCase and SnakeCase
14
+ POWERTOOLS_LOGGER_CASE : PascalCase
16
15
POWERTOOLS_BATCH_ERROR_HANDLING_POLICY : DeriveFromEvent
17
16
POWERTOOLS_BATCH_MAX_DEGREE_OF_PARALLELISM : 1
18
- POWERTOOLS_BATCH_PARALLEL_ENABLED : false
17
+ POWERTOOLS_BATCH_PARALLEL_ENABLED : false
18
+ POWERTOOLS_BATCH_THROW_ON_FULL_BATCH_FAILURE : true
19
19
20
20
Resources :
21
- HelloWorldFunction :
22
- Type : AWS::Serverless::Function
23
- Properties :
24
- CodeUri : ./src/HelloWorld/
25
- Handler : HelloWorld::HelloWorld.Function::KinesisEventHandlerUsingAttribute
26
- Policies :
27
- # Lambda Destinations require additional permissions
28
- # to send failure records to DLQ from Kinesis/DynamoDB
29
- - Version : ' 2012-10-17'
30
- Statement :
31
- Effect : ' Allow'
32
- Action :
33
- - sqs:GetQueueAttributes
34
- - sqs:GetQueueUrl
35
- - sqs:SendMessage
36
- Resource : !GetAtt SampleDLQ.Arn
37
- - KMSDecryptPolicy :
38
- KeyId : !Ref CustomerKey
39
- Events :
40
- KinesisStream :
41
- Type : Kinesis
42
- Properties :
43
- Stream : !GetAtt SampleStream.Arn
44
- BatchSize : 100
45
- StartingPosition : LATEST
46
- MaximumRetryAttempts : 2
47
- DestinationConfig :
48
- OnFailure :
49
- Destination : !GetAtt SampleDLQ.Arn
50
- FunctionResponseTypes :
51
- - ReportBatchItemFailures
52
21
53
- SampleDLQ :
54
- Type : AWS::SQS::Queue
55
- Properties :
56
- KmsMasterKeyId : !Ref CustomerKey
57
-
58
- SampleStream :
59
- Type : AWS::Kinesis::Stream
60
- Properties :
61
- ShardCount : 1
62
- StreamEncryption :
63
- EncryptionType : KMS
64
- KeyId : alias/aws/kinesis
65
-
66
22
# --------------
67
- # KMS key for encrypted queues
23
+ # KMS key for encrypted messages / records
68
24
CustomerKey :
69
25
Type : AWS::KMS::Key
70
26
Properties :
71
27
Description : KMS key for encrypted queues
72
28
Enabled : true
73
29
KeyPolicy :
74
- Version : ' 2012-10-17'
30
+ Version : " 2012-10-17"
75
31
Statement :
76
32
- Sid : Enable IAM User Permissions
77
33
Effect : Allow
78
34
Principal :
79
- AWS : !Sub ' arn:aws:iam::${AWS::AccountId}:root'
80
- Action : ' kms:*'
81
- Resource : ' * '
82
- - Sid : Allow use of the key
35
+ AWS : !Sub " arn:aws:iam::${AWS::AccountId}:root"
36
+ Action : " kms:*"
37
+ Resource : " * "
38
+ - Sid : Allow AWS Lambda to use the key
83
39
Effect : Allow
84
40
Principal :
85
41
Service : lambda.amazonaws.com
86
42
Action :
87
43
- kms:Decrypt
88
44
- kms:GenerateDataKey
89
- Resource : ' * '
45
+ Resource : " * "
90
46
91
47
CustomerKeyAlias :
92
48
Type : AWS::KMS::Alias
93
49
Properties :
94
- AliasName : alias/powertools-batch-sqs-demo
95
- TargetKeyId : !Ref CustomerKey
50
+ AliasName : !Sub alias/${AWS::StackName}-kms-key
51
+ TargetKeyId : !Ref CustomerKey
52
+
53
+ # --------------
54
+ # Batch Processing for Kinesis Data Stream
55
+ KinesisStreamDeadLetterQueue :
56
+ Type : AWS::SQS::Queue
57
+ Properties :
58
+ KmsMasterKeyId : !Ref CustomerKey
59
+
60
+ KinesisStream :
61
+ Type : AWS::Kinesis::Stream
62
+ Properties :
63
+ ShardCount : 1
64
+ StreamEncryption :
65
+ EncryptionType : KMS
66
+ KeyId : !Ref CustomerKey
67
+
68
+ KinesisStreamConsumer :
69
+ Type : AWS::Kinesis::StreamConsumer
70
+ Properties :
71
+ ConsumerName : powertools-dotnet-sample-batch-kds-consumer
72
+ StreamARN : !GetAtt KinesisStream.Arn
73
+
74
+ KinesisBatchProcessorFunction :
75
+ Type : AWS::Serverless::Function
76
+ Properties :
77
+ Policies :
78
+ - Statement :
79
+ - Sid : KinesisStreamConsumerPermissions
80
+ Effect : Allow
81
+ Action :
82
+ - kinesis:DescribeStreamConsumer
83
+ Resource :
84
+ - !GetAtt KinesisStreamConsumer.ConsumerARN
85
+ - Sid : DlqPermissions
86
+ Effect : Allow
87
+ Action :
88
+ - sqs:SendMessage
89
+ - sqs:SendMessageBatch
90
+ Resource : !GetAtt KinesisStreamDeadLetterQueue.Arn
91
+ - Sid : KmsKeyPermissions
92
+ Effect : Allow
93
+ Action :
94
+ - kms:Decrypt
95
+ - kms:GenerateDataKey
96
+ Resource : !GetAtt CustomerKey.Arn
97
+ CodeUri : ./src/HelloWorld/
98
+ Handler : HelloWorld::HelloWorld.Function::KinesisEventHandlerUsingAttribute
99
+ Events :
100
+ Kinesis :
101
+ Type : Kinesis
102
+ Properties :
103
+ BatchSize : 5
104
+ BisectBatchOnFunctionError : true
105
+ DestinationConfig :
106
+ OnFailure :
107
+ Destination : !GetAtt KinesisStreamDeadLetterQueue.Arn
108
+ Enabled : true
109
+ FunctionResponseTypes :
110
+ - ReportBatchItemFailures
111
+ MaximumRetryAttempts : 2
112
+ ParallelizationFactor : 1
113
+ StartingPosition : LATEST
114
+ Stream : !GetAtt KinesisStreamConsumer.ConsumerARN
115
+
116
+ KinesisBatchProcessorFunctionLogGroup :
117
+ Type : AWS::Logs::LogGroup
118
+ Properties :
119
+ LogGroupName : !Sub "/aws/lambda/${KinesisBatchProcessorFunction}"
120
+ RetentionInDays : 7
121
+
122
+ Outputs :
123
+ KinesisStreamArn :
124
+ Description : " Kinesis Stream ARN"
125
+ Value : !GetAtt KinesisStream.Arn
0 commit comments