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.
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)"
Related
Any idea what's wrong with the following curl statement? I am using this to upload files to a neptune database from an EC2 instance.
curl -X POST \
-H 'Content-Type: application/json' \
https://*my neptune endpoint*:8182/loader -d '
{
"source" : "s3://<file path>/<file name>.nq",
"format" : "nquads",
"iamRoleArn" : "arn:aws:iam::##########:role/NeptuneLoadFromS3",
"region" : "us-east-1",
"failOnError" : "FALSE",
"parallelism" : "MEDIUM",
"updateSingleCardinalityProperties" : "FALSE",
"queueRequest" : "TRUE"
}'
I have used this command template multiple times before without issue. The only things that i have changed here are the neptune endpoint and the file location on s3. When i run it now, i get the following error:
{"detailedMessage":"Json parse error: Unexpected character ('' (code 8203 / 0x200b)): was expecting double-quote to
start field name\n at [Source: (String)\"{\n \"source\" : \"s3://<file path>/<file name>.nq\",\n \"format\"
: \"nquads\",\n \"iamRoleArn\" : \"arn:aws:iam::#########:role/NeptuneLoadFromS3\",\n \"region\"
: \"us-east-1\",\n \"failOnError\" : \"FALSE\",\n \"parallelism\" : \"MEDIUM\",\n
\"updateSingleCardinalityProperties\" : \"FALSE\",\n \"queueRequest\" : \"TRUE\"\n }\"; line: 1, column: 3]",
"requestId":"4ebb82c9-107d-8578-cf84-8056817e504e","code":"BadRequestException"}
Anything that i change in the statement does not seem to have an effect on the outcome. Is there something really obvious that i am missing here?
Hi community,
I have been struggling with an issue in ansible issue for days now.
Everything is executed wihtin a Jenkins pipeline.
The ansible command looks like:
sh """
ansible-playbook ${env.WORKSPACE}/cost-optimization/ansible/manage_dynamo_db.yml \
--extra-vars '{"projectNameDeployConfig":${projectNameDeployConfig},"numberOfReplicas":${numberOfReplicas},"dynamodbtask":${dynamodbtask}}'
"""
And the playbooks is:
playbook.yml
---
- hosts: localhost
vars:
numberOfReplicas: "{{numberOfReplicas}}"
dynamodbtask: "{{dynamodbtask}}"
namespace: "{{projectNameDeployConfig}}"
status: "{{status}}"
- tasks:
- name: "Get replica number for the pods"
command: aws dynamodb put-item --table-name pods_replicas
register: getResult
when: dynamodbtask == "get"
- name: "Update replica number for specified pods"
command: |
aws dynamodb put-item
--table-name pods_replicas
--item '{"ProjectNameDeployConfig":{"S":{{namespace}}},"NumberReplicas":{"N":{{numberOfReplicas}}}}'
register: updatePayload
when: dynamodbtask == "put" and getResult is skipped
However, there is always the following error:
fatal: [localhost]: FAILED! => {"changed": true, "cmd": ["aws", "dynamodb", "put-item", "--table-name",
"pods_replicas", "--item", "{\"ProjectNameDeployConfig\":{\"S\":LERN-PolicyCenterV10},\"NumberReplicas\":
{\"N\":0}}"], "delta": "0:00:01.702107", "end": "2020-02-09 16:58:26.055579",
"msg": "non-zero return code", "rc": 255, "start": "2020-02-09 16:58:24.353472", "stderr": "\nError parsing parameter '--item': Invalid JSON: No JSON object could be decoded\nJSON received: {\"ProjectNameDeployConfig\":{\"S\":LERN-PolicyCenterV10},\"NumberReplicas\":{\"N\":0}}", "stderr_lines": ["", "Error parsing parameter '--item': Invalid JSON: No JSON object could be decoded", "JSON received: {\"ProjectNameDeployConfig\":{\"S\":LERN-PolicyCenterV10},\"NumberReplicas\":{\"N\":0}}"], "stdout": "", "stdout_lines": []}
There are two answers to your question: the simple one and the correct one
The simple one is that had you actually fed the JSON into jq, or python -m json.tool, you would have observed that namespace is unquoted:
"{\"ProjectNameDeployConfig\":{\"S\": LERN-PolicyCenterV10 },\"NumberReplicas\": {\"N\":0}}"
where I added a huge amount of space, but didn't otherwise alter the quotes
The correct answer is that you should never use jinja2 to try and assemble structured text when there are filters that do so for you.
What you actually want is to use the to_json filter:
- name: "Update replica number for specified pods"
command: |
aws dynamodb put-item
--table-name pods_replicas
--item {{ dynamodb_item | to_json | quote }}
vars:
dynamodb_item:
"ProjectNameDeployConfig":
"S": '{{ projectNameDeployConfig }}'
"NumberReplicas":
"N": 0
register: updatePayload
when: dynamodbtask == "put" and getResult is skipped
although you'll notice that I changed your variable name because namespace is the name of a type in jinja2, so you can either call it ns or I just used the interpolation value from your vars: block at the top of the playbook, as it doesn't appear that it changed from then
I am sending the following valid JSON as a message via MQTT to a device :
{
"devices": [
{
"known": true,
"local": false,
"eep": "MSC_V3_PRESSAC_20",
"id": "01:96:23:83",
"O_nominalVoltage": 120
}
],
"uuid": "821ca781-dd98-4531-8391-19d4e4da2c96"
}
but I receive the following error back :
"Handling command: org.json.JSONException: Expected a ',' or '}' at character 62 of {devices:[{known:true,local:false,eep:MSC_V3_PRESSAC_20,id:01:96:23:83,O_nominalVoltage:120}],uuid:821ca781-dd98-4531-8391-19d4e4da2c96}"
}
Can anyone see anything wrong with this? I don't understand why there is a problem with character 62.
For more information, I am sending the message via the mosquitto_pub command when publishing to an MQTT topic on a remote device.
My device is running Java code which uses the Java Paho libraries. I am using the AWS IoT MQTT broker.
I have a C# application that return a Json status when I call "http://host:port/app-status".
The response looks like:
{
"prtg":
{
"result": [
{
"channel": "DDS - ZDM - Konsistenzprüfung",
"value": "3",
"valuelookup": "prtg.RCLookup.DDS_ZDM_Check.BitField"
},
{
"channel": "ZDM DB Verbindungsversuche",
"value": "0",
"valuelookup": "prtg.RCLookup.Default.DB.Connect.Retry"
}
]
}
}
Then i have on zabbix server an item which type is http agent.
The request works fine. But I get this error:
Preprocessing failed for: HTTP/1.1 200 Ok..Content-Length: 361..Content-Type: application/json..Server: Grapevine/4.1.1.0 M...
1. Failed: cannot extract value from json by path ".prtg.result[0].value": cannot parse as a valid JSON object: invalid object format, expected opening character '{' or '[' at: 'HTTP/1.1 200 Ok
Content-Length: 361
Content-Type: application/json
Server: Grapevine/4.1.1.0 Microsoft-HTTPAPI/2.0
Date: Fri, 12 Apr 2019 14:19:12
In the preprocessing tab I have set a processing step with JsonPath.
The JsonPath is: .prtg.result[0].value
What is wrong?
Can help me everybody?
from error message it seems that you are trying to parse response from server inclusive headers which is wrong - you need to parse as JSON only data which is sent back (exclusive headers)
I'm using tastypie with django. I have one line of code:
data = self.deserialize(request, request.body, format=request.META.get('CONTENT_TYPE', 'application/json'))
I use this code from the command line to send a post request to my webserver:
curl -X post -d "{ 'username' : 'user', 'password' : 'password' }" http://127.0.0.1:8000/api/employee/login/ --header "Content-Type:application/json"
When I run this, it results in a json response of
{"error": ""}
Looking at my server logs I see:
[15/Feb/2014 20:39:49] "post /api/user/login/ HTTP/1.1" 400 13
A log message logged immediately before the deserialize line will be logged successfully, but a log message logged immediately after the deserialize line will not be logged, so I am pretty sure the deserialize is wrong. Does anyone know what could be wrong or if I should consider something else as the problem?
Your JSON is not valid. Please check it here. The 400 (bad request) status should give you clue about that. It should be: {"username": "user", "password": "password"}. Here you have some solutions how to escape " char in CURL command. Tastypie unfortunately raises exception without message here but we can easily fix that for future to save time for other people which will use your API.
from tastypie.exceptions import BadRequest
from tastypie.serializers import Serializer
class VerboseSerializer(Serializer):
"""
Gives message when loading JSON fails.
"""
# Tastypie>=0.9.6,<=0.11.0
def from_json(self, content):
"""
Override method of `Serializer.from_json`. Adds exception message when loading JSON fails.
"""
try:
return json.loads(content)
except ValueError as e:
raise BadRequest(u"Incorrect JSON format: Reason: \"{}\" (See www.json.org for more info.)".format(e.message))
class MyResource(BaseModelResource):
class Meta:
serializer = VerboseSerializer(formats=['json'])