I am trying to make a local Java program run in AWS Lambda and make it such that it can be called with a HTTP request. All I need is just to be able to duplicate the functionality of running java locally from the command line through HTTP in AWS so other people in the company can run the code by just sending a HTTP request in Postman(for now, next step is a web form that just makes the request) instead of downloading the jar and launching the Java command line.
I went through the hello world tutorial in the Amazon website and was able to adapt my code, and run it successfully using the test function in the AWS Lambda control panel. I am also able to see the logs in cloudwatch that it ran and also observe the results. So it all works from the Lambda control panel test function.
So instead of command line arguments, I'm giving the arguments in JSON format as follows:
{
"environment": "dev",
"username": "Test",
"password": "Test22",
"storeId": "TESTMA0001",
"data": "a,b,c,d"
}
And this works quite well when invoking the lambda from the test function.
However I want to be able to enter this in the body of a HTTP request and have my lambda run so I added an api gateway through the gui in the aws lambda panel, chose HTTP API kind and default options.
Then I send a HTTP GET request to the api endpoint with the body being the same input I used in the testing panel, but whenever I run it, I get internal server error. I turned on access logs for the gateway api, and I get the following, my lambda is not being launched by the api since there is no lambda log being written when I use the API, it gets written when I launch it from the AWS lambda web panel.
{
"requestId": "KByVuheeoAMEPLA=",
"ip": "",
"requestTime": "27/Mar/2020:02:25:40 +0000",
"httpMethod": "GET",
"routeKey": "$default",
"status": "500",
"protocol": "HTTP/1.1",
"responseLength": "35"
}
My handleRequest function takes a string, string map as input and returns a string as output:
public class StoreCategoryImporter implements RequestHandler<Map<String,String>, String> {
#Override
public String handleRequest(Map<String,String> event, Context context)
I don't even use the context object but it was there in the tutorial so it remained.
I googled for hours and I have not been able to find a solution, any help would be appreciated. I find most AWS tutorials to skip over some crucial details or they don't have it for POJO developers and use js which I don't understand.
Thank you in advance.
To simulate API Gateway event for tests in your lambda you, the lambda console has some pre-set values. In your lambda you go to Configure test event and choose the event you want to simulate, e.g.:
Alternatively, you can print out real event in your lambda to CloudWatch logs, and use that for tests.
I have solved this problem by more googling and finding a closer solution. Forget about the AWS tutorial, you need to override the handleRequest(APIGatewayProxyRequestEvent, Context) method, not the one that just takes in a Map(String,String) event as described in the hello world tutorial if you want to be able to trigger your lambda through a HTTP request.
Also, the "configure test event" in the AWS GUI is useless in this case. It cannot parse JSON that isn't a primitive. Probably the CLI would work better.
Related
I am trying to test my Springboot App using jMeter. I want to send multiple request with some JSON payload to receive the response concurrently (via threading).
While doing this, in order to check validity of response, I want to keep a log where it can show the request-response pair (side-by-side or even in separate files, they should just be identifiable which request gave which response).
This is to test if one request is not tampering other request's response (data validation).
I have already tried Simple Writer tool where we can log request and response (I think jmeter have used some different terminology in menu) on configure menu. But it doesn't seem to be working when I run the results.
So my main concern is how can we store the JSON request data and response data pair somewhere after test iteration have completed. I have never used jmeter before so a little bit of detailing will help.
Thanks!
You can use Flexible File Writer which gives you the full freedom with regards to what and where to store.
For example if you configure the Flexible File Writer as:
I'll provide textual form of the sample template:
---------REQUEST----------------------\r\n|requestData|\r\n---------RESPONSE--------------------\r\n|responseData|\r\n-------------------------------------
You will get results file looking like:
---------REQUEST----------------------
POST https://jsonplaceholder.typicode.com/posts
POST data:
{
"title": "foo",
"body": "bar",
"userId": 1
}
[no cookies]
---------RESPONSE--------------------
{
"id": 101
}
-------------------------------------
You can install Flexible File Writer plugin using JMeter Plugins Manager
Check out the JMeter docs on configuring the Results Tree. It will show you the results and you can configure how much to keep and where.
https://jmeter.apache.org/usermanual/component_reference.html#View_Results_Tree
In particular you might benefit from this:
https://jmeter.apache.org/usermanual/component_reference.html#Save_Responses_to_a_file
I have a simple lambda in AWS that takes plain text (non-JSON) input and gives plain text (non-JSON) output, and it works when I test it in the Lambda Management Console. I'd like to call it by POSTing the input via HTTP, so I added API Gateway as a trigger, but it says "An error occurred during JSON parsing" - fair enough, because I didn't output JSON.
I found a number of similar questions here, but they focused on fixing the JSON. My question is whether it's possible to avoid it altogether. Can I configure API Gateway to just pass through the request and response bodies, or is there another way to get an HTTP request to my lambda that would allow that?
I have a string variable in my Java application that is being built by Jenkins. After Jenkins build is done, it sends a notification to our internal messenger. I need to include this Java string into the notification message. This string is not constant. It is dynamic and depends on the response that is being returned by a request that is handled in Java app.
Currently, the notification message consists of a build's metadata - status, build number, job name. These values are taken by Jenkins by getting the values of respective environment variables.
How can I get in Jenkins the value of the Java string variable?
According to our previuous comments, I guess you need to do something like this:
Create an API in your Java App: this API needs to publish an operation with the parsed response (the one which gets the 3rd service response).
Call this API from Jenkins, with, for example, a curl (you can do it with Groovy if you want to), something like this (assuming you return a json response):
//The next http://yourdomain... URL is the one your Java app will expose with your parsed response
def response = sh script: "curl 'http://yourdomain/api/v1/yourResource'", returnStdout: true
def jsonProcessed = readJSON text: response
//Do some post-process in Jenkins if you need to using readJSON. I just put a dummy raise error example (Check the readJSON link below)
if (jsonProcessed.key == 'whatever') {
error "Raise some error"
}
// Or directly the code to send the response to the messenger
// TODO Your sending code HERE
Send the response from Jenkins to your messenger.
Help with readJSON
Hope it helps.
I am new to jmeter (I am using version 3.3) and I created a test plan with the goal of sending an email on Assertion failure.
in this email I want to add some information about the name of the request and its reason
so I have added and if controller with this condition:
${JMeterThread.last_sample_ok}
a beanshell preprocess with this script:
and an SMTP Sampler with this body:
and a response assertion:
I want to get an email anytime it hits the condition of response code=500 and the info described above.
I got to receive the email on that condition but the body message is literally this:
${body}
this is the assertion result:
what am I doing wrong?
How to get what I need?
Thanks
Your prev variable is not defined in the Beanshell PreProcessor (it exists only for PostProcessor and Listener, I would suggest using ctx.getPreviousResult() instead where ctx stands for JMeterContextService instance.
You also need to enable your HTTP Request GET - posts as this will be this "previous result" you're interested in.
Be aware that starting from JMeter 3.1 it is recommended to use Groovy for any form of scripting so consider migrating to JSR223 PreProcessor and Groovy language on next available opportunity. You should be even able to re-use the same code as I don't see any Beanshell-specific features in it. See Apache Groovy - Why and How You Should Use It article for more information on Groovy scripting in JMeter.
The script is sending an email if the last sampler is ok, therefore the assertion is ok too, so the body variable won't hold any value.
Just adjust your if statement to !${JMeterThread.last_sample_ok}, and then move up your HTTP sampler HTTP Request - POST/articles above the if controller.
This will make your script send an email if the sampler failed and you will have the body variable holding the failure message.
I am writing a REST API in JAX-RS 2.0, JDK 8 for the below requirement
POST API /server/fileUpload/ (Multipart Form data) where I need to send a Big .AI (Adobe Illustrator) File in this.
The Server, takes the file and return Status 202 (Accepted), Acknowledging that file transfer happened Successfully. (From endpoint to Server)
Now at the Server, I am using Java + Imagemagik to convert .AI File (20-25 MB File) to small JPG Thumbnail, place on a Apache HTTP Server and share the location (like http://happyplace/thumbnail0987.jpg)
Now the Second Response should come from Server with Status 200 OK and Thumbnail URL
is it feasible with one REST API? (Async/similar)
or should I split it to 2 API calls, Please suggest
No. In http, one request gets one response. The client must send a second request to get a second response.
You can use WebSockets for that.
If you are calling from script the call will be async you can handle the Thumbnail URL when you get a response. When you are calling from java program i suggest to run it on a different thread, If the execution is not sequential i.e ( Remaining lines can be executed without getting URL). If url is needed for the remaining section of code you can make one call and wait for the response then execute remaining code.
You need to make different APIs for both scenarios. One for showing file upload status and another for all file conversion and manipulation.
On the client side second request must be callback of first request.
The best way to handle these kind of scenario is to use Java Reactive (Project Reactor, WebFlux).
You can return two response using custom middlewares in asp.net (however not recommended).
Return response from one middleware and subsequently you can invoke next middleware and return second response from second middleware