gpt4 book ai didi

amazon-web-services - 使用 CloudFront 在 AWS API 上启用 POST

转载 作者:行者123 更新时间:2023-12-03 07:27:26 27 4
gpt4 key购买 nike

我已按照本教程 ( https://docs.aws.amazon.com/lambda/latest/dg/build-pipeline.html ) 构建了一个基本 API。

然后,在 lambda-pipeline-stack 的 AWS API Gateway 上,我添加了一个指向 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.

但是,当我进入我的 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]

enter image description here

关于amazon-web-services - 使用 CloudFront 在 AWS API 上启用 POST,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62618032/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com