-
Notifications
You must be signed in to change notification settings - Fork 0
/
template.yaml
128 lines (118 loc) · 4.49 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
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
# This is the SAM template that represents the architecture of your serverless application
# https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-template-basics.html
# The AWSTemplateFormatVersion identifies the capabilities of the template
# https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/format-version-structure.html
AWSTemplateFormatVersion: 2010-09-09
Description: sam-delivery-order-ms
# Transform section specifies one or more macros that AWS CloudFormation uses to process your template
# https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/transform-section-structure.html
Transform: AWS::Serverless-2016-10-31
# Resources declares the AWS resources that you want to include in the stack
# https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/resources-section-structure.html
Resources:
DeliveryOrderFifoQueue:
Type: AWS::SQS::Queue
Properties:
FifoQueue: true
ContentBasedDeduplication: true
RequestDeliveryTopic:
Type: AWS::SNS::Topic
Properties:
TopicName: RequestDeliveryTopic
Subscription:
- Endpoint: #https://first.provider/example/url
Protocol: https
- Endpoint: #https://first.provider/example/url
Protocol: https
# Each Lambda function is defined by properties:
# https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
# This is a Lambda function config associated with the source code: post-delivery-order.js
postDeliveryOrderFunction:
Type: AWS::Serverless::Function
Properties:
Handler: src/handlers/post-delivery-order.postDeliveryOrderHandler
Runtime: nodejs14.x
Architectures:
- x86_64
MemorySize: 128
Timeout: 3
Description: Publish a new delivery order into the queue
Environment:
Variables:
SQSqueueName: !Ref DeliveryOrderFifoQueue
Policies:
## Read more about SAM Policy templates at:
## https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-policy-templates.html
- SQSSendMessagePolicy:
QueueName: !GetAtt DeliveryOrderFifoQueue.QueueName
Events:
Api:
Type: Api
Properties:
Path: /
Method: POST
putDeliveryOrderFunction:
Type: AWS::Serverless::Function
Properties:
Handler: src/handlers/update-delivery-order.putDeliveryOrderHandler
Runtime: nodejs14.x
Architectures:
- x86_64
MemorySize: 128
Timeout: 3
Description: Publish a new delivery order into the queue
Environment:
Variables:
# Make table name accessible as environment variable from function code during execution
TABLE: !Ref DeliveryOderTable
Policies:
- DynamoDBCrudPolicy:
TableName: !Ref DeliveryOderTable
Events:
Api:
Type: Api
Properties:
Path: /
Method: PUT
DeliveryOrderQueueSubscriberFunction:
Type: AWS::Serverless::Function
Properties:
Handler: src/handlers/delivery-order-subscriber.deliveryOrderSubscriberHandler
Runtime: nodejs14.x
MemorySize: 128
Timeout: 3
Description: Subscribe to the delivery order queue to receive delivery order creation events
# ReservedConcurrentExecutions: 1
Environment:
Variables:
# Make table name accessible as environment variable from function code during execution
TABLE: !Ref DeliveryOderTable
TOPIC: !Ref RequestDeliveryTopic
Policies:
- SQSPollerPolicy:
QueueName: !GetAtt DeliveryOrderFifoQueue.QueueName
- DynamoDBCrudPolicy:
TableName: !Ref DeliveryOderTable
- SNSPublishMessagePolicy:
TopicName: !GetAtt RequestDeliveryTopic.TopicName
Events:
NewDeliveryOrderEvent:
Type: SQS
Properties:
Queue: !GetAtt DeliveryOrderFifoQueue.Arn
BatchSize: 10
# DynamoDB table to store delivery request
DeliveryOderTable:
Type: AWS::Serverless::SimpleTable
Properties:
TableName: delivery_order
PrimaryKey:
Name: id
Type: String
ProvisionedThroughput:
ReadCapacityUnits: 2
WriteCapacityUnits: 2
Outputs:
WebEndpoint:
Description: "API Gateway endpoint URL for Prod stage"
Value: !Sub "https://${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com/Prod/"