-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtemplate.yml
101 lines (96 loc) · 2.55 KB
/
template.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
AWSTemplateFormatVersion: 2010-09-09
Transform:
- AWS::Serverless-2016-10-31
Resources:
#region CreateOrder function
CreateOrderFunction:
Type: AWS::Serverless::Function
Properties:
FunctionName: CreateOrder
Handler: orders/src/create-order-lambda.handler
Runtime: nodejs12.x
Environment:
Variables:
QUEUE_URL: !Ref OrdersQueue
Role:
Fn::GetAtt:
- CreateOrderFunctionRole
- Arn
CreateOrderFunctionRole:
Type: AWS::IAM::Role
Properties:
RoleName: CreateOrderFunctionRole
AssumeRolePolicyDocument:
Statement:
- Effect: Allow
Principal:
Service: [lambda.amazonaws.com]
Action: sts:AssumeRole
Path: /
ManagedPolicyArns:
- !Sub 'arn:${AWS::Partition}:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole'
Policies:
- PolicyName: CreateOrder
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action:
- 'sqs:SendMessage'
Resource:
- Fn::GetAtt:
- "OrdersQueue"
- "Arn"
#endregion
#region AddOrder function
AddOrderFunction:
Type: AWS::Serverless::Function
Properties:
FunctionName: AddOrder
Handler: list-of-orders/src/add-order-lambda.handler
Runtime: nodejs12.x
Role:
Fn::GetAtt:
- AddOrderFunctionRole
- Arn
Events:
Mapping:
Type: SQS
Properties:
BatchSize: 1
Queue:
Fn::GetAtt:
- "OrdersQueue"
- "Arn"
AddOrderFunctionRole:
Type: AWS::IAM::Role
Properties:
RoleName: AddOrderFunctionRole
AssumeRolePolicyDocument:
Statement:
- Effect: Allow
Principal:
Service: [lambda.amazonaws.com]
Action: sts:AssumeRole
Path: /
ManagedPolicyArns:
- !Sub 'arn:${AWS::Partition}:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole'
Policies:
- PolicyName: AddOrder
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action:
- 'sqs:ReceiveMessage'
- 'sqs:DeleteMessage'
- 'sqs:GetQueueAttributes'
Resource:
- Fn::GetAtt:
- "OrdersQueue"
- "Arn"
#endregion
OrdersQueue:
Type: AWS::SQS::Queue
Properties:
QueueName: Orders