-
Notifications
You must be signed in to change notification settings - Fork 0
/
serverless.ts
132 lines (123 loc) · 3.56 KB
/
serverless.ts
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
import type { AWS } from '@serverless/typescript'
import { getArn, iamAllow, INTERNAL_STAGE, join } from '@utils/index'
import { EVENT_STORE_TOPIC } from '@utils/cf-utils'
// dbs
import ordersTable from '@clients/db/projection/resources'
import eventStoreTable from '@clients/db/event-store/resources'
// mutations
import createOrder from '@functions/api/commands/create-order'
import updateOrder from '@functions/api/commands/update-order'
import deleteOrder from '@functions/api/commands/delete-order'
// queries
import getOrderById from '@functions/api/queries/get-order-by-id'
import getOrdersInProgress from '@functions/api/queries/get-orders-in-progress'
// sns topics
import eventStoreTopic from '@clients/sns/resources'
// event handlers with sqs queues
import {
orderCreatedEventHandler,
orderCreatedEventHandlerConfig,
} from '@functions/events/order-created'
import {
orderUpdatedEventHandler,
orderUpdatedEventHandlerConfig,
} from '@functions/events/order-updated'
import {
orderDeletedEventHandler,
orderDeletedEventHandlerConfig,
} from '@functions/events/order-deleted'
// domain event dispatcher
import eventDispatcher from '@functions/events/event-dispatcher'
const serverlessConfiguration: AWS = {
service: 'starcups',
frameworkVersion: '3',
plugins: ['serverless-esbuild', 'serverless-offline'],
provider: {
name: 'aws',
runtime: 'nodejs16.x',
region: 'us-east-1',
apiGateway: {
minimumCompressionSize: 1024,
shouldStartNameWithService: true,
},
environment: {
AWS_NODEJS_CONNECTION_REUSE_ENABLED: '1',
NODE_OPTIONS: '--enable-source-maps --stack-trace-limit=1000',
EVENT_STORE_TABLE: `orders-event-store-${INTERNAL_STAGE}`,
PROJECTION_TABLE_NAME: `orders-projection-${INTERNAL_STAGE}`,
DOMAIN_EVENT_TOPIC: { Ref: EVENT_STORE_TOPIC },
},
iamRoleStatements: [
iamAllow(
[
'dynamodb:Query',
'dynamodb:PutItem',
'dynamodb:UpdateItem',
'dynamodb:BatchWriteItem',
'dynamodb:DeleteItem',
],
[getArn('OrdersTable'), join('/', getArn('OrdersTable'), 'index/*')],
),
iamAllow(
[
'dynamodb:PutItem',
'dynamodb:GetItem',
'dynamodb:Query',
'dynamodb:DescribeStream',
],
[getArn('EventStore')],
),
{
Effect: 'Allow',
Action: ['sns:Publish'],
Resource: { Ref: 'EventStoreTopic' },
},
],
},
// import the function via paths
functions: {
eventDispatcher,
createOrder,
updateOrder,
deleteOrder,
getOrderById,
getOrdersInProgress,
orderCreatedEventHandler,
orderUpdatedEventHandler,
orderDeletedEventHandler,
},
resources: {
Resources: {
...orderCreatedEventHandlerConfig.resources,
...orderUpdatedEventHandlerConfig.resources,
...orderDeletedEventHandlerConfig.resources,
OrdersTable: ordersTable,
EventStore: eventStoreTable,
EventStoreTopic: eventStoreTopic,
},
},
package: { individually: true },
custom: {
esbuild: {
bundle: true,
minify: false,
sourcemap: true,
exclude: ['aws-sdk'],
target: 'node14',
define: { 'require.resolve': undefined },
platform: 'node',
concurrency: 10,
},
stageConfig: {
// only for demonstration purposes
// this is how we set environment variables for different stages
dev: {
someExternalArn: 'arn:aws',
},
prod: {
someExternalArn: 'arn:aws',
},
},
},
}
module.exports = serverlessConfiguration