-
Notifications
You must be signed in to change notification settings - Fork 0
/
template.yaml
executable file
·150 lines (141 loc) · 4.63 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
142
143
144
145
146
147
148
149
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: >
todo-list-aws
Application TODO-LIST with SAM format
# Parameters
Parameters:
Stage:
Type: String
Default: default
AllowedValues:
- default
- staging
- production
Description: Enter staging or production. Default is default
# More info about Globals: https://github.com/awslabs/serverless-application-model/blob/master/docs/globals.rst
Globals:
Function:
Timeout: 3
Environment:
Variables:
DYNAMODB_TABLE: !Ref TodosDynamoDbTable
ENDPOINT_OVERRIDE: ""
Resources:
CreateTodoFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: src/
Role: !Sub "arn:aws:iam::${AWS::AccountId}:role/LabRole"
Handler: create.create
Runtime: python3.7
Events:
Create:
Type: Api
Properties:
Path: /todos
Method: post
ListTodosFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: src/
Role: !Sub "arn:aws:iam::${AWS::AccountId}:role/LabRole"
Handler: list.list
Runtime: python3.7
AutoPublishAlias: prod
Events:
Create:
Type: Api
Properties:
Path: /todos
Method: get
GetTodoFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: src/
Role: !Sub "arn:aws:iam::${AWS::AccountId}:role/LabRole"
Handler: get.get
Runtime: python3.7
Events:
Create:
Type: Api
Properties:
Path: /todos/{id}
Method: get
GetTranslateTodoFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: src/
Role: !Sub "arn:aws:iam::${AWS::AccountId}:role/LabRole"
Handler: getTranslate.getTranslate
Runtime: python3.7
Events:
Create:
Type: Api
Properties:
Path: /todos/{id}/{language}
Method: get
UpdateTodoFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: src/
Role: !Sub "arn:aws:iam::${AWS::AccountId}:role/LabRole"
Handler: update.update
Runtime: python3.7
Events:
Create:
Type: Api
Properties:
Path: /todos/{id}
Method: put
DeleteTodoFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: src/
Role: !Sub "arn:aws:iam::${AWS::AccountId}:role/LabRole"
Handler: delete.delete
Runtime: python3.7
Events:
Create:
Type: Api
Properties:
Path: /todos/{id}
Method: delete
TodosDynamoDbTable:
Type: AWS::DynamoDB::Table
Properties:
TableName: !Sub "${Stage}-TodosDynamoDbTable"
AttributeDefinitions:
- AttributeName: id
AttributeType: S
KeySchema:
- AttributeName: id
KeyType: HASH
ProvisionedThroughput:
ReadCapacityUnits: 1
WriteCapacityUnits: 1
Outputs:
# ServerlessRestApi is an implicit API created out of Events key under Serverless::Function
# Find out more about other implicit resources you can reference within SAM
# https://github.com/awslabs/serverless-application-model/blob/master/docs/internals/generated_resources.rst#api
BaseUrlApi:
Description: "Base URL of API"
Value: !Sub "https://${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com/Prod"
CreateTodoApi:
Description: "API Gateway endpoint URL for ${opt:stage} stage for Create TODO"
Value: !Sub "https://${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com/Prod/todos/"
ListTodosApi:
Description: "API Gateway endpoint URL for ${opt:stage} stage for List TODO"
Value: !Sub "https://${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com/Prod/todos"
GetTodoApi:
Description: "API Gateway endpoint URL for ${opt:stage} stage for Get TODO"
Value: !Sub "https://${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com/Prod/todos/{id}"
GetTranslateTodoApi:
Description: "API Gateway endpoint URL for ${opt:stage} stage for Get TODO"
Value: !Sub "https://${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com/Prod/todos/{id}/{language}"
UpdateTodoApi:
Description: "API Gateway endpoint URL for ${opt:stage} stage for Update TODO"
Value: !Sub "https://${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com/Prod/todos/{id}"
DeleteTodoApi:
Description: "API Gateway endpoint URL for ${opt:stage} stage for Delete TODO"
Value: !Sub "https://${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com/Prod/todos/{id}"