通过AWS CLI更新HTTP API的CORS策略

问题描述 投票:0回答:1

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

例如:

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,因为它可以节省很多钱!

提前感谢!

amazon-web-services api aws-api-gateway api-gateway
1个回答
0
投票

这对我有用

$ 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": {}
}
© www.soinside.com 2019 - 2024. All rights reserved.