-
Notifications
You must be signed in to change notification settings - Fork 969
/
Copy pathtemplate.yaml
116 lines (107 loc) · 4.03 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: API Gateway REST API with Lambda Proxy integration and CORS enabled (uksb-1tthgi812) (tag:apigw-cors-proxy)
Resources:
ApiGatewayRestApi:
Type: AWS::ApiGateway::RestApi
Properties:
Description: API with Cors Support
EndpointConfiguration:
Types:
- REGIONAL
Name: cors-api
ApiGatewayResource:
Type: AWS::ApiGateway::Resource
Properties:
ParentId: !GetAtt ApiGatewayRestApi.RootResourceId
PathPart: 'helloworld'
RestApiId: !Ref ApiGatewayRestApi
ApiGatewayGetMethod:
Type: AWS::ApiGateway::Method
Properties:
AuthorizationType: NONE
HttpMethod: GET
Integration:
IntegrationHttpMethod: POST
IntegrationResponses:
-
ResponseParameters:
method.response.header.Access-Control-Allow-Headers: "'Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token'"
method.response.header.Access-Control-Allow-Methods: "'POST,GET,OPTIONS'"
method.response.header.Access-Control-Allow-Origin: "'*'"
StatusCode: '200'
Type: AWS
Uri: !Sub "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations"
MethodResponses:
-
ResponseParameters:
method.response.header.Access-Control-Allow-Headers: true
method.response.header.Access-Control-Allow-Methods: true
method.response.header.Access-Control-Allow-Origin: true
StatusCode: '200'
OperationName: 'helloworld'
ResourceId: !Ref ApiGatewayResource
RestApiId: !Ref ApiGatewayRestApi
ApiGatewayOptionsMethod:
Type: AWS::ApiGateway::Method
Properties:
AuthorizationType: NONE
HttpMethod: OPTIONS
Integration:
IntegrationHttpMethod: POST
Type: AWS_PROXY
Uri: !Sub "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionOptions.Arn}/invocations"
OperationName: 'helloworld'
ResourceId: !Ref ApiGatewayResource
RestApiId: !Ref ApiGatewayRestApi
MyFunction:
Type: AWS::Serverless::Function
Properties:
Handler: index.handler
Runtime: python3.7
InlineCode: |
import json
def handler(event, context):
return {
"statusCode": 200,
"body": json.dumps({ "message" : "Hello from Lambda!"}),
}
MyFunctionPermission:
Type: AWS::Lambda::Permission
DependsOn:
- ApiGatewayRestApi
Properties:
Action: lambda:InvokeFunction
FunctionName: !Ref MyFunction
Principal: apigateway.amazonaws.com
MyFunctionOptions:
Type: AWS::Serverless::Function
DependsOn: ApiGatewayRestApi
Properties:
Handler: index.handler
Runtime: python3.7
InlineCode: |
import json
def handler(event, context):
return {
"statusCode": 200,
"headers": {
"Access-Control-Allow-Origin": '*',
"Access-Control-Allow-Headers": 'Content-Type,Authorization,X-AMZ-Date,X-Api-Key,X-AMZ-Security-Token',
"Access-Control-Allow-Methods": 'GET,POST,OPTIONS'
}
}
MyFunctionOptionsPermission:
Type: AWS::Lambda::Permission
DependsOn:
- ApiGatewayRestApi
Properties:
Action: lambda:InvokeFunction
FunctionName: !Ref MyFunctionOptions
Principal: apigateway.amazonaws.com
Deployment:
Type: AWS::ApiGateway::Deployment
DependsOn: ApiGatewayGetMethod
Properties:
RestApiId: !Ref ApiGatewayRestApi
StageName: prod