【问题标题】:updating CORS policy of HTTP API via AWS CLI通过 AWS CLI 更新 HTTP API 的 CORS 策略
【发布时间】:2020-04-30 16:53:10
【问题描述】:

亚马逊发布了通过 API 网关创建 HTTP API 的功能。在他们的网站上,他们描述可以通过 AWS CLI 创建 HTTP API:https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-examples.html#http-api-examples.cli.quick-create

举例:

aws apigatewayv2 create-api --name my-api --protocol-type HTTP --target arn:aws:lambda:us-east-2:123456789012:function:function-name

对于 REST API,我知道可以通过 AWS CLI 更新 CORS 策略。我想知道是否也可以通过 AWS CLI 更改/创建 HTTP API 的 CORS 策略?

我想使用 HTTP API,因为它可以节省很多钱!

提前致谢!

【问题讨论】:

  • 您当然可以通过 CLI 更新 CORS 策略。我已经能够使用aws apigatewayv2 update-api --api-id API-ID --cors-configuration AllowOrigins="*" 成功更新它。我的主要问题是 API 网关似乎没有尊重此政策,因为我所有的飞行前选项请求都收到 500 错误。

标签: amazon-web-services api aws-api-gateway api-gateway


【解决方案1】:

这对我有用

$ aws2 apigatewayv2 update-api --api-id $API_ID --cors-configuration AllowHeaders="*",AllowMethods=GET,POST,AllowOrigins="*",MaxAge=3600

{
    "ApiEndpoint": "https://$API_ID.execute-api.$AWS_REGION.amazonaws.com",
    "ApiId": $API_ID,
    "ApiKeySelectionExpression": "$request.header.x-api-key",
    "CorsConfiguration": {
        "AllowHeaders": [
            "*"
        ],
        "AllowMethods": [
            "GET",
            "POST"
        ],
        "AllowOrigins": [
            "*"
        ],
        "MaxAge": 3600
    },
    "CreatedDate": "2020-01-28T17:41:35+00:00",
    "Name": "http-api",
    "ProtocolType": "HTTP",
    "RouteSelectionExpression": "$request.method $request.path",
    "Tags": {}
}

【讨论】:

    猜你喜欢
    • 2021-02-13
    • 2023-04-07
    • 2021-06-22
    • 1970-01-01
    • 2020-08-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-11
    相关资源
    最近更新 更多