无法将列表值传递给apigateway更新方法,从而获得参数patchOperations [2] .value的无效类型

时间:2019-02-22 17:08:32

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

我正在尝试使用以下命令使用列表值更新方法authorizationScopes

aws apigateway update-method --rest-api-id xxxxxxxxxx --resource-id yyyyy --http-method ANY \
--patch-operations "op=replace,path=/authorizationType,value=COGNITO_USER_POOLS" "op=replace,path=/authorizerId,value=zzzzz" \
"op=replace,path=/authorizationScopes,value=app-identifier/token,app-identifier/personProfile"

但出现此错误:

Parameter validation failed:
Invalid type for parameter patchOperations[2].value, 
value: [u'app-identifier/token', u'app-identifier/personProfile'],
 type: <type 'list'>, valid types: <type 'basestring'>

也可以使用[]尝试此命令:

aws apigateway update-method --rest-api-id xxxxxxxxxx --resource-id yyyyy --http-method ANY \
--patch-operations "op=replace,path=/authorizationType,value=COGNITO_USER_POOLS" "op=replace,path=/authorizerId,value=zzzzz" \
"op=replace,path=/authorizationScopes,value=[app-identifier/token,app-identifier/personProfile]"

但也会出现与上述相同的错误。

如果我从控制台手动设置并从以下命令获取它: aws apigateway get-method --rest-api-id xxxxxxx --resource-id yyyy --http-method ANY

给我这个输出:

{
    "apiKeyRequired": false,
    "httpMethod": "ANY",
    "methodIntegration": {
        "passthroughBehavior": "WHEN_NO_MATCH",
        "timeoutInMillis": 29000,
        "requestParameters": {},
        "uri": "arn:aws:apigateway:us-east-1:lambda:path/2015-03-31/functions/arn:aws:lambda:us-east-1:111111:function:app:${stageVariables.ENV}/invocations",
        "httpMethod": "POST",
        "requestTemplates": {},
        "cacheNamespace": "xxxx",
        "type": "AWS_PROXY",
        "cacheKeyParameters": []
    },
    "authorizationScopes": [
        "app-identifier/token",
        "app-identifier/personProfile"
    ],
    "authorizationType": "COGNITO_USER_POOLS",
    "authorizerId": "yyyyy"
}

awscli限制或我以错误的方式传递了它

参考:https://docs.aws.amazon.com/cli/latest/reference/apigateway/update-method.html

1 个答案:

答案 0 :(得分:0)

我是JSON语法的粉丝,所以我认为您可以通过简单的方式解决问题。因此,您可以使用以下内容创建一个名为sample-update.json的文件;

    {
        "restApiId": "xxxxxxxxxx",
        "resourceId": "yyyyy",
        "httpMethod": "ANY",
        "patchOperations": [
            {
                "op": "replace",
                "path": "/authorizationType",
                "value": "COGNITO_USER_POOLS",
                "from": "anything_you_like_or_ignore"
            },
            {
                "op": "replace",
                "path": "/authorizerId",
                "value": "zzzzz",
                "from": "anything_you_like2_or_ignore"
            }
        ]
    }

然后执行行;

aws apigateway update-method --cli-input-json file://sample-update.json

我相信这是为了简化您的问题并继续执行其他任务:)。或者,如果您不想使用JSON,则可以运行以下等效项;

aws apigateway update-method \
    --rest-api-id xxxxxxxxxx \
    --resource-id yyyyy \
    --http-method ANY \
    --patch-operations \ 
    "op=replace,path=/authorizationType,value=COGNITO_USER_POOLS,from=anything" \ 
    "op=replace,path=/authorizerId,value=zzzzz,from=anything" 

关于/ authorizationScope,您无法对其执行替换操作。我错过了第一次回答您的问题。 参见api gateway docs