-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserverless.cdc.yml
138 lines (128 loc) · 3.69 KB
/
serverless.cdc.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
service: dynamodb-outbox-demo-cdc
provider:
name: aws
runtime: nodejs18.x
architecture: arm64
stage: ${opt:stage, "prod"}
region: ${opt:region, "eu-north-1"}
memorySize: ${opt:memory, 1024}
timeout: 10
logRetentionInDays: 7
versionFunctions: false
deploymentBucket:
blockPublicAccess: true
maxPreviousDeploymentArtifacts: 5
serverSideEncryption: AES256
stackTags:
service: ${self:service}
stage: ${self:provider.stage}
runtime: ${self:provider.runtime}
region: ${self:provider.region}
tags:
service: ${self:service}
stage: ${self:provider.stage}
runtime: ${self:provider.runtime}
region: ${self:provider.region}
apiGateway:
minimumCompressionSize: 1024
plugins:
- serverless-esbuild
- serverless-offline
- serverless-iam-roles-per-function
package:
individually: true
custom:
config:
awsAccountNumber: "123412341234"
eventBusName: ${self:service}
tableName: ${self:service}
aws:
eventBusArn: arn:aws:events:${self:provider.region}:${self:custom.config.awsAccountNumber}:event-bus/${self:custom.config.eventBusName}
tableArn: arn:aws:dynamodb:${self:provider.region}:${self:custom.config.awsAccountNumber}:table/${self:custom.config.tableName}
# The functions are ordered in the logical order they are run
functions:
AddBook:
handler: src/AddBookCDC.handler
description: Adds a book to the collection
events:
- httpApi:
method: POST
path: /book
iamRoleStatements:
- Effect: "Allow"
Action:
- dynamodb:PutItem
Resource: ${self:custom.aws.tableArn}
environment:
REGION: ${self:provider.region}
TABLE_NAME: ${self:custom.config.tableName}
RemoveBook:
handler: src/RemoveBookCDC.handler
description: Removes a book from the collection
events:
- httpApi:
method: DELETE
path: /book
iamRoleStatements:
- Effect: "Allow"
Action:
- dynamodb:DeleteItem
Resource: ${self:custom.aws.tableArn}
environment:
REGION: ${self:provider.region}
TABLE_NAME: ${self:custom.config.tableName}
ChangeProcessor:
handler: src/ChangeProcessor.handler
description: Lambda that acts on data changes in DynamoDB
events:
- stream:
type: dynamodb
arn:
Fn::GetAtt:
- OutboxTable
- StreamArn
iamRoleStatements:
- Effect: "Allow"
Action:
- events:PutEvents
Resource: ${self:custom.aws.eventBusArn}
environment:
REGION: ${self:provider.region}
EVENT_BUS_NAME: ${self:custom.config.eventBusName}
BookAdded:
handler: src/BookAddedCDC.handler
description: Respond to a book being added
events:
- eventBridge:
eventBus: ${self:custom.config.eventBusName} # Creates new EventBridge bus
pattern:
source:
- OutboxDemo.ChangeProcessor
detail-type:
- BookAdded
BookRemoved:
handler: src/BookRemovedCDC.handler
description: Respond to a book being removed
events:
- eventBridge:
eventBus: ${self:custom.config.eventBusName}
pattern:
source:
- OutboxDemo.ChangeProcessor
detail-type:
- BookRemoved
resources:
Resources:
OutboxTable:
Type: AWS::DynamoDB::Table
Properties:
TableName: ${self:custom.config.tableName}
AttributeDefinitions:
- AttributeName: name
AttributeType: S
KeySchema:
- AttributeName: name
KeyType: HASH
StreamSpecification:
StreamViewType: NEW_IMAGE
BillingMode: PAY_PER_REQUEST