Anupam
Anupam

Reputation: 274

Pass JSON string as an input to aws command

I am trying to invoke API from the data pipeline where i am getting below error . This is what i am trying .

aws apigateway test-invoke-method --rest-api-id  int836id123 --resource-id  1ukckkkwq1 --http-method POST --body "{\"QUEUEURL\": \"\",
\"BUCKETREGION\": \"us-east-1\",
\"FLAGFILE\": \"\",
\"FTPUSERID\": \"abcd-test-parameter\",
\"FTPPATH\": \"/abcd/Incr1\", 
\"FTPPASSWORD\": \"abcd-test-parameter\", 
\"PARAMETERSTOREREGION\":\"us-east-1\",
\"ISFTP2S3\": \"false\", 
\"FTPSERVER\": \"11.42.123.111\", 
\"BUCKETNAME\": \"path/Lineite/MAIN\", 
\"QUEUEREGION\": \"\",
\"LOCALPATH\": \"path\"}"

I have verified there is no extra space of enter in the command . Also i tried to to run without \ but same error .

Here is the error i get

2018 : Lambda invocation failed with status: 400\nMon Apr 02 06:45:20 UTC 2018 : Execution failed: Could not parse request body into json: Unexpected character ('Q' (code 81)): was expecting double-quote to start field name\n at [Source: [B@72073757; line: 1, column: 3]\nMon Apr 02 06:45:20 UTC 2018 : Method completed with status: 400\n", "latency": 41, "headers": {} }

When i tried to run from AWS cli it worked but not working from data pipeline.

Upvotes: 1

Views: 1944

Answers (1)

Inian
Inian

Reputation: 85780

You could use a here-document to define a properly formatted JSON so that you don't have to worry about escaping the quotes. Define a function as

jsonDump()
{
  cat <<EOF
{
   "QUEUEURL":"",
   "BUCKETREGION":"us-east-1",
   "FLAGFILE":"",
   "FTPUSERID":"abcd-test-parameter",
   "FTPPATH":"/abcd/Incr1",
   "FTPPASSWORD":"abcd-test-parameter",
   "PARAMETERSTOREREGION":"us-east-1",
   "ISFTP2S3":"false",
   "FTPSERVER":"11.42.123.111",
   "BUCKETNAME":"path/Lineite/MAIN",
   "QUEUEREGION":"",
   "LOCALPATH":"path"
}
EOF
}

and call now the function as below

aws apigateway test-invoke-method --rest-api-id  int836id123 --resource-id  1ukckkkwq1 --http-method POST --body "$(jsonDump)"

Upvotes: 2

Related Questions