Comments (8)
This is now implemented and merged into master. Release 0.5 will go out later today.
You can set it by using the stripBasePath
method in the LambdaContainerHandler
object.
JerseyLambdaContainerHandler<AwsProxyRequest, AwsProxyResponse> handler = JerseyLambdaContainerHandler.getAwsProxyHandler(jerseyApplication);
handler.stripBasePath("/customDomainBasePath");
I've used Jersey for my example but the method is available in all implementations.
from aws-serverless-java-container.
Hi @jinwg
I can see this going both ways. Let me make a practical example of an application that is composed of two services: First, a catalogue service accessible from the /catalogue
resource; second, an ordering service accessible from the /orders
resources. The services would be implemented as two separate Lambda function, each expecting a full resource path - for the orders service this could be /orders/{orderId}
.
To allow the two teams to build the APIs independently you would declare these two as completely separate APIs in API Gateway and them bring them together with a custom domain name, using the /orders
and /catalogue
as base paths in the custom domain name.
Because each team has declared the full path for each service in their code, you would still want to receive the full path of the request.
I can also see a scenario where the developers of the orders service would just declare the /
and /{id}
in their code, assuming that API Gateway is in charge of the routing before that. While this would work, I don't think it's practical when you want to start the application outside of API Gateway and Lambda.
One option here could be to expose a setting in the library to decide whether a base path mapping should be excluded from the request path object. Any thoughts?
from aws-serverless-java-container.
@sapessi , thanks for your reply. sometime the base path in API gateway domain mapping is not full controlled by developer. other product team may decide how to use that. and this issue only happen when i use {proxy+} mode, if i publish each method behind API endpoint, this problem will not happen. look below path filed for 2 cases, possible it is problem of APIGateway?
Custom domain with base path /contentalerts
"path": "/contentalerts1/subscriptions/user/1234",
"pathParameters": {
"proxy": "subscriptions/user/1234"
},
"requestContext": {
"path": "/contentalerts1/subscriptions/user/1234",
Direct API endpoint without custom domain
"path": "/subscriptions/user/1234",
"pathParameters": {
"proxy": "subscriptions/user/1234"
},
"requestContext": {
"path": "/dev/subscriptions/user/1234",
from aws-serverless-java-container.
oh, sorry.. i misunderstand you.. my bad..
from aws-serverless-java-container.
@jinwg No need to close the issue. If you think we should offer an option to exclude a base path from the request leave it open and we'll talk it through
from aws-serverless-java-container.
@sapessi This sounds like an issue with the APIGateway, surely it shouldn't be including the custom domains base path but instead be mapping directly to the raw endpoint. A quick work around for this, is rewriting the path
variable to match the resource
variable e.g.
awsProxyRequest.setPath(awsProxyRequest.getResource());
It's an unfortunate hack but it worked for us.
from aws-serverless-java-container.
@johnboy14 I don't think it's so black and white. The base path may actually be part of the endpoint you define in the code. Per my original example, you may have the API called orders that defines the resources under /orders. However, the /orders
resource is not part of the API definition but rather a base path in the custom domain name, this way you can have both /orders
and /catalogue
under the same domain name, even though they are completely separate APIs. To write your app in such a way that it can be executed both in Lambda + API Gateway and EC2 you would want to define the full path in your annotations /orders/{id}
. In this case it would be important for API GW to pass the full path.
The Resource
string would not work here. The resource is what is configured in API Gateway, such as /orders/{proxy+}
- this is something most framework would not understand.
I think the most generic solution is to offer an option to define whether you want the base path excluded or not.
from aws-serverless-java-container.
@sapessi, thanks for reopening this again. i agree with you, it is better to offer an option to define wether or not exclude the base path, and suggest excluding the base path by default. i think a microservice usually is supposed to handle its own internal resources without dependency of external input.
Thanks again.
from aws-serverless-java-container.
Related Issues (20)
- Reinitialization of Spring context when using SnapStart HOT 3
- Spring Cloud Gateway throwing "hostname can't be null" based on my request only having headers and not multi-value headers HOT 4
- ServletContext: Servlet.getServletConfig() is null HOT 1
- Cannot invoke "org.springframework.web.servlet.DispatcherServlet.getServletContext()" because "servlet" is null HOT 4
- org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: No content to map due to end-of-input HOT 1
- org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: No content to map due to end-of-input HOT 8
- Cannot deserialize value of type `java.lang.String` from Object value HOT 3
- SpringDelegatingLambdaContainerHandler unable to respond with rendered templates HOT 10
- SpringDelegatingLambdaContainerHandler does not handle Headers correctly for FunctionUrls HOT 7
- Cookies not able to be deleted by setting max-age to 0 HOT 3
- com.amazonaws.serverless.exceptions.InvalidRequestEventException: The incoming event is not a valid request from Amazon API Gateway or an Application Load Balancer HOT 2
- 2.x release HOT 1
- AwsProxyResponse class is generating response JSON which is rejected by API gateway with Malformed error HOT 3
- Moved AwsProxyRequestBuilder into test package HOT 4
- How to handle spring security with springboot serverless HOT 2
- Null Pointer While Setting Filter Post Startup Lambda Handler HOT 2
- Spring boot 3 context initialization issue when using with a servlet application having webflux dependency for web client HOT 3
- Error with version 2.0.2 when multi-value header is active in alb HOT 6
- Springboot 2 Lambda Layer Support HOT 2
- Query parameter values not URL decoded when using HTTP API V2 Gateway with a RequestStreamHandler implementation HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from aws-serverless-java-container.