Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save crblack82/cb9eed5740586966e18875cd60000ab9 to your computer and use it in GitHub Desktop.
Save crblack82/cb9eed5740586966e18875cd60000ab9 to your computer and use it in GitHub Desktop.
AWSTemplateFormatVersion: '2010-09-09'
Description: Template to connect DynamoDB Stream to EventBridge
Resources:
OrdersTable:
Type: AWS::DynamoDB::Table
Properties:
TableName:
Fn::Sub: ${AWS::StackName}-orders
AttributeDefinitions:
- AttributeName: id
AttributeType: S
KeySchema:
- AttributeName: id
KeyType: HASH
ProvisionedThroughput:
ReadCapacityUnits: 5
WriteCapacityUnits: 5
StreamSpecification:
StreamViewType: NEW_AND_OLD_IMAGES
ApplicationEventBus:
Type: AWS::Events::EventBus
Properties:
Name:
Fn::Sub: ${AWS::StackName}-bus
PipeDLQueue:
Type: AWS::SQS::Queue
Properties:
QueueName:
Fn::Sub: ${AWS::StackName}-pipe-dlq
PipeRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Principal:
Service:
- pipes.amazonaws.com
Action:
- sts:AssumeRole
Policies:
- PolicyName:
Fn::Sub: ${AWS::StackName}-source-policy
PolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Action:
- dynamodb:DescribeStream
- dynamodb:GetRecords
- dynamodb:GetShardIterator
- dynamodb:ListStreams
Resource:
Fn::GetAtt:
- OrdersTable
- StreamArn
- PolicyName:
Fn::Sub: ${AWS::StackName}-target-policy
PolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Action:
- events:PutEvents
Resource:
Fn::GetAtt:
- ApplicationEventBus
- Arn
OrderCreatedPipe:
Type: AWS::Pipes::Pipe
Properties:
Name:
Fn::Sub: ${AWS::StackName}-order-created
Description: Pipes to connect to DDB stream listening only for insert changes
RoleArn:
Fn::GetAtt:
- PipeRole
- Arn
Source:
Fn::GetAtt:
- OrdersTable
- StreamArn
SourceParameters:
FilterCriteria:
Filters:
- Pattern: '{ "eventName": ["INSERT"] }'
DynamoDBStreamParameters:
StartingPosition: LATEST
BatchSize: 1
DeadLetterConfig:
Arn:
Fn::GetAtt:
- PipeDLQueue
- Arn
Target:
Fn::GetAtt:
- ApplicationEventBus
- Arn
TargetParameters:
EventBridgeEventBusParameters:
DetailType: OrderCreated
Source: myapp.orders
OrderUpdatedPipe:
Type: AWS::Pipes::Pipe
Properties:
Name:
Fn::Sub: ${AWS::StackName}-order-updated
Description: Pipes to connect to DDB stream listening only for modify changes
RoleArn:
Fn::GetAtt:
- PipeRole
- Arn
Source:
Fn::GetAtt:
- OrdersTable
- StreamArn
SourceParameters:
FilterCriteria:
Filters:
- Pattern: '{ "eventName": ["MODIFY"] }'
DynamoDBStreamParameters:
StartingPosition: LATEST
BatchSize: 1
DeadLetterConfig:
Arn:
Fn::GetAtt:
- PipeDLQueue
- Arn
Target:
Fn::GetAtt:
- ApplicationEventBus
- Arn
TargetParameters:
EventBridgeEventBusParameters:
DetailType: OrderUpdated
Source: myapp.orders
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment