0
votes

I am trying to update the method authorizationScopes with the list value using the following command:

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"

but got this error:

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'>

Also try this command with []:

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]"

but also getting the same error as above.

If I set it manually from the console and get it from this command: aws apigateway get-method --rest-api-id xxxxxxx --resource-id yyyy --http-method ANY

give me this output:

{
    "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 limitation or I am passing it in wrong way

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

1

1 Answers

0
votes

I am a fan of JSON syntax so I think you can resolve your issues in a simple manner. So, you can create a file called sample-update.json with the following content;

    {
        "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"
            }
        ]
    }

Then execute line;

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

I believe this is the to simplify your problem and to get on with another task :). Alternatively if you prefer not to use JSON you can run the following equivalent;

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" 

With regards to /authorizationScope, you can’t perform replace operations on them. I missed it first time answering your question. See the api gateway docs