1- AWSTemplateFormatVersion : ' 2010-09-09'
1+ AWSTemplateFormatVersion : " 2010-09-09"
22Transform : 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)
44
55Globals :
66 Function :
7- Timeout : 5
8- MemorySize : 256
9- Runtime : nodejs18.x
10- Tracing : Active
7+ Timeout : 20
8+ Runtime : dotnet8
9+ MemorySize : 1024
1110 Environment :
1211 Variables :
13- POWERTOOLS_SERVICE_NAME : powertools-dotnet-sample-batch-processing
12+ POWERTOOLS_SERVICE_NAME : powertools-dotnet-sample-batch-kinesis
1413 POWERTOOLS_LOG_LEVEL : Debug
15- POWERTOOLS_LOGGER_CASE : PascalCase # Allowed values are: CamelCase, PascalCase and SnakeCase
14+ POWERTOOLS_LOGGER_CASE : PascalCase
1615 POWERTOOLS_BATCH_ERROR_HANDLING_POLICY : DeriveFromEvent
1716 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
1919
2020Resources :
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
5221
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-
6622 # --------------
67- # KMS key for encrypted queues
23+ # KMS key for encrypted messages / records
6824 CustomerKey :
6925 Type : AWS::KMS::Key
7026 Properties :
7127 Description : KMS key for encrypted queues
7228 Enabled : true
7329 KeyPolicy :
74- Version : ' 2012-10-17'
30+ Version : " 2012-10-17"
7531 Statement :
7632 - Sid : Enable IAM User Permissions
7733 Effect : Allow
7834 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
8339 Effect : Allow
8440 Principal :
8541 Service : lambda.amazonaws.com
8642 Action :
8743 - kms:Decrypt
8844 - kms:GenerateDataKey
89- Resource : ' * '
45+ Resource : " * "
9046
9147 CustomerKeyAlias :
9248 Type : AWS::KMS::Alias
9349 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