-
Notifications
You must be signed in to change notification settings - Fork 0
/
template.yaml
141 lines (141 loc) · 3.99 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
129
130
131
132
133
134
135
136
137
138
139
140
141
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: My lambda function to be connected with a react app!
Globals:
Function:
Timeout: 15
Parameters:
STAGE:
Type: String
Default: dev
DynamoDB:
Type: String
Default: FeedbackDB
Resources:
MyApiGateway:
Type: AWS::Serverless::Api
Properties:
StageName: !Ref STAGE
GetFeedbackFunction:
Type: AWS::Serverless::Function
Properties:
FunctionName: !Sub ${AWS::StackName}-getFeedbackLambda
Description: Get feedback function
CodeUri: feedback/
Environment:
Variables:
DynamoTable: !Ref MyDynamoDBTable
DynamoTableARN: !GetAtt MyDynamoDBTable.Arn
Policies:
- DynamoDBCrudPolicy:
TableName: !Ref MyDynamoDBTable
Handler: app.getFeedback
Runtime: nodejs18.x
Architectures:
- x86_64
MemorySize: 128
Events:
GetFeedback:
Type: Api
Properties:
Path: /feedback/{id}
Method: GET
RestApiId: !Ref MyApiGateway
ListFeedbackFunction:
Type: AWS::Serverless::Function
Properties:
FunctionName: !Sub ${AWS::StackName}-listFeedbackLambda
Description: List all feedback function
CodeUri: feedback/
Environment:
Variables:
DynamoTable: !Ref MyDynamoDBTable
DynamoTableARN: !GetAtt MyDynamoDBTable.Arn
Policies:
- DynamoDBCrudPolicy:
TableName: !Ref MyDynamoDBTable
Handler: app.listFeedback
Runtime: nodejs18.x
Architectures:
- x86_64
MemorySize: 128
Events:
ListFeedback:
Type: Api
Properties:
Path: /feedback
Method: GET
RestApiId: !Ref MyApiGateway
PostFeedbackFunction:
Type: AWS::Serverless::Function
Properties:
FunctionName: !Sub ${AWS::StackName}-postFeedbackLambda
Description: Submit feedback function
CodeUri: feedback/
Environment:
Variables:
DynamoTable: !Ref MyDynamoDBTable
DynamoTableARN: !GetAtt MyDynamoDBTable.Arn
Policies:
- DynamoDBCrudPolicy:
TableName: !Ref MyDynamoDBTable
Handler: app.postFeedback
Runtime: nodejs18.x
Architectures:
- x86_64
Events:
PostFeedback:
Type: Api
Properties:
Path: /feedback
Method: POST
RestApiId: !Ref MyApiGateway
DeleteFeedbackFunction:
Type: AWS::Serverless::Function
Properties:
FunctionName: !Sub ${AWS::StackName}-deleteFeedbackLambda
Description: Delete feedback function
CodeUri: feedback/
Environment:
Variables:
DynamoTable: !Ref MyDynamoDBTable
DynamoTableARN: !GetAtt MyDynamoDBTable.Arn
Policies:
- DynamoDBCrudPolicy:
TableName: !Ref MyDynamoDBTable
Handler: app.deleteFeedback
Runtime: nodejs18.x
Architectures:
- x86_64
MemorySize: 128
Events:
DeleteFeedback:
Type: Api
Properties:
Path: /feedback/{id}
Method: DELETE
RestApiId: !Ref MyApiGateway
MyDynamoDBTable:
Type: AWS::DynamoDB::Table
Properties:
TableName: !Ref DynamoDB
AttributeDefinitions:
- AttributeName: id
AttributeType: S
KeySchema:
- AttributeName: id
KeyType: HASH
BillingMode: PAY_PER_REQUEST
Outputs:
MyApiGateway:
Description: API Gateway endpoint URL for Prod stage for Feedback function
Value: !Sub https://${MyApiGateway}.execute-api.${AWS::Region}.amazonaws.com/${STAGE}/feedback/
GetFeedbackFunction:
Description: GET Feedback Lambda Function ARN
Value: !GetAtt GetFeedbackFunction.Arn
PostFeedbackFunction:
Description: POST Feedback Lambda Function ARN
Value: !GetAtt PostFeedbackFunction.Arn
MyDynamoDBTable:
Description: DynamoDB table ARN
Value: !GetAtt MyDynamoDBTable.Arn