-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathserverless-cf-template.yml
More file actions
108 lines (102 loc) · 3.83 KB
/
serverless-cf-template.yml
File metadata and controls
108 lines (102 loc) · 3.83 KB
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
# Copyright [2024] [Phil Chen]
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# Things to note or change:
# Change your S3Bucket to the name of your bucket where you put the lambda.zip
# Change the role name in two places from "role/serverless" to the role name you created
# To test use the URL provided in the Outputs under TestURL in a browser
AWSTemplateFormatVersion: "2010-09-09"
Description: Serverless Application that outputs JSON.
Resources:
endpointApiPermissionProd:
Type: 'AWS::Lambda::Permission'
Properties:
Action: 'lambda:invokeFunction'
Principal: apigateway.amazonaws.com
FunctionName: !Ref endpoint
SourceArn: !Sub
- >-
arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/endpoint_python
- __Stage__: Prod
__ApiId__: !Ref ServerlessRestApi
ServerlessRestApiProdStage:
Type: 'AWS::ApiGateway::Stage'
Properties:
DeploymentId: !Ref ServerlessRestApiDeployment00
RestApiId: !Ref ServerlessRestApi
StageName: Prod
ServerlessRestApiDeployment00:
Type: 'AWS::ApiGateway::Deployment'
Properties:
RestApiId: !Ref ServerlessRestApi
Description: 'RestApi deployment id: 00'
StageName: Stage
endpoint:
Type: 'AWS::Lambda::Function'
Properties:
Code:
S3Bucket: 'S3_BUCKET_YOUR_APP_ZIP_IS_LOCATED'
S3Key: 'lambda.zip'
Description: 'aws-serverless-cfn-template'
MemorySize: '128'
Handler: lambda.endpoint
Role: !Sub 'arn:aws:iam::${AWS::AccountId}:role/serverless'
Timeout: '30'
Runtime: 'python3.11'
ServerlessRestApi:
Type: 'AWS::ApiGateway::RestApi'
Properties:
Body:
info:
version: '1.0'
title: !Ref 'AWS::StackName'
paths:
/endpoint_python:
get:
consumes:
- application/json
produces:
- application/json
responses:
'200':
description: 200 response
headers:
Content-Type:
type: string
x-amazon-apigateway-integration:
httpMethod: POST
credentials: !Sub 'arn:aws:iam::${AWS::AccountId}:role/serverless'
type: aws
uri: !Sub >-
arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${endpoint.Arn}/invocations
responses: {
"default": {
"statusCode": "200",
"responseTemplates": {
application/json: ""
}
}
}
passthroughBehavior: "when_no_templates"
swagger: '2.0'
endpointApiPermissionTest:
Type: 'AWS::Lambda::Permission'
Properties:
Action: 'lambda:invokeFunction'
Principal: apigateway.amazonaws.com
FunctionName: !Ref endpoint
SourceArn: !Sub
- >-
arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/endpoint_python
- __Stage__: '*'
__ApiId__: !Ref ServerlessRestApi
Outputs:
TestURL:
Description: Test your serverless app with this url in a browser.
Value: !Join [ "", [ "https://", !Ref "ServerlessRestApi", ".execute-api.", !Sub "${AWS::Region}", ".amazonaws.com/Prod/endpoint_python"]]