forked from aws/serverless-application-model
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplate.yaml
44 lines (40 loc) · 1.27 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
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: CORS enabled API Gateway that uses a Lambda TOKEN Authorizer by default
Resources:
MyApi:
Type: AWS::Serverless::Api
Properties:
StageName: Prod
Auth:
DefaultAuthorizer: MyAuthorizer
AddDefaultAuthorizerToCorsPreflight: false # removes MyAuthorizer from the automatically created OPTIONS methods
Authorizers:
MyAuthorizer:
FunctionArn: !GetAtt AuthorizerFunction.Arn
Cors:
AllowHeaders: "'Authorization'" # this is the default header used by TOKEN authorizers
AllowOrigin: "'http://localhost:8080'"
AuthorizerFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: src/
Handler: authorizer.handler
Runtime: nodejs10.x
HelloWorldFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: src/
Handler: index.handler
Runtime: nodejs10.x
Events:
HelloWorld:
Type: Api
Properties:
RestApiId: !Ref MyApi
Path: /
Method: get
Outputs:
HelloWorldUrl:
Description: 'HelloWorldFunction Prod stage URL'
Value: !Sub 'https://${MyApi}.execute-api.${AWS::Region}.amazonaws.com/Prod/'