422 [Error] Cannot Process In CloudWatch Logs - amazon-web-services

I am trying to make a Lambda hit a HTTP endpoint and deliver some simple JSON - Lambda works completely fine and the URL is ok however when the JSON is trying to be delivered I see a 422 error [Error Cannot Process] when I check CloudWatch Logs. Any idea why this could be?

Related

Data Fusion alert HTTP Callback is failing with error code 411

In data fusion Alert I want to invoke an API using(HTTP callback) running in Cloud Run after successful pipeline execution.
I am getting response code 411
It is a POST request call. I am not sending any request body so I have updated Content-Length:0 in request header. still getting the response code 411.
I want to know the steps to be followed to make a successful http post call

AWS X Ray logging HTTP 404 response as 200 instead

I'm setting up AWS X-Ray integration for my lambda service in Python, but I've encountered a strange issue.
I make an external HTTP call with the built in Python requests library, and my logs show that the status code is 404. Here's a snippet:
...
response = get_request(url, headers, params)
print(f"stat = {response.status_code}") # logs as 404
...
When I check AWS X-Ray, I can see the error rate is 100%:
But when I click on traces, the response code then becomes 200.
Why is there a discrepancy between the response codes?
From the documentation here, I should only need to add patch_all() method in order to trace my requests, which I've already done, so why is it I am still seeing 200 response.

Telegram Bot - URL of webhook dissapears

I have a telegram bot which uses a webhook (API Gateway - AWS). The code of the bot is stored in a lambda and works correctly.
If I use the command getWebHookInfo this is what I get:
{"ok":true,"result":{"url":"https://mywebhook-api.eu-west-3.amazonaws.com","has_custom_certificate":false,"pending_update_count":0,"max_connections":40,"ip_address":"10.100.100.100","allowed_updates":["message","inline_query","callback_query"]}}
Then, whenever I send a message the url of the webhook disappears and I don't get any last error message. This is what I get if I use again the getWebHookInfo command:
{"ok":true,"result":{"url":"","has_custom_certificate":false,"pending_update_count":1,"allowed_updates":["message","inline_query","callback_query"]}}
Also, if I do a post request in Postman emulating a Telegram message the code works correctly and I will also receive an answer for the pending message !
It doesn't seems an error of the webhook, and for sure it's not an error of the code of the bot.
What's funny is that for a moment it worked, but it didn't last more than a few minutes... Any help will be appreciated, I'm completely out of ideas!

Cloud scheduler - HTTP - list in payload/body

I have a scheduled job in GCP that POSTs to the endpoint of a REST service. The payload expected by the url is
{"foo": ["bar"]}
I specified "{\"foo\": \[\"bar\"\]}" in the Body field in the web console :
AND specified application/json in the Content-Type header.
But I get 400 error from the endpoint (Bad request). The endpoint is working perfectly fine when requested from the swagger, so I think the problem comes from how I specify the payload in the cron job.
How should I write the payload in Cloud Scheduler web interface ?
Simply use you raw JSON {"foo": ["bar"]}. The escape characters are for gcloud CLI.

AWS API Gateway Multiple 2XX Responses

We have an API endpoint we are building through API Gateway that can have two possible successful responses: 200 OK if all of the requested data is returned, and a 206 Partial Content if the data is paginated and additional requests are required to fetch all the data.
I found at https://aws.amazon.com/blogs/compute/amazon-api-gateway-mapping-improvements/ that Amazon now allows multiple 2XX responses to be defined, but I cannot attribute both responses to a success in the Integration Response configuration. Right now we have 200 set as the default, but it appears as if we have to specify a Lambda Error Regex for the 206 mapping.
Does this basically mean that I have to fail the 206 with an error message and then use the regex to determine if that message is being sent, and then basically just treat it like a success? Or how can I properly return either a 200 or a 206 as a successful response?
The endpoint that AWS will hit on our server will properly return a 200 or a 206, but when AWS responds to the client it is currently only sending a 200.
Does this basically mean that I have to fail the 206 with an error
message and then use the regex to determine if that message is being
sent, and then basically just treat it like a success?
Yes, that is correct. Quirky, wrong, but it works.
The API gateway doesnt provide sending multiple success 2xx response. Below are some options
Make your lambda or backend application fail and return some json response. Create a regex in integration response and map the response to a particular error code. The matching of regex is done on errorMessage field which can be only get once you throw error from lambda.
Utilise reponse overriding. You can create a default mapping which matches all or some responses and then in the mapping template you can override the status code to whatever you want to send back.
Eg:-
Lambda returns
def handler(event, context):
x = {
"message": "partial"
}
return x
API gateway integration response
Lambda error regex: -
Method response status: 200
Default mapping: Yes
Mapping template:
#set($inputRoot = $input.path('$'))
$input.json("$")
#if($inputRoot.toString().contains("partial"))
#set($context.responseOverride.status = 206)
#end