2

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:

    <dependency>
        <groupId>com.amazonaws.serverless</groupId>
        <artifactId>aws-serverless-java-container-spring</artifactId>
        <version>[0.1,)</version>
    </dependency>

I have some issues with this steps:

  1. Do i need to remove @ComponentScan and use @Import for all classes. Means if i have 10 controllers and 4 service classes and 2 repository classes that we are autowiring, So do we need to add all these classes in @Import

Actually i am new in this. Can anyone help me with simple steps?

1
  • It is unclear what you are asking. Are you trying to deploy your entire Spring Boot application to AWS Lambda? Commented Jul 31, 2019 at 15:04

1 Answer 1

1

The 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

Sign up to request clarification or add additional context in comments.

7 Comments

Do we need to put Outputs.SpringBootPetStoreApi.Value in sam.yml file?. sam.yaml file is important?
In my application i have no API but have kafka consumer.
If we have multiple controller, we have to put @EnableWebMvc in all controller?
Can you please provide me sample code having mulliple controller with service and repository?
You don't need Outputs section in case you don't plan to reuse any resources from this template in the others. As you have a Kafka consumer, then you probably would like to pass the connection configuration through environment parameters to the lambda. Check this doc for reference docs.aws.amazon.com/lambda/latest/dg/env_variables.html and use in the Lambda definition like Environment: Variables: ENV_VAR_NAME: "value" (or you can start with a hardcoded value).
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.