-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplate.yml
169 lines (157 loc) · 4.42 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
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
AWSTemplateFormatVersion: 2010-09-09
Description: >-
My Secret Backend Stack
Transform:
- AWS::Serverless-2016-10-31
Globals:
Function:
Timeout: 100
Runtime: nodejs14.x
MemorySize: 128
Environment:
Variables:
SECRET_TABLE: !Ref SecretTable
Resources:
ApiGateway:
Type: AWS::Serverless::Api
Properties:
StageName: Prod
Cors:
AllowMethods: "'*'"
AllowHeaders: "'*'"
AllowOrigin: "'*'"
GatewayResponses:
UNAUTHORIZED:
StatusCode: 401
ResponseParameters:
Headers:
Access-Control-Allow-Origin: "'*'"
Access-Control-Allow-Headers: "'*'"
Access-Control-Allow-Methods: "'*'"
DEFAULT_4XX:
ResponseParameters:
Headers:
Access-Control-Allow-Origin: "'*'"
Access-Control-Allow-Headers: "'*'"
Access-Control-Allow-Methods: "'*'"
DEFAULT_5XX:
ResponseParameters:
Headers:
Access-Control-Allow-Origin: "'*'"
Access-Control-Allow-Headers: "'*'"
Access-Control-Allow-Methods: "'*'"
viewSecret:
Type: AWS::Serverless::Function
Properties:
CodeUri: src/handlers/secrets/
Handler: view.handler
AutoPublishAlias: live
Description: To view the secret
Policies:
- DynamoDBReadPolicy:
TableName: !Ref SecretTable
Layers:
- !Ref UtilsLayer
- !Ref ExceptionsLayer
Events:
ApiEvent:
Type: Api
Properties:
RestApiId: !Ref ApiGateway
Path: /secret/{secret}
Method: GET
createSecret:
Type: AWS::Serverless::Function
Properties:
CodeUri: src/handlers/secrets/
Handler: create.handler
AutoPublishAlias: live
Description: To create a secret for a user
Policies:
- DynamoDBWritePolicy:
TableName: !Ref SecretTable
Layers:
- !Ref UtilsLayer
- !Ref ExceptionsLayer
- !Ref NodePackages
Events:
ApiEvent:
Type: Api
Properties:
RestApiId: !Ref ApiGateway
Path: /secret
Method: POST
checkSecret:
Type: AWS::Serverless::Function
Properties:
CodeUri: src/handlers/secrets/
Handler: check.handler
AutoPublishAlias: live
Description: To check if the secret is exist and not opened
Policies:
- DynamoDBReadPolicy:
TableName: !Ref SecretTable
Layers:
- !Ref UtilsLayer
- !Ref ExceptionsLayer
Events:
ApiEvent:
Type: Api
Properties:
RestApiId: !Ref ApiGateway
Path: /secret/{secret}/check
Method: GET
deleteSecret:
Type: AWS::Serverless::Function
Properties:
CodeUri: src/handlers/secrets/
Handler: delete.handler
AutoPublishAlias: live
Description: To delete the secret from database
Policies:
- DynamoDBCrudPolicy:
TableName: !Ref SecretTable
Layers:
- !Ref UtilsLayer
- !Ref ExceptionsLayer
Events:
ApiEvent:
Type: Api
Properties:
RestApiId: !Ref ApiGateway
Path: /secret/{secret}
Method: DELETE
NodePackages:
Type: AWS::Serverless::LayerVersion
Properties:
LayerName: my-secret-app-dependencies
Description: All shared node packages cross lambdas
ContentUri: src/layers/dependencies/
RetentionPolicy: Retain
UtilsLayer:
Type: AWS::Serverless::LayerVersion
Properties:
LayerName: my-secret-utils
Description: Get the shared utils for cross lambdas
ContentUri: src/layers/functions/
RetentionPolicy: Retain
ExceptionsLayer:
Type: AWS::Serverless::LayerVersion
Properties:
LayerName: my-secret-exception-classes
Description: The exceptions thats exist in secret app
ContentUri: src/layers/exceptions/
RetentionPolicy: Retain
SecretTable:
Type: AWS::Serverless::SimpleTable
Properties:
PrimaryKey:
Name: uri
Type: String
ProvisionedThroughput:
ReadCapacityUnits: 2
WriteCapacityUnits: 2
Outputs:
WebEndpoint:
Description: "API Gateway endpoint URL for Prod stage"
Value: !Sub 'https://${ApiGateway}.execute-api.${AWS::Region}.amazonaws.com/${ApiGateway.Stage}/'