-
Notifications
You must be signed in to change notification settings - Fork 0
/
serverless.yml
174 lines (159 loc) · 4.99 KB
/
serverless.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
170
171
172
173
174
# Welcome to Serverless!
#
# This file is the main config file for your service.
# It's very minimal at this point and uses default values.
# You can always add more config options for more control.
# We've included some commented out config examples here.
# Just uncomment any of them to get that config option.
#
# For full config options, check the docs:
# docs.serverless.com
#
# Happy Coding!
service: tgupta-me-contact-me
provider:
name: aws
runtime: python2.7
region: us-east-1
stage: dev
environment:
GOOGLE_SECRET_NAME: 'google-recaptcha-secret'
STAGE: '${self:custom.stage}'
SNS_TOPIC: '${self:custom.snstopicArn}'
iamRoleStatements:
$ref: ./config/tgupta-me-contact-me-iam-role.json
package:
exclude:
- node_modules/
- README.md
- requirements.txt
- src/tests/
functions:
contactme:
handler: src/contactme/contactme.lambda_handler
custom:
stage: ${opt:stage, self:provider.stage}
vars: ${file(serverless_vars.yml):${self:custom.stage}}
pythonRequirements:
dockerizePip: non-linux
snstopicArn:
Fn::Join:
- ''
- - 'arn:aws:sns:'
- Ref: AWS::Region
- ":"
- Ref: AWS::AccountId
- ":"
- "tgupta-me-contactme-topic"
plugins:
- serverless-python-requirements
resources:
Resources:
ApiGatewayContactUs:
Type: AWS::ApiGateway::RestApi
Properties:
Name: tgupta-me-contact-me-${self:custom.stage}
ApiGatewayResource:
Type: AWS::ApiGateway::Resource
Properties:
ParentId:
Fn::GetAtt:
- ApiGatewayContactUs
- RootResourceId
PathPart: api
RestApiId:
Ref: ApiGatewayContactUs
ApiGatewayMethodOptions:
Type: AWS::ApiGateway::Method
Properties:
AuthorizationType: NONE
ResourceId:
Ref: ApiGatewayResource
RestApiId:
Ref: ApiGatewayContactUs
HttpMethod: OPTIONS
Integration:
IntegrationResponses:
- StatusCode: 200
ResponseParameters:
method.response.header.Access-Control-Allow-Headers: "'Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token,X-Amz-User-Agent'"
method.response.header.Access-Control-Allow-Methods: "'POST,OPTIONS'"
method.response.header.Access-Control-Allow-Origin: "'*'"
method.response.header.Access-Control-Allow-Credentials: "'false'"
ResponseTemplates:
application/json: ''
PassthroughBehavior: WHEN_NO_MATCH
RequestTemplates:
application/json: '{"statusCode": 200}'
Type: MOCK
MethodResponses:
- StatusCode: 200
ResponseModels:
application/json: 'Empty'
ResponseParameters:
method.response.header.Access-Control-Allow-Headers: false
method.response.header.Access-Control-Allow-Methods: false
method.response.header.Access-Control-Allow-Origin: false
method.response.header.Access-Control-Allow-Credentials: true
ApiGatewayMethodPost:
Type: AWS::ApiGateway::Method
Properties:
HttpMethod: POST
RequestParameters: {}
ResourceId:
Ref: ApiGatewayResource
RestApiId:
Ref: ApiGatewayContactUs
AuthorizationType: NONE
Integration:
IntegrationHttpMethod: POST
Type: AWS_PROXY
Uri:
Fn::Join:
- ''
- - 'arn:aws:apigateway:'
- Ref: AWS::Region
- ':lambda:path/2015-03-31/functions/'
- Fn::GetAtt:
- ContactmeLambdaFunction
- Arn
- '/invocations'
MethodResponses: []
ApiGatewayDeployment:
Type: AWS::ApiGateway::Deployment
Properties:
RestApiId:
Ref: ApiGatewayContactUs
StageName: prod
DependsOn:
- ApiGatewayMethodPost
- ApiGatewayMethodOptions
ContactUsFunctionPermission:
Type: AWS::Lambda::Permission
DependsOn:
- ApiGatewayDeployment
Properties:
Action: lambda:invokeFunction
FunctionName:
Ref: ContactmeLambdaFunction
Principal: apigateway.amazonaws.com
SourceArn:
Fn::Join:
- ''
- - 'arn:aws:execute-api:'
- Ref: AWS::Region
- ':'
- Ref: AWS::AccountId
- ':'
- Ref: ApiGatewayContactUs
- '/*/*'
ApiGatewayBasePathMapping:
Type: AWS::ApiGateway::BasePathMapping
DependsOn:
- ContactUsFunctionPermission
Properties:
BasePath: prod # Change this to whatever you want your base path to be
DomainName: ${self:custom.vars.RECORD} # Change this to however you manage your domains
RestApiId:
Ref: ApiGatewayContactUs
Stage: prod