本文介绍了通过AWS CLI更新HTTP API的CORS策略的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Amazon已发布了通过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 .

Amazon has released the ability to create HTTP API's via API gateway. On their website they describe that it is possible to create an HTTP API via AWS CLI: 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策略?

For REST API's I know it is possible to update the CORS policy via AWS CLI. I was wondering if it is also possible to change/create the CORS policy for HTTP API's via AWS CLI?

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

I want to use HTTP API's because it saves a lot of money!

提前谢谢!

推荐答案

这对我有用

$ 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": {}
}

这篇关于通过AWS CLI更新HTTP API的CORS策略的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-29 13:43