通过 AWS CLI 更新 HTTP API 的 CORS 策略 [英] updating CORS policy of HTTP API via AWS CLI

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

问题描述

亚马逊发布了通过 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 策略的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆