-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplate.yml
124 lines (119 loc) · 4.08 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
AWSTemplateFormatVersion: "2010-09-09"
Transform: AWS::Serverless-2016-10-31
Resources:
ContactFormApiDataBucket:
Type: AWS::S3::Bucket
Properties:
BucketName: contact-form-api-data-bucket
ContactFormApi:
Type: AWS::Serverless::Api
Properties:
StageName: prod
Cors:
AllowOrigin: "'*'"
AllowMethods: "'OPTIONS,GET,POST'"
AllowHeaders: "'Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token'"
ContactFormApiSaveMessage:
Type: AWS::Serverless::Function
Properties:
Handler: index.saveMessage
Runtime: nodejs18.x
CodeUri: ./lambda
MemorySize: 128
Timeout: 10
Policies:
- S3ReadPolicy:
BucketName: !Ref ContactFormApiDataBucket
- S3WritePolicy:
BucketName: !Ref ContactFormApiDataBucket
Environment:
Variables:
BUCKET_NAME: !Ref ContactFormApiDataBucket
Events:
ApiGateway:
Type: Api
Properties:
RestApiId: !Ref ContactFormApi
Path: /
Method: POST
Auth:
ApiKeyRequired: true
ContactFormApiRetrieveMessage:
Type: AWS::Serverless::Function
Properties:
Handler: index.retrieveMessages
Runtime: nodejs18.x
CodeUri: ./lambda
MemorySize: 128
Timeout: 10
Policies:
- S3ReadPolicy:
BucketName: !Ref ContactFormApiDataBucket
Environment:
Variables:
BUCKET_NAME: !Ref ContactFormApiDataBucket
Events:
ApiGateway:
Type: Api
Properties:
RestApiId: !Ref ContactFormApi
Path: /{email}
Method: GET
Auth:
ApiKeyRequired: true
ContactFormApiOptions:
Type: AWS::Serverless::Function
Properties:
Handler: index.optionsHandler
Runtime: nodejs18.x
CodeUri: ./lambda
MemorySize: 128
Timeout: 10
Events:
ApiGatewayRootOptions:
Type: Api
Properties:
RestApiId: !Ref ContactFormApi
Path: /
Method: OPTIONS
ApiGatewayEmailOptions:
Type: Api
Properties:
RestApiId: !Ref ContactFormApi
Path: /{email}
Method: OPTIONS
ContactFormApiKey:
Type: AWS::ApiGateway::ApiKey
Properties:
Enabled: true
Name: ContactFormApiKey
StageKeys:
- RestApiId: !Ref ContactFormApi
StageName: prod
ContactFormApiUsagePlan:
Type: AWS::ApiGateway::UsagePlan
Properties:
UsagePlanName: ContactFormApiUsagePlan
Description: "Usage plan for the contact form API"
ApiStages:
- ApiId: !Ref ContactFormApi
Stage: prod
Throttle:
BurstLimit: 100
RateLimit: 50
ContactFormApiUsagePlanKey:
Type: AWS::ApiGateway::UsagePlanKey
Properties:
KeyId: !Ref ContactFormApiKey
KeyType: API_KEY
UsagePlanId: !Ref ContactFormApiUsagePlan
Outputs:
ApiKey:
Description: "API Key for accessing the endpoint"
Value: !Ref ContactFormApiKey
ApiUrl:
Description: "API Gateway endpoint URL"
Value: !Sub "https://${ContactFormApi}.execute-api.${AWS::Region}.amazonaws.com/prod/"
BucketName:
Description: "S3 Bucket Name"
Value: !Ref ContactFormApiDataBucket