[英]Enable POST on AWS API with CloudFront
我按照本教程( https://docs.aws.amazon.com/lambda/latest/dg/build-pipeline.html )构建了一个基本的 ZDB974238714CA8DE634A7CE1D083A1
然后,在用于lambda-pipeline-stack
的 AWS API 网关上,我添加了一个指向 CloudFront 分布的自定义域(例如 api.example.com)。
当我尝试将模板更改为使用POST
请求而不是GET
时,我收到了一个错误:
This distribution is not configured to allow the HTTP request method that was used for this request.
The distribution supports only cachable requests.
但是,当我 go 进入我的 CloudFront 发行版以尝试启用POST
时,无法访问该发行版。 如何为这种类型的 API 启用POST
?
这是我的模板供参考:
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: Shows time
Resources:
TimeFunction:
Type: AWS::Serverless::Function
Properties:
Handler: index.handler
Runtime: nodejs10
CodeUri: ./
Events:
MyTimeApi:
Type: Api
Properties:
Path: /time
Method: POST
您需要在 CloudFront 上允许 POST,因为默认情况下只允许 GET、HEAD
Type: AWS::CloudFront::Distribution
Properties:
DistributionConfig:
...
HttpVersion: http2
DefaultCacheBehavior:
...
AllowedMethods: [DELETE, GET, HEAD, OPTIONS, PATCH, POST, PUT]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.