不需要。可以在API Gateway创建时指定一个域名,并使用通配符*为该域名配置路径,并在CloudFront中将此域名的别名设置为根目录路径。以下为示例代码:
1.在API Gateway中添加“{proxy+}”路径为通配符*的模糊匹配通配符,将其与API的集成或Lambda函数的使用者进行配置:
resources:
- path: /{proxy+}
RestApiId:
Type: AWS::ApiGateway::Resource
- RestApiId:
ResourceId: ResourceId
HttpMethod: GET # Method type GET / POST etc.
Integration:
IntegrationHttpMethod: POST
IntegrationResponses:
- StatusCode: 200
ResponseTemplates:
application/json: |
#set($inputRoot = $input.path('$'))
"output": "hello from lambda!",
Type: AWS_PROXY
Uri: !Sub
arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${LambdaArn}/invocations
- RestApiId:
ResourceId: ResourceId
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'"
method.response.header.Access-Control-Allow-Origin: "'*'"
ResponseTemplates:
application/json:
Type: Mock
- RestApiId:
ResourceId:
StageName: Dev
Method: GET