-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserverless.yml
More file actions
145 lines (131 loc) · 4.24 KB
/
serverless.yml
File metadata and controls
145 lines (131 loc) · 4.24 KB
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
139
140
141
142
143
144
145
service: messaging-api
provider:
name: aws
region: eu-west-1
runtime: nodejs8.10
iamRoleStatements:
- Effect: Allow
Action:
- SNS:Publish
Resource:
- ${self:custom.SNSSendEmailTopicArn}
- ${self:custom.SNSSmsEmailTopicArn}
- Effect: Allow
Action:
- dynamodb:PutItem
- dynamodb:UpdateItem
- dynamodb:DeleteItem
Resource: arn:aws:dynamodb:${self:provider.region}:*:table/*
- Effect: Allow
Action:
- ses:SendEmail
Resource: arn:aws:ses:${self:provider.region}:539272187627:identity/*
- Effect: Allow
Action:
- dynamodb:PutItem
- dynamodb:UpdateItem
- dynamodb:DeleteItem
Resource: arn:aws:dynamodb:${self:provider.region}:*:table/*
- Effect: Allow
Action:
- dynamodb:Query
- dynamodb:Scan
- dynamodb:GetItem
Resource: arn:aws:dynamodb:${self:provider.region}:*:table/*
environment:
REPLAY_EMAIL: support@example.com
MESSAGES_DYNAMODB_TABLE: ${self:custom.DynamoMessagesTable}
custom:
prefix: ${self:service}-${opt:stage, self:provider.stage}
SNSSendEmailTopicName: ${self:custom.prefix}-email-topic
SNSSendSmsTopicName: ${self:custom.prefix}-sms-topic
SNSSaveEmailToDbTopicName: ${self:custom.SNSSendEmailTopicName}
SNSSaveSmsToDbTopicName: ${self:custom.SNSSendSmsTopicName}
SNSSendEmailTopicArn: arn:aws:sns:${self:provider.region}:#{AWS::AccountId}:${self:custom.SNSSendEmailTopicName}
SNSSmsEmailTopicArn: arn:aws:sns:${self:provider.region}:#{AWS::AccountId}:${self:custom.SNSSendSmsTopicName}
DynamoMessagesTable: ${self:custom.prefix}-messages-table
documentation:
api:
info:
version: '2'
title: Messaging api
models:
- name: SendEmailRequest
contentType: "application/json"
schema: ${file(./schemas/sendEmailRequestSchema.json)}
- name: SendSmsRequest
contentType: "application/json"
schema: ${file(./schemas/sendSmsRequestSchema.json)}
functions:
apiSendEmail:
handler: src/api/emailsPost.handleEmailPostRequest
environment:
SNS_TOPIC_EMAIL_ARN: ${self:custom.SNSSendEmailTopicArn, env:SNS_TOPIC_EMAIL_ARN}
events:
- http:
path: emails
method: post
reqValidatorName: onlyBody
documentation:
summary: Send email
description: Send email to recipient
requestModels:
"application/json": SendEmailRequest
apiGetEmail:
handler: src/api/emailsGet.getEmailsHandler
environment:
MESSAGES_DYNAMODB_TABLE: ${self:custom.DynamoMessagesTable}
events:
- http:
path: emails/{recipient}
method: get
apiSendSms:
handler: src/api/smsPost.handleSmsPostRequest
environment:
SNS_TOPIC_SMS_ARN: ${self:custom.SNSSmsEmailTopicArn, env:SNS_TOPIC_SMS_ARN}
events:
- http:
path: sms
method: post
reqValidatorName: onlyBody
documentation:
summary: Send sms
description: Send sms to recipient
requestModels:
"application/json": SendSmsRequest
apiGetSms:
handler: src/api/smsGet.getSmsHandler
environment:
MESSAGES_DYNAMODB_TABLE: ${self:custom.DynamoMessagesTable}
events:
- http:
path: sms/{recipient}
method: get
sendEmail:
handler: src/services/email.sendEmailHandler
events:
- sns: ${self:custom.SNSSendEmailTopicName}
sendSms:
handler: src/services/sms.sendSms
events:
- sns: ${self:custom.SNSSendSmsTopicName}
saveEmail:
handler: src/services/store.saveMessagesHandler
environment:
MESSAGES_DYNAMODB_TABLE: ${self:custom.DynamoMessagesTable}
events:
- sns: ${self:custom.SNSSaveEmailToDbTopicName}
saveSms:
handler: src/services/store.saveMessagesHandler
environment:
MESSAGES_DYNAMODB_TABLE: ${self:custom.DynamoMessagesTable}
events:
- sns: ${self:custom.SNSSaveSmsToDbTopicName}
resources:
- ${file(resources/dynamoDb.yml)}
- ${file(resources/requestValidators.yml)}
plugins:
- serverless-pseudo-parameters
- serverless-plugin-typescript
- serverless-reqvalidator-plugin
- serverless-aws-documentation