-
Notifications
You must be signed in to change notification settings - Fork 0
/
template.yaml
72 lines (65 loc) · 1.97 KB
/
template.yaml
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
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: Form handler to initiate The Machine
# Config applied to all lambda functions.
Globals:
Function:
Timeout: 30
Runtime: nodejs14.x
Environment:
Variables:
REGISTRATION_TOPIC: !Ref RegistrationTopic
REGISTRATION_TABLE: !Ref RegistrationTable
# Okay let's create stuff in AWS!
Resources:
# This is the SNS topic we will pubish our registration events.
RegistrationTopic:
Type: AWS::SNS::Topic
# This is where we will store the registration data.
RegistrationTable:
Type: AWS::DynamoDB::Table
Properties:
AttributeDefinitions:
-
AttributeName: "email"
AttributeType: "S"
KeySchema:
-
AttributeName: "email"
KeyType: "HASH"
ProvisionedThroughput:
ReadCapacityUnits: "5"
WriteCapacityUnits: "5"
# This lambda function handles the form submission from the registrant.
RegisterPostHandler:
Type: AWS::Serverless::Function
Properties:
CodeUri: src/
Handler: post.handler
Events:
Register:
Type: Api
Properties:
Path: /register
Method: post
Policies:
- SNSPublishMessagePolicy:
TopicName: !GetAtt RegistrationTopic.TopicName
# This lambda function consumes the event from SNS and saves the registration to the database.
RegistrationTopicSubscriber:
Type: AWS::Serverless::Function
Properties:
CodeUri: src/
Handler: sns.handler
Events:
RegistrationEvent:
Type: SNS
Properties:
Topic: !Ref RegistrationTopic
Policies:
- DynamoDBCrudPolicy:
TableName: !Ref RegistrationTable
Outputs:
RegistrationApi:
Description: "API Gateway endpoint URL"
Value: !Sub "https://${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com/Prod/register/"