updating CORS policy of HTTP API via AWS CLI

只愿长相守 提交于 2021-02-08 10:44:53

问题


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.

FOR EXAMPLE:

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

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?

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

Thanks in advance!


回答1:


This worked for me

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


来源:https://stackoverflow.com/questions/59725722/updating-cors-policy-of-http-api-via-aws-cli

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!