aws-serverless-java-container | Java wrapper to run Spring | REST library
kandi X-RAY | aws-serverless-java-container Summary
kandi X-RAY | aws-serverless-java-container Summary
A Java wrapper to run Spring, Jersey, Spark, and other apps inside AWS Lambda.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Encodes the given String as a String .
- Parse the header value .
- Gets the filter chain .
- Create resources .
- Return output stream .
- Performs the actual proxy request .
- Returns the authenticated user principal .
- Writes the response body to the LambdaProxyResponse object .
- Performs a forward request .
- Validates the configuration .
aws-serverless-java-container Key Features
aws-serverless-java-container Examples and Code Snippets
Community Discussions
Trending Discussions on aws-serverless-java-container
QUESTION
I have created a spring boot application with spring data JPA that should connect with a RDS instance,i have api's exposed which will deo CRUD basically I have provided the DB connection details as below in application.yml file,
...ANSWER
Answered 2021-Feb-18 at 12:23Increasing Lambda timeout fixed this issue. Added the below lines too,
LambdaContainerHandler.getContainerConfig().setInitializationTimeout(60_000); handler = SpringBootLambdaContainerHandler.getAwsProxyHandler(Application.class);
QUESTION
I have a spring boot app that I am trying to boot as a Lambda with the aws-serverless-java-container-spring library, and upon startup I get the error:
...ANSWER
Answered 2020-Dec-08 at 23:28The common answer to this question is that you have mixed up some libraries, although I could never find good instructions on how to resolve the issue.
The key thing to understand here is that the org.springframework.cloud.bootstrap.BootstrapApplicationListener
class comes from the spring-cloud-context
library, while org.springframework.boot.builder.SpringApplicationBuilder
comes from the spring-boot
library.
Using mvn dependency:tree
I could see the following output:
QUESTION
I am new to aws lambda and I am moving my spring boot 2.x based project to lambda.But I am struggling with lambda cold-start and warm-up. I tried a few things mentioned in this link:https://github.com/awslabs/aws-serverless-java-container/wiki/Quick-start---Spring-Boot, but still the application takes around 45 secs to start.
Things I tried:
Async initialization from the above link. It did help a bit but not enough.
Skip the Init phase of the lambda. It helped reduce almost 8 secs.
Provisioned concurrency but as far as I could see, it is not helping either. When I saw the logs, the spring context is getting initialized every time, if any request comes after an interval of 15-20 mins.
The response time of my lambda in different scenarios is:
...ANSWER
Answered 2020-Mar-21 at 19:21A 5 minute Cloudwatch Event would come out to arount 8600 calls / month. If you ran even 100000 calls it's still free according to the calculator on https://aws.amazon.com/lambda/pricing/ with 3GB of memory.
To configure Cloudwatch to ping your Lambda, start by creating rule (Cloudwatch -> Rules) and have it run every 5 minutes:
Then, have it run your Lambda:
My Lambda in this example is named SnapshotHandler and it takes a small JSON object. Note that this calls the Lambda directly, not through an API gateway. That may or may not be what your Lambda code is expecting so you may need to update.
If you want to call this Lambda via a HTTP/S API, you'll need to setup an SNS topic to publish the Cloudwatch event to and have the SNS topic call your API via HTTP. This is a bit more complicated but not terrible.
All in all, you can do this but the cost is dependent on how many "normal" calls your API gets. At 1000000 calls per month a 3GB / 800ms Lambda is at about USD $33. At 10000000 it's nearly USD $400. But if you're getting that many calls (an average of about 230/second) it seems unlikely you need a heartbeat too.
QUESTION
I'm using aws-serverless-java-container to wrap a Jersey service in a AWS Lambda. I decided to use function alias to have a "test" and "prod" stage that eventually points to different versions of the lambda function.
I need to select some properties in a .properties file based on that alias, basically because I need to talk to a "test" or "prod" DB or use a different endpoint to invoke an external web service.
For such purpose I need to invoke the method getInvokedFunctionArn of the Context object. Unfortunately the Jersey resource is not aware of such context by default.
Below a sample resource:
...ANSWER
Answered 2019-Jun-23 at 07:19You can Inject context to jersey resources using Spring profile
Define for test and prod profiles different methods/objects
If you don't have Spring, you can check jersey integration
jersey-spring4 module that will act as the integration bridge for Spring and Jersey.
See full example in github aws-serverless-java-container library running a Spring application with profiles in AWS Lambda
There are two ways to activate Spring Profiles (as defined with the @Profile annotation). We recommend using the static initializer that receives a list of profiles. The Serverless Java Container framework takes care of setting the profile and initializing the application at once.
QUESTION
I want to configure aws lambda in my existing Spring boot project. In my project i am using lombok, kafka consumer, and microservice. I follow steps at:
https://github.com/awslabs/aws-serverless-java-container/wiki/Quick-start---Spring-Boot
I added dependency:
...ANSWER
Answered 2019-Jul-31 at 23:35The lambda will still work with @ComponentScan
but the cold-start will take longer because of the all classes scan, which is mentioned in the tutorial. You can read more about cold-start in java, for example here https://aws.amazon.com/blogs/opensource/java-apis-aws-lambda (see "Cold start notes"). In short, when AWS Lambda doesn't reuse a container with your function/application it starts the application and scans all the classes while executing @ComponentScan
. With @Import
you avoid this scan, and that makes cold-start faster.
You can also check the code sample for this package https://github.com/awslabs/aws-serverless-java-container/tree/master/samples/springboot/pet-store
QUESTION
I just tried to run a Spring Boot application on AWS Lambda using the following article: https://github.com/awslabs/aws-serverless-java-container/wiki/Quick-start---Spring-Boot
Basic requests are just working fine, but sending files seems to cause problems. Running the application locally works fine:
...ANSWER
Answered 2018-Oct-27 at 17:19This was a bug in Amazon's library and has been fixed some days ago. More information is available here. Just make sure to use version 1.2 or above:
QUESTION
I want to develop a new java webservice
to be deployed on AWS Lambda
, but I also want to be able to easily test it.
My idea is to code my webservice
using Jersey
and be able to compile it into a war
file, so I can test it localy and also be able to compile it into a jar
for the Serverless Java container
from AWS.
My first thought was to create 2 modules on IntelliJ IDEA 2017.3 Ultimate
, one for the war
and one for the jar
, all using Maven, with the 2 modules sharing the same code base for the Jersey REST Resources
(the webservice
classes). But unfortunately I am too new to IntelliJ IDEA
and I can't put this to work.
Is there a way to achieve this?
...ANSWER
Answered 2017-Dec-07 at 13:53Solution you provided is workable but IMO overcomplicated a bit. I did something similar for my project: first I made a module with all the sources and tests, then I sliced it to different artifacts. It's not the cleanest solution though - you have a risk of placing dependent classes to different artifacts and cause classloading issues in runtime.
In your case it is simpler - you only need to repackage same content to another artifact, if I get it right. In simplest case, one module would be enough. You can just add a plugin for assembling WAR archive, like that:
QUESTION
I am using the AWS labs' serverless container (https://github.com/awslabs/aws-serverless-java-container) to handle the lambda entrypoint and response for a lambda that returns HTML. It appears that it calls the lambda and returns the HTML just fine from the lambda. However, API Gateway then throws a fit processing the response. I am using the API Gateway as a proxy, not configuring individual endpoints.
Wed Jun 21 20:53:29 UTC 2017 : Endpoint response body before transformations: --- statusCode: 200 headers: Content-Type: "text/html" body: "\r\n\r\nhttp://www.w3.org/1999/xhtml\"\r\n \ \ lang=\"en\">\r\n \r\n \r\n \ \ Page Title\r\n \r\n \r\n \ \ \r\n \r\n\ \ \r\n \r\n ... [TRUNCATED] Wed Jun 21 20:53:29 UTC 2017 : Endpoint response headers: {x-amzn-Remapped-Content-Length=0, x-amzn-RequestId=adb2b101-56c3-11e7-afc6-8383d836980f, Connection=keep-alive, Content-Length=17551, Date=Wed, 21 Jun 2017 20:53:29 GMT, X-Amzn-Trace-Id=root=1-594adcc9-6987c6ed102696c505538b02;sampled=0, Content-Type=application/octet-stream} Wed Jun 21 20:53:29 UTC 2017 : Execution failed due to configuration error: Malformed Lambda proxy response Wed Jun 21 20:53:29 UTC 2017 : Method completed with status: 502
As you can see from the logs, the AWS own Java object, AwsProxyResponse, properly wraps the HTML content how AWS coded it. You see it returning the proper body and text/html headers. It seems API Gateway then blows up handling a response from AWS's own response.
How do I get AWS Gateway to properly handle the response when the response form the lambda is Content-Type: test/html?
...ANSWER
Answered 2017-Jun-21 at 21:48The response from the Lambda function does not look correct. It appears a raw string without any format.
It should be JSON in the format:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install aws-serverless-java-container
You can use aws-serverless-java-container like any standard Java library. Please include the the jar files in your classpath. You can also use any IDE and you can run and debug the aws-serverless-java-container component as you would do with any other Java program. Best practice is to use a build tool that supports dependency management such as Maven or Gradle. For Maven installation, please refer maven.apache.org. For Gradle installation, please refer gradle.org .
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page