GET and POST Spring boot rest api with aws Lambda - aws-lambda

I have a spring boot application with GET and POST request which is working fine. Now I want to use aws lambda. I have check various article and github project for converting serverless application but didn't find any useful.
I tried with simple application which accept string as input and it is running in aws lambda but my requirement is having json input for multiple POST requests.
If anyone can help me with how to test and run multiple POST request.

Related

How to integrate swagger with spring cloud function

I have one spring boot application having three spring cloud function which I am able to execute via postman or curl successfully .Now my next step is to add swagger documentation for the same. I have followed all configuration that we do to add swagger with normal spring boot project. And it is up and running but problem is that my functions URL are not listed in swagger since Request Mapping or API operations annotations are not getting picked up maybe those are just functions not a controller that's y. So if someone could help how to integrate so i can document all cloud functions that I am creating.

Is there anyway we can use Spring Cloud Functions + AWS Lambda adapter to process http file uploads?

I am new to AWS and FAAS. My work place is interested in processing HTTP file upload with AWS Lambda and Spring Boot. A quick research led me to Spring Cloud Functions + AWS Lambda adapter; however, documentation doesn't cover anything related to HTTP file uploads, so I wonder if it is possible to do that with Spring Cloud Function or I have to fallback to AWS Lambda Spring Boot integration (https://github.com/awslabs/aws-serverless-java-container)?
Thanks in advance for your kind enlightenment!
AWS lambda can be triggered in many ways like API gateway, S3Event, SNS notification and SQS. API gateway integrates lambda with HTTP end points. API gateway is not designed to handle file uploads. API gateway converts binary data to base64 encoded text. Handling binary data as text consumes a lot of memory and processing gets tricky as well.
Also API gateway has a 10MB limit on payload size. The best approach to upload files is using S3. Even better approach would be to use a lambda function to generate a pre-signed S3 url to upload files.
Spring cloud function when integrated with an API gateway is intended to expose a single HTTP endpoint. However AWS Lambda spring boot integration by awslabs can expose multiple end points. Choose the approach that best works you.
Hope that helps.

Spring Cloud Function-suitable for REST API? How to access GET path params?

I'm new to WebFlux and Serverless. I'm trying to create a REST API as Serverless via AWS API gateway.
The flow would be API Gateway --> Lambda --> DynamoDB
In order to achieve the API flow, would the Spring Cloud Function be the best choice? I found aws-serverless-java-container does the job seamlessly(wrapper of converting the event to http request/response)
I've gone through the documentation on http://cloud.spring.io/spring-cloud-function/single/spring-cloud-function.html and few examples found in https://github.com/spring-cloud/spring-cloud-function.
But still, I'm not convinced on whether with Spring Cloud Function I would be able to achieve the API flavor.
#Bean
//How path or query params can be mapped?
public Function<Flux<String>, Flux<String>> getEmployeeDetails() {
// business logic goes here
}
In the above snippet, how to achieve the GET request/response model. If my endpoint has /{dept}/{employee}/{name}, how Spring cloud function accepts the path params in GET request?
Any pointers would be helpful.
API Gateway wraps all data of the incoming request into an APIGatewayProxyRequestEvent object, which has several attributes, like the request body, path and query parameters, or the HTTP method of the original request.
For your use case, you would get the three path parameters dept, employee, and name.
However, the problem is that SpringBootApiGatewayRequestHandler, which does the mapping between the incoming APIGatewayProxyRequestEvent and your function, currently only considers a request body, but no other parameters at all.
I hope that the developers will fix this in the future.
In the meantime, you could implement a modified version of SpringBootApiGatewayRequestHandler, which considers the required parameters.
I've written a small article, which covers exactly this topic.
I have the same mistake with this, the documentation prompts you to think that you can do this, but you can't. This is only an example from spring-cloud-function, and springboot function aws specific code doesn't have this feature implemented (as far I could see).
You can follow the default route, if you want to implement your application in lambda with spring: https://github.com/awslabs/aws-serverless-java-container/blob/master/samples/springboot/pet-store.
Or... If you want, you can try the hard way, but attemption: you are completely alone: https://github.com/arawn/building-serverless-application-with-spring-webflux.
This project himself implements ObjecMapper conversions and you can get the parameters from request: https://github.com/arawn/building-serverless-application-with-spring-webflux/blob/master/src/main/java/serverless/aws/springframework/http/server/reactive/SimpleAPIGatewayProxyServerHttpRequest.java
The trick from here is to create Path template in lambda with proxy (Path: '/{proxy+}') and request are delegated from aws mapper.
Good luck!

Testing REST API provider response without mock

Currently, I am working on a project on Spring Boot where we are integrating with external REST API. As part of our integration suite test, we are doing the mock test of the actual external API which executes as part of the CI/CD.
My question is in production it calls the actual API so, how we can do that in the test environment. I don't think we need to make the actual external provider call during multiple integration test which will load the external API, also at the same time would like to test with actual REST response from the service.
Any suggestions?
If the public API has a swagger description, you could use the Atlassian Pact Swagger Validator. I describe the workflow in this talk: https://www.youtube.com/watch?v=79GKBYSqMIo#t=39m10s
Another alternative would be to create a mock API for the external service. There are some free services like https://mockfirst.com, https://www.mockable.io/, etc. where you can do that.

mimic swagger api on spring boot application

I got a Spring boot REST based proxy server application with standard REST End point exposed(GET, POST,PUT and DELETE) to outside world.
Any requests coming from external world then will be routed to actual functionality internally.
Now the requirement is to expose all the API supported by my REST proxy server. As I mentioned I do not have static controller path in my code for individual APIs. So would like to get your input how to create swagger support for all the internal APIs that my proxy server support. Is there are a way I can generate swagger schema manually to mimics the controller path? Or is there any other way to solve this problem?
Thanks in advance.

Resources