Skip to content

Commit 1956b93

Browse files
authored
Merge pull request #658 from aws-powertools/develop
chore: Sync main with develop for release
2 parents 8e821bf + 4ab0fea commit 1956b93

File tree

28 files changed

+889
-370
lines changed

28 files changed

+889
-370
lines changed

.github/ISSUE_TEMPLATE/bug_report.yml

+2
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ body:
5959
label: AWS Lambda function runtime
6060
options:
6161
- dotnet6
62+
- dotnet8
63+
- dotnet8 (AOT)
6264
validations:
6365
required: true
6466
- type: textarea
+86-73
Original file line numberDiff line numberDiff line change
@@ -1,105 +1,118 @@
1-
AWSTemplateFormatVersion: '2010-09-09'
1+
AWSTemplateFormatVersion: "2010-09-09"
22
Transform: AWS::Serverless-2016-10-31
3-
Description: partial batch response sample
3+
Description: Example project demoing DynamoDB Streams processing using the Batch Processing Utility in Powertools for AWS Lambda (.NET)
44

55
Globals:
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-ddb
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
19-
20-
Resources:
21-
HelloWorldFunction:
22-
Type: AWS::Serverless::Function
23-
Properties:
24-
CodeUri: ./src/HelloWorld/
25-
Handler: HelloWorld::HelloWorld.Function::DynamoDbStreamHandlerUsingAttribute
26-
Policies:
27-
# Lambda Destinations require additional permissions
28-
# to send failure records 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-
DynamoDBStream:
41-
Type: DynamoDB
42-
Properties:
43-
Stream: !GetAtt SampleTable.StreamArn
44-
StartingPosition: LATEST
45-
MaximumRetryAttempts: 2
46-
DestinationConfig:
47-
OnFailure:
48-
Destination: !GetAtt SampleDLQ.Arn
49-
FunctionResponseTypes:
50-
- ReportBatchItemFailures
17+
POWERTOOLS_BATCH_PARALLEL_ENABLED : false
18+
POWERTOOLS_BATCH_THROW_ON_FULL_BATCH_FAILURE: true
5119

52-
SampleDLQ:
53-
Type: AWS::SQS::Queue
54-
Properties:
55-
KmsMasterKeyId: !Ref CustomerKey
20+
Resources:
5621

57-
SampleTable:
58-
Type: AWS::DynamoDB::Table
59-
Properties:
60-
BillingMode: PAY_PER_REQUEST
61-
AttributeDefinitions:
62-
- AttributeName: pk
63-
AttributeType: S
64-
- AttributeName: sk
65-
AttributeType: S
66-
KeySchema:
67-
- AttributeName: pk
68-
KeyType: HASH
69-
- AttributeName: sk
70-
KeyType: RANGE
71-
SSESpecification:
72-
SSEEnabled: true
73-
StreamSpecification:
74-
StreamViewType: NEW_AND_OLD_IMAGES
75-
7622
# --------------
77-
# KMS key for encrypted queues
23+
# KMS key for encrypted messages / records
7824
CustomerKey:
7925
Type: AWS::KMS::Key
8026
Properties:
8127
Description: KMS key for encrypted queues
8228
Enabled: true
8329
KeyPolicy:
84-
Version: '2012-10-17'
30+
Version: "2012-10-17"
8531
Statement:
8632
- Sid: Enable IAM User Permissions
8733
Effect: Allow
8834
Principal:
89-
AWS: !Sub 'arn:aws:iam::${AWS::AccountId}:root'
90-
Action: 'kms:*'
91-
Resource: '*'
92-
- 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
9339
Effect: Allow
9440
Principal:
9541
Service: lambda.amazonaws.com
9642
Action:
9743
- kms:Decrypt
9844
- kms:GenerateDataKey
99-
Resource: '*'
45+
Resource: "*"
10046

10147
CustomerKeyAlias:
10248
Type: AWS::KMS::Alias
10349
Properties:
104-
AliasName: alias/powertools-batch-sqs-demo
105-
TargetKeyId: !Ref CustomerKey
50+
AliasName: !Sub alias/${AWS::StackName}-kms-key
51+
TargetKeyId: !Ref CustomerKey
52+
53+
# --------------
54+
# Batch Processing for DynamoDb (DDB) Stream
55+
DdbStreamDeadLetterQueue:
56+
Type: AWS::SQS::Queue
57+
Properties:
58+
KmsMasterKeyId: !Ref CustomerKey
59+
60+
DdbTable:
61+
Type: AWS::DynamoDB::Table
62+
Properties:
63+
BillingMode: PAY_PER_REQUEST
64+
AttributeDefinitions:
65+
- AttributeName: id
66+
AttributeType: S
67+
KeySchema:
68+
- AttributeName: id
69+
KeyType: HASH
70+
StreamSpecification:
71+
StreamViewType: NEW_AND_OLD_IMAGES
72+
73+
DdbStreamBatchProcessorFunction:
74+
Type: AWS::Serverless::Function
75+
Properties:
76+
CodeUri: ./src/HelloWorld/
77+
Handler: HelloWorld::HelloWorld.Function::DynamoDbStreamHandlerUsingAttribute
78+
Policies:
79+
- AWSLambdaDynamoDBExecutionRole
80+
- Statement:
81+
- Sid: DlqPermissions
82+
Effect: Allow
83+
Action:
84+
- sqs:SendMessage
85+
- sqs:SendMessageBatch
86+
Resource: !GetAtt DdbStreamDeadLetterQueue.Arn
87+
- Sid: KmsKeyPermissions
88+
Effect: Allow
89+
Action:
90+
- kms:GenerateDataKey
91+
Resource: !GetAtt CustomerKey.Arn
92+
Events:
93+
Stream:
94+
Type: DynamoDB
95+
Properties:
96+
BatchSize: 5
97+
BisectBatchOnFunctionError: true
98+
DestinationConfig:
99+
OnFailure:
100+
Destination: !GetAtt DdbStreamDeadLetterQueue.Arn
101+
Enabled: true
102+
FunctionResponseTypes:
103+
- ReportBatchItemFailures
104+
MaximumRetryAttempts: 2
105+
ParallelizationFactor: 1
106+
StartingPosition: LATEST
107+
Stream: !GetAtt DdbTable.StreamArn
108+
109+
DdbStreamBatchProcessorFunctionLogGroup:
110+
Type: AWS::Logs::LogGroup
111+
Properties:
112+
LogGroupName: !Sub "/aws/lambda/${DdbStreamBatchProcessorFunction}"
113+
RetentionInDays: 7
114+
115+
Outputs:
116+
DdbTableName:
117+
Description: "DynamoDB Table Name"
118+
Value: !Ref DdbTable
+92-62
Original file line numberDiff line numberDiff line change
@@ -1,95 +1,125 @@
1-
AWSTemplateFormatVersion: '2010-09-09'
1+
AWSTemplateFormatVersion: "2010-09-09"
22
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)
44

55
Globals:
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

2020
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
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

Comments
 (0)