Reputation: 3050
For my POC, created simple lambda function , which will give emp information through rest api. Created lambda function and access all the emp data using API gateway. Facing some challenges while accessing particular data.
i am looking for
emp/1 - to retrieve emp id emp/_search?name="apple" - search name contains apple.
Question is how to retrieve path and request parameters in java code.
public class TestAwsLambdaFunction implements RequestHandler<Map<String, Object>, String> {
@Override
public String handleRequest(Map<String, Object> input, Context context) {
String empID= null;
try {
@SuppressWarnings("unchecked")
Map<String, String> pathParameters = (Map<String, String>) input.get("querystring");
empID= pathParameters.get("id");
System.out.println(empID);
// TO-Do Business logic -
} catch (Exception e) {
// TODO: handle exception
}
return "Hello from Lambda!" + empID;
}
}
What is the best way to expose my data in Rest api call. Bit confused with Lambda or serverless . have any option to show the data via page wise. Since i am new to AWS. Please guide me
Upvotes: 0
Views: 2380
Reputation: 11449
Question is how to retrieve path and request parameters in java code.
You can use mapping template to send $input.params('name') property in the request body to your Lambda function.
What is the best way to expose my data in Rest api call
Use the proxy integration with these guidelines:
By Ben Kehoe
https://docs.aws.amazon.com/apigateway/latest/developerguide/how-to-call-api.html
https://www.puresec.io/blog/aws-security-best-practices-for-api-gateway
https://www.stackery.io/blog/serverless-function-architecture-principles/
https://technology.finra.org/code/enjoying-auto-scaling-integrated-authentication-low-host-cost.html
Upvotes: 1
Reputation: 774
You need to choose Lambda Proxy Integrations
when you set up your API Gateway. Here's official document Set up Lambda Proxy Integrations in API Gateway.
In this case, API Gateway will pass the whole request data to Lambda, including the request headers, query string parameters, URL path variables and so on. Then you can parse the data using your Java code.
Upvotes: 1