I am having difficulty getting http method used in a call to aws lambda via api gateway. I created a REST api in api gateway, which makes a call to a lambda function. In the lambda function I want to have two functions, one for POST requests and one for GET requests. I am unable to get the method from event. In other threads answers are usually for javascript or java only.
I run the following curl command from my terminal:
curl "https://myurl/endpoint"
I also try to send a GET request via advanced rest client.
Here's what I'm trying to do:
def lambda_handler(event, context):
method = event['httpMethod']
if method == "GET":
return get_function()
if method == "POST":
return post_function()
Running the above code results in a keyError.
I have tried this as well:
method = event['requestContext']['http']['method']
I tried printing out the event itself like this method = event. All I get from this is {}, both in the response and in cloudwatch.
How can I read the http method in a request
Below code should work in Python 3.7 runtime. Of course, you can improve the code but, it will give you what you are looking for.
reqcontxt = event.get("requestContext")
httpprtcl = reqcontxt.get("http")
methodname = httpprtcl.get("method")
print('### http method name ###' + str(methodname))
Thanks.
Hiren
With help from #Marcin I understood that I had to tick 'Use Lambda Proxy Integration' option in integration request. Without it my request did not pass any method or headers data to lambda.
It was either this or I would need to add some more code in my application to define the method but as I was using curl for testing I didn't add -X GET nor anything like that to the request.
Related
I am processing data from Event Hub. Whenever events are available in event hub series of azure functions are called sequentially to processes the data.
function A is using event data as input --> function B is using output of function A as an input and likewise 2 more functions are there.
Response body is missing in only one function (same, ex.: function B in picture) in some iterations.
Sometimes response body for one of the azure function is missing however response code is 200. I have logged the response body in azure function before returning the response and it(response body) is present in logs.
What can be the reason of not getting the response body.
In the attached image Function B is having this issue.
Update: After adding concurrency control to 1(So that it runs sequentially) issue is resolved however again after removing concurrency control issue is coming. What can be the issue ?
One of the workaround you can follow to resolve the above issue,
Make sure that all of the azure function has been created in the same region that might be the reason for not getting the request body for one function and getting for others.
Would suggest you to create Azure logic app and functions in the same region.
Another workaround is to provide the content type in your event hub to application/json if still having the same the try to set text/plain.
For more information please refer this MICROSOFT DOCUMENTATION| Receive and respond to inbound HTTPS requests in Azure Logic Apps
For the similar issue please refer this MS Q&A| Http Webhook Outputs does not have body content, only headers .
Locust is having option to use HTTPUser and FastHTTPUser
HTTPUSer internally using python requests which accepts cookies as an argument with json content
e.g. self.client.get(url, header=myheader, cookies=mycookies) here I can configure mycookies as json. Same is not working if I change the code to FastHTTPUser instead of HTTPUser. Need details how to configure hardcoded cookies as key value before making the request in FastHTTPUser approach.
I don't see why you have received downvotes for your question. I found it valid and I think you should create an issue in the locust github page:
https://github.com/locustio/locust/issues/
I think you could solve it like this:
from requests.cookies import cookiejar_from_dict
#task
def task_cookie(self):
cookiejar_from_dict(mycookies, self.client.cookiejar)
self.client.get(url, header=myheader)
I will try to make a PR to make this automatic
I was set for task to write small autotest API. (even though I am a manual junior tester).
The function is:
def test_post_tokens
In this post request I need to get authrization-header from response.
Next I need to pick up this token and insert it into other requests. (or set it to pytest environment). For example:
def test_get_account_info
It is possible to manually set a token for each request, but it takes a lot of time and the hunt to do everything correctly.
In postman, I solved this problem by getting a token in the first request and setting it in an environment
pm.environment.set ("token", postman.getResponseHeader ("Auth-Token"));
I am trying to use nipple to post to an url within my nodejs application, which itself is running on hapi.js
The documentation essentially doesn't seem to spell it out.
(https://www.npmjs.com/package/nipple)
I tried passing it as payload inside options but that, while not returning an error, returns a 400. Can someone provide a correct example doing a post using nipple?
Essentially, I have two variables that I need to send - let's call the var1 and var2.
Thanks!
That link says that the project has been renamed to wreck. On wreck's github, several of the tests are for a post requests, including this one:
https://github.com/hapijs/wreck/blob/master/test/index.js#L68
If you are still scratching your head, you could also try using curl or postman to sanity check your URL, regardless of any nipple/wreck errors. If that also gives you a 400, nipple/wreck may not be the culprit.
I'm trying to simulate an asynchronous response on a webservice mock. The goal is to response a synchronous acknowledge message and then a delayed message back to the replyTo address. The approach I have selected uses mock service that will handle the acknowledge and then run a test case that will handle the processed message back to the replyTo. I'm using OnRequest Script to generate the acknowledged message and AfterRequest Script to run the test case that will emulate the delay and the response back to the replyTo.
So the question is which script object I can use to have access to the requestContent. I have seen examples using:
def holder = new com.eviware.soapui.support.XmlHolder( mockRequest.requestContent )
but the mockRequest instance is not available on AfterRequest, Which object I can use instead to have a holder with the request content?
I did find that
def holder = new com.eviware.soapui.support.XmlHolder( mockResult.getMockRequest().requestContent )
do the trick, but now I find that running a test script in AfterRequest delays the synchronous response back, Why could this be happening? Isn't AfterRequest's script executed after the mock service response back? Do i have to explicitly execute something at Dispatch or at OnRequest in order to summit back the response before AfterRequest code being executed?
I know this is really old question, but I just faced the same issue myself. I have no idea why it works as it works, but you can avoid the problem by accessing the request content in OnRequest, then store needed information to context and use the context in AfterRequest to get the information you need.