Skip to content

feat: Add Batch Processing Utility #337

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 50 commits into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from 49 commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
f24f96a
Initial commit.
lachriz-aws Nov 13, 2022
0549eb1
Initial commit.
lachriz-aws Nov 13, 2022
f97e15e
Merge branch 'awslabs:develop' into feature/batch-processing
lachriz-aws Nov 13, 2022
f508aa8
Merge branch 'develop' of github.com:lachriz-aws/aws-lambda-powertool…
lachriz-aws May 1, 2023
4d6dae6
Merge remote-tracking branch 'upstream/develop' into develop
lachriz-aws May 1, 2023
cfe3304
Merge branch 'feature/batch-processing' into develop
lachriz-aws May 1, 2023
b436261
Preparing for unit tests.
lachriz-aws May 1, 2023
3e67cdb
Added support for record handler providers.
lachriz-aws May 1, 2023
38d71df
Added 'TODO' and an example related to logging of failures during rec…
lachriz-aws May 1, 2023
d8c992c
Minor comments update.
lachriz-aws May 1, 2023
b1c8a99
Added unit tests for SQS batch processing logic (standard vs fifo que…
lachriz-aws May 1, 2023
3d9bf81
Updated the 'partial failure mechanics' to match those of the Python …
lachriz-aws May 4, 2023
7b4fa10
Merge remote-tracking branch 'upstream/develop' into develop
lachriz-aws Jun 30, 2023
2f7caef
Post-merge clean-up in solution file.
lachriz-aws Jun 30, 2023
66b7ae4
Merge branch 'develop' into feature/batch-processing
lachriz-aws Jun 30, 2023
1908794
The 'BatchProcesserAttribute' now derives from the 'UniversalWrapperA…
lachriz-aws Jul 1, 2023
4d3ced9
Added support for parallel processing of batch items (POWERTOOLS_BATC…
lachriz-aws Jul 1, 2023
b153943
Added support for configuring processing options via environment vari…
lachriz-aws Jul 2, 2023
a93da4c
Added missing copyright statements.
lachriz-aws Jul 2, 2023
13e2f82
Updated nuget package references in BatchProcessing projects.
lachriz-aws Jul 2, 2023
199101b
Started work on BatchProcessing docs.
lachriz-aws Jul 2, 2023
d7a2d59
Added remaining comments and improved the support for reading process…
lachriz-aws Jul 2, 2023
1ec18a0
Minor updates to titles, links and descriptions in the BatchProcessin…
lachriz-aws Jul 3, 2023
749c482
Trying to fix sonarcloud security Omitting "KmsMasterKeyId" disables …
hjgraca Jul 20, 2023
210be16
Merge branch 'develop' of https://github.com/hjgraca/powertools-lambd…
hjgraca Aug 19, 2023
8ea523d
Replace Moq
hjgraca Aug 19, 2023
34afc7e
Merge remote-tracking branch 'upstream/develop' into feature/batch-pr…
hjgraca Aug 29, 2023
a3923cb
Parallel behind config. Add SetExecutionEnvironment. Refactor
hjgraca Sep 1, 2023
ece1daa
Merge branch 'develop' of https://github.com/hjgraca/powertools-lambd…
hjgraca Sep 1, 2023
aa08c47
fix result duplication. fix warnings, more tests
hjgraca Sep 1, 2023
d468c50
Refactor SQSBatchProcessor. Add tests for all SQS handler scenarios
hjgraca Sep 6, 2023
059612b
finishing sqs tests
hjgraca Sep 11, 2023
a8fffd3
Merge branch 'develop' of https://github.com/hjgraca/powertools-lambd…
hjgraca Sep 11, 2023
974c93d
refactoring, kinesis tests, readme and initial docs
hjgraca Sep 12, 2023
2927354
fix sonar sam template without kms
hjgraca Sep 12, 2023
146d343
fix sonar kms key, doc line updates due to added kms
hjgraca Sep 12, 2023
53c6b0f
dynamodb tests
hjgraca Sep 12, 2023
127bf40
name refactorings
hjgraca Sep 12, 2023
6e6ea41
fix examples
hjgraca Sep 12, 2023
4abb4e5
Merge branch 'develop' of https://github.com/hjgraca/powertools-lambd…
hjgraca Sep 13, 2023
2b042a8
Batch support for central package management
hjgraca Sep 13, 2023
cec087f
fix examples (will remove project reference once released and add nug…
hjgraca Sep 13, 2023
cb8db81
docs: add kinesis and dynamodb
hjgraca Sep 13, 2023
96e2d08
docs update and conclusion. Testing fail all messages.
hjgraca Sep 13, 2023
562b162
docs updates
hjgraca Sep 13, 2023
b0491c2
refactor to interfaces
amirkaws Sep 15, 2023
68b488c
rename KenisisDataStream to KenisisEvent
amirkaws Sep 15, 2023
e632af6
implement processors as interface
amirkaws Sep 15, 2023
f567b65
implement processors as interface in example
amirkaws Sep 15, 2023
3736f2d
Merge branch 'develop' of https://github.com/hjgraca/powertools-lambd…
hjgraca Sep 19, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 105 additions & 0 deletions docs/snippets/batch/templates/dynamodb.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: partial batch response sample

Globals:
Function:
Timeout: 5
MemorySize: 256
Runtime: nodejs18.x
Tracing: Active
Environment:
Variables:
POWERTOOLS_SERVICE_NAME: powertools-dotnet-sample-batch-processing
POWERTOOLS_LOG_LEVEL: Debug
POWERTOOLS_LOGGER_CASE: PascalCase # Allowed values are: CamelCase, PascalCase and SnakeCase
POWERTOOLS_BATCH_ERROR_HANDLING_POLICY: DeriveFromEvent
POWERTOOLS_BATCH_MAX_DEGREE_OF_PARALLELISM: 1
POWERTOOLS_BATCH_PARALLEL_ENABLED: false

Resources:
HelloWorldFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: ./src/HelloWorld/
Handler: HelloWorld::HelloWorld.Function::DynamoDbStreamHandlerUsingAttribute
Policies:
# Lambda Destinations require additional permissions
# to send failure records from Kinesis/DynamoDB
- Version: '2012-10-17'
Statement:
Effect: 'Allow'
Action:
- sqs:GetQueueAttributes
- sqs:GetQueueUrl
- sqs:SendMessage
Resource: !GetAtt SampleDLQ.Arn
- KMSDecryptPolicy:
KeyId: !Ref CustomerKey
Events:
DynamoDBStream:
Type: DynamoDB
Properties:
Stream: !GetAtt SampleTable.StreamArn
StartingPosition: LATEST
MaximumRetryAttempts: 2
DestinationConfig:
OnFailure:
Destination: !GetAtt SampleDLQ.Arn
FunctionResponseTypes:
- ReportBatchItemFailures

SampleDLQ:
Type: AWS::SQS::Queue
Properties:
KmsMasterKeyId: !Ref CustomerKey

SampleTable:
Type: AWS::DynamoDB::Table
Properties:
BillingMode: PAY_PER_REQUEST
AttributeDefinitions:
- AttributeName: pk
AttributeType: S
- AttributeName: sk
AttributeType: S
KeySchema:
- AttributeName: pk
KeyType: HASH
- AttributeName: sk
KeyType: RANGE
SSESpecification:
SSEEnabled: true
StreamSpecification:
StreamViewType: NEW_AND_OLD_IMAGES

# --------------
# KMS key for encrypted queues
CustomerKey:
Type: AWS::KMS::Key
Properties:
Description: KMS key for encrypted queues
Enabled: true
KeyPolicy:
Version: '2012-10-17'
Statement:
- Sid: Enable IAM User Permissions
Effect: Allow
Principal:
AWS: !Sub 'arn:aws:iam::${AWS::AccountId}:root'
Action: 'kms:*'
Resource: '*'
- Sid: Allow use of the key
Effect: Allow
Principal:
Service: lambda.amazonaws.com
Action:
- kms:Decrypt
- kms:GenerateDataKey
Resource: '*'

CustomerKeyAlias:
Type: AWS::KMS::Alias
Properties:
AliasName: alias/powertools-batch-sqs-demo
TargetKeyId: !Ref CustomerKey
95 changes: 95 additions & 0 deletions docs/snippets/batch/templates/kinesis.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: partial batch response sample

Globals:
Function:
Timeout: 5
MemorySize: 256
Runtime: nodejs18.x
Tracing: Active
Environment:
Variables:
POWERTOOLS_SERVICE_NAME: powertools-dotnet-sample-batch-processing
POWERTOOLS_LOG_LEVEL: Debug
POWERTOOLS_LOGGER_CASE: PascalCase # Allowed values are: CamelCase, PascalCase and SnakeCase
POWERTOOLS_BATCH_ERROR_HANDLING_POLICY: DeriveFromEvent
POWERTOOLS_BATCH_MAX_DEGREE_OF_PARALLELISM: 1
POWERTOOLS_BATCH_PARALLEL_ENABLED: false

Resources:
HelloWorldFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: ./src/HelloWorld/
Handler: HelloWorld::HelloWorld.Function::KinesisEventHandlerUsingAttribute
Policies:
# Lambda Destinations require additional permissions
# to send failure records to DLQ from Kinesis/DynamoDB
- Version: '2012-10-17'
Statement:
Effect: 'Allow'
Action:
- sqs:GetQueueAttributes
- sqs:GetQueueUrl
- sqs:SendMessage
Resource: !GetAtt SampleDLQ.Arn
- KMSDecryptPolicy:
KeyId: !Ref CustomerKey
Events:
KinesisStream:
Type: Kinesis
Properties:
Stream: !GetAtt SampleStream.Arn
BatchSize: 100
StartingPosition: LATEST
MaximumRetryAttempts: 2
DestinationConfig:
OnFailure:
Destination: !GetAtt SampleDLQ.Arn
FunctionResponseTypes:
- ReportBatchItemFailures

SampleDLQ:
Type: AWS::SQS::Queue
Properties:
KmsMasterKeyId: !Ref CustomerKey

SampleStream:
Type: AWS::Kinesis::Stream
Properties:
ShardCount: 1
StreamEncryption:
EncryptionType: KMS
KeyId: alias/aws/kinesis

# --------------
# KMS key for encrypted queues
CustomerKey:
Type: AWS::KMS::Key
Properties:
Description: KMS key for encrypted queues
Enabled: true
KeyPolicy:
Version: '2012-10-17'
Statement:
- Sid: Enable IAM User Permissions
Effect: Allow
Principal:
AWS: !Sub 'arn:aws:iam::${AWS::AccountId}:root'
Action: 'kms:*'
Resource: '*'
- Sid: Allow use of the key
Effect: Allow
Principal:
Service: lambda.amazonaws.com
Action:
- kms:Decrypt
- kms:GenerateDataKey
Resource: '*'

CustomerKeyAlias:
Type: AWS::KMS::Alias
Properties:
AliasName: alias/powertools-batch-sqs-demo
TargetKeyId: !Ref CustomerKey
83 changes: 83 additions & 0 deletions docs/snippets/batch/templates/sqs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: partial batch response sample

Globals:
Function:
Timeout: 5
MemorySize: 256
Runtime: nodejs18.x
Tracing: Active
Environment:
Variables:
POWERTOOLS_SERVICE_NAME: powertools-dotnet-sample-batch-processing
POWERTOOLS_LOG_LEVEL: Debug
POWERTOOLS_LOGGER_CASE: PascalCase # Allowed values are: CamelCase, PascalCase and SnakeCase
POWERTOOLS_BATCH_ERROR_HANDLING_POLICY: DeriveFromEvent
POWERTOOLS_BATCH_MAX_DEGREE_OF_PARALLELISM: 1
POWERTOOLS_BATCH_PARALLEL_ENABLED: false

Resources:
HelloWorldFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: ./src/HelloWorld/
Handler: HelloWorld::HelloWorld.Function::SqsHandlerUsingAttribute
Policies:
- SQSPollerPolicy:
QueueName: !GetAtt SampleQueue.QueueName
- KMSDecryptPolicy:
KeyId: !Ref CustomerKey
Events:
Batch:
Type: SQS
Properties:
Queue: !GetAtt SampleQueue.Arn
FunctionResponseTypes:
- ReportBatchItemFailures

SampleDLQ:
Type: AWS::SQS::Queue
Properties:
KmsMasterKeyId: !Ref CustomerKey

SampleQueue:
Type: AWS::SQS::Queue
Properties:
VisibilityTimeout: 30 # Fn timeout * 6
SqsManagedSseEnabled: true
RedrivePolicy:
maxReceiveCount: 2
deadLetterTargetArn: !GetAtt SampleDLQ.Arn
KmsMasterKeyId: !Ref CustomerKey

# --------------
# KMS key for encrypted queues
CustomerKey:
Type: AWS::KMS::Key
Properties:
Description: KMS key for encrypted queues
Enabled: true
KeyPolicy:
Version: '2012-10-17'
Statement:
- Sid: Enable IAM User Permissions
Effect: Allow
Principal:
AWS: !Sub 'arn:aws:iam::${AWS::AccountId}:root'
Action: 'kms:*'
Resource: '*'
- Sid: Allow use of the key
Effect: Allow
Principal:
Service: lambda.amazonaws.com
Action:
- kms:Decrypt
- kms:GenerateDataKey
Resource: '*'

CustomerKeyAlias:
Type: AWS::KMS::Alias
Properties:
AliasName: alias/powertools-batch-sqs-demo
TargetKeyId: !Ref CustomerKey
Loading