xxxxxxxxxx
@SpringBootApplication
public class SpringCloudFunctionAwsApplication {
@Bean
public Function<String, String> uppercase() {
return (String request) -> request.toUpperCase();
}
@Bean
public Function<String, String> lowercase() {
return (String request) -> request.toLowerCase();
}
public static void main(String[] args) {
SpringApplication.run(SpringCloudFunctionAwsApplication.class, args);
}
}
You can use the aws-serverless-java-container library to run a Spring Boot application in AWS Lambda. You can use the library within your Lambda handler to load your Spring Boot application and proxy events to it. In the repository we have included a sample Spring Boot application to get you started.
xxxxxxxxxx
@Component("generateShortcode")
public class GenerateShortcodeFunction implements Function<String, String> {
@Autowired
private LambdaFunctions lambdaFunctions;
@Autowired
private UrlDAO urlDAO;
@Override
public String apply(String url) {
try {
new URL(url);
} catch (MalformedURLException e) {
throw new InvalidURLFormatException();
}
String shortCode = urlDAO.generateShortCode();
urlDAO.storeUrl(shortCode, url);
EmailDetails emailDetails = new EmailDetails("marc@mtdevuk.com",
"marc@mtdevuk.com", "Congratulations, you have created a shortCode for: " + url,
url, shortCode);
lambdaFunctions.sendShortcodeGeneratedEmail(emailDetails);
return shortCode;
}
}
https://github.com/awslabs/aws-serverless-java-container/wiki/Quick-start---Spring-Boot