-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplate.yaml
94 lines (89 loc) · 2.39 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
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: Serverless patterns - Amazon API Gateway to AWS Lambda to Amazon DynamoDB
Parameters:
ENVIRONMENT:
Type: String
Description: AWS Environment where code is being executed (dev or prod).
Default: "dev"
DYNAMO_URL:
Type: String
Description: AWS local DynamoDB instance URI (will only be used if ENVIRONMENT is "dev")
# Default: "http://localhost:8000"
Default: "http://host.docker.internal:8000"
TABLE_NAME:
Type: String
Description: DynamoDB table name.
Default: "todo_1"
Resources:
Index:
Type: AWS::Serverless::Function
Properties:
Handler: index.handler
Runtime: python3.9
Timeout: 10
CodeUri: src/
Policies:
DynamoDBCrudPolicy:
TableName: !Ref TABLE_NAME
Environment:
Variables:
ENVIRONMENT: !Ref ENVIRONMENT
DYNAMO_URL: !Ref DYNAMO_URL
TABLE_NAME: !Ref TABLE_NAME
Events:
ApiEvent:
Type: Api
Properties:
Path: /todos/list
Method: GET
Create:
Type: AWS::Serverless::Function
Properties:
Handler: create.handler
Runtime: python3.9
Timeout: 10
CodeUri: src/
Policies:
DynamoDBCrudPolicy:
TableName: !Ref TABLE_NAME
Environment:
Variables:
ENVIRONMENT: !Ref ENVIRONMENT
DYNAMO_URL: !Ref DYNAMO_URL
TABLE_NAME: !Ref TABLE_NAME
Events:
ApiEvent:
Type: Api
Properties:
Path: /todos/create
Method: POST
Delete:
Type: AWS::Serverless::Function
Properties:
Handler: delete.handler
Runtime: python3.9
Timeout: 10
CodeUri: src/
Policies:
DynamoDBCrudPolicy:
TableName: !Ref TABLE_NAME
Environment:
Variables:
ENVIRONMENT: !Ref ENVIRONMENT
DYNAMO_URL: !Ref DYNAMO_URL
TABLE_NAME: !Ref TABLE_NAME
Events:
ApiEvent:
Type: Api
Properties:
Path: /todos/delete/{pk}
Method: DELETE
DynamoDBTable:
Type: AWS::Serverless::SimpleTable
Properties:
TableName: ToDos
Outputs:
EndpointUrl:
Description: 'HTTP REST endpoint URL'
Value: !Sub 'https://${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com/Prod'