AWS CLI Invalid JSON error - pending property name enclosed in double quotes

I am writing an AWS dependent application in javascript and I am using the AWS CLI to automate the build process for my AWS resources. I am trying to create an API gateway resource with CORS enabled. When calling the put-integration-response

CLI api gateway method , when I add an argument --response-parameters

, I got the following error:

>> Error parsing parameter '--response-parameters': Invalid JSON: Expecting property name enclosed in double quotes: line 1 column 2 (char 1)
>> JSON received: {method.response.header.Access-Control-Allow-Origin:'*'}

      

Here is the -response-parameters argument causing problems:

--response-parameters {"method.response.header.Access-Control-Allow-Origin":"\'*\'"}

If that helps, this argument is fed through the grunt-exec plugin for Grunt. What exactly is causing this problem? I tried adding more double quotes, but they don't seem to show up in the "Received JSON".

+3


source to share


2 answers


You can encode a static value to "'"' '' * '"'" '".

Example:



aws apigateway put-integration-response --rest-api-id xxxxx --resource-id xxxxxx --http-method GET --status-code 200 --response-parameters '{"method.response.header.Access-Control-Allow-Origin": "'"'"'*'"'"'"}' 

      

I suggest using the JavaScript SDK to call the API Gateway to manage your resources. More information can be found in the SDK documentation .

+1


source


I had the same problem when I was reading the AWS Lambda Functions tutorial where I couldn't get the response-models argument to accept JSON (on Windows 10) no matter what I tried. I finally figured it out: I created a file called response-models.json with the content in the first line of the file as {"application / json": "Empty"} and I saved it to the current directory. Then I used the file: //response-models.json as the value for the response-models argument IMPORTANT: The file must be saved in a BOM format so that only ASCII characters come out of it, and no other gibberish. (I used Sublime Text, which allows you to save in UTF-8 without BOM, as well as many other formats.) And voila! I got the answer:



{
    "statusCode": "200",
    "responseModels": {
        "application/json": "Empty"
    }
}

      

0


source







All Articles