generated from raulcorreia7/Best-README-Template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserverless.yml
125 lines (116 loc) · 3.3 KB
/
serverless.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
org: raulcorreia7
app: tmpro-challenge
service: raul-project
frameworkVersion: "2"
provider:
name: aws
runtime: nodejs14.x
lambdaHashingVersion: 20201221
stage: ${opt:stage, 'dev'}
region: eu-central-1
environment:
MESSAGE_TOPIC_NAME: ${self:custom.topicName}
MESSAGE_TOPIC_ARN: ${self:custom.topicArn}
DYNAMODB_TABLE: ${self:service}-${self:provider.stage}
EMAIL_ARN: arn:aws:ses:eu-central-1:061659491951:identity/[email protected]
FROM_NAME: "Raúl Correia"
FROM_EMAIL: "[email protected]"
iamRoleStatements:
- Effect: "Allow"
Action:
- "sns:*"
- dynamodb:GetItem
- dynamodb:PutItem
- dynamodb:Query"
# SNS:SetSMSAttributes needs to be set manually due to sandbox account.
Resource:
- ${self:custom.topicArn}
- "Fn::GetAtt": [MessageDynamoDbTable, Arn]
- "*"
custom:
topicName: message-topic-channel
# cloud formation intrinstic function to get ARN of topic.
# `MessageTopic` references the cloudformation in `resources`
topicArn:
Fn::Join:
- ""
- - "arn:aws:sns:"
- Ref: AWS::Region
- ":"
- Ref: AWS::AccountId
- ":"
- Fn::GetAtt:
- MessageTopic
- TopicName
functions:
# Create A HTTP Post API to post messages
post-message:
handler: src/post-message.handler
memorySize: 128
events:
- httpApi:
method: POST
path: /message
# Create a HTTP Get API to get Message
get-message:
handler: src/get-message.handler
memorySize: 128
events:
- httpApi:
method: GET
path: /message/{target}
# Create a lambda that listens to SNS topics and saves to DynamoDB
save-message:
handler: src/save-message.handler
memorySize: 128
events:
- sns:
arn: !Ref MessageTopic
topicName: ${self:custom.topicName}
# Creates a lambda that listens to SNS topics, filters delivery by email and sends an email
send-email:
handler: src/send-email.handler
memorySize: 128
events:
- sns:
arn: !Ref MessageTopic
topicName: ${self:custom.topicName}
filterPolicy:
delivery:
- "email"
# Creates a lambda that listens to SNS topics, filters delivery by SMS and sends an SMS
send-sms:
handler: src/send-sms.handler
memorySize: 128
events:
- sns:
arn: !Ref MessageTopic
topicName: ${self:custom.topicName}
filterPolicy:
delivery:
- "sms"
resources:
Resources:
# This creates a new sns topic.
MessageTopic:
Type: AWS::SNS::Topic
Properties:
DisplayName: "Second stand alone topic created via CloudFormation"
TopicName: ${self:custom.topicName}
# This creates a new DynamoDB table
MessageDynamoDbTable:
Type: AWS::DynamoDB::Table
DeletionPolicy: Delete
Properties:
AttributeDefinitions:
- AttributeName: id
AttributeType: S
- AttributeName: target
AttributeType: S
KeySchema:
- AttributeName: target
KeyType: HASH
- AttributeName: id
KeyType: RANGE
BillingMode: PAY_PER_REQUEST
TableName: ${self:provider.environment.DYNAMODB_TABLE}