Trying to run spring cloud function with spring boot in AWS lambda. The lambda errors out at runtime - errors attached below
- Java Version: 11
- Spring Boot: 2.7.1
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.1</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>com.myorg.jobs</groupId>
<artifactId>sample-jobs</artifactId>
<packaging>jar</packaging>
<properties>
<builder>paketobuildpacks/builder:tiny</builder>
<spring-boot.version>2.7.1</spring-boot.version>
<spring-native.version>0.12.1</spring-native.version>
<log4j2.version>2.17.1</log4j2.version>
<java.version>11</java.version>
<wrapper.version>1.0.29.RELEASE</wrapper.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<wrapper.version>1.0.29.RELEASE</wrapper.version>
<aws-lambda-events.version>3.9.0</aws-lambda-events.version>
<spring-cloud-function.version>3.2.12</spring-cloud-function.version>
<com.amazonaws.java-sdk-lambda.version>1.9.22</com.amazonaws.java-sdk-lambda.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<!-- <optional>true</optional> -->
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-lambda-java-core</artifactId>
<version>1.1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-lambda</artifactId>
<version>${com.amazonaws.java-sdk-lambda.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.experimental/spring-native -->
<dependency>
<groupId>org.springframework.experimental</groupId>
<artifactId>spring-native</artifactId>
<version>0.12.1</version>
</dependency>
<dependency>
<groupId>com.github.ulisesbocchio</groupId>
<artifactId>jasypt-spring-boot-starter</artifactId>
<version>3.0.5</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<image>
<builder>${builder}</builder>
<env>
<BP_NATIVE_IMAGE>true</BP_NATIVE_IMAGE>
<BP_JVM_VERSION>11</BP_JVM_VERSION>
<BP_NATIVE_IMAGE_BUILD_ARGUMENTS>--initialize-at-build-time=org.springframework.util.ConcurrentReferenceHashMap,org.springframework.util.ClassUtils
--trace-class-initialization=org.springframework.util.ConcurrentReferenceHashMap,org.springframework.util.ClassUtils</BP_NATIVE_IMAGE_BUILD_ARGUMENTS>
</env>
<pullPolicy>IF_NOT_PRESENT</pullPolicy>
</image>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.experimental</groupId>
<artifactId>spring-aot-maven-plugin</artifactId>
<version>${spring-native.version}</version>
<executions>
<execution>
<id>test-generate</id>
<goals>
<goal>test-generate</goal>
</goals>
</execution>
<execution>
<id>generate</id>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<pluginRepositories>
<pluginRepository>
<id>spring-snapshots</id>
<url>https://repo.spring.io/snapshot</url>
</pluginRepository>
<pluginRepository>
<id>spring-milestones</id>
<url>https://repo.spring.io/milestone</url>
</pluginRepository>
</pluginRepositories>
<repositories>
<repository>
<id>spring-release</id>
<name>Spring release</name>
<url>https://repo.spring.io/release</url>
</repository>
</repositories>
</project>
SpringBoot Main Application
import java.net.InetAddress;
import java.net.UnknownHostException;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.elasticsearch.ElasticsearchRestClientAutoConfiguration;
import org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfiguration;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.core.env.Environment;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.data.mongodb.repository.config.EnableMongoRepositories;
import com.myorg.profile.util.DefaultProfileUtil;
import com.ulisesbocchio.jasyptspringboot.annotation.EnableEncryptableProperties;
@SpringBootApplication
@EnableEncryptableProperties
@EnableAutoConfiguration(exclude = { ErrorMvcAutoConfiguration.class, ElasticsearchRestClientAutoConfiguration.class })
@EnableConfigurationProperties
@ComponentScan(basePackages = { "com.myorg" })
@EnableFeignClients(basePackages = "com.myorg")
@EnableJpaRepositories(basePackages = "com.myorg")
@EnableMongoRepositories("com.myorg")
public class SampleJobApplication {
private static final Logger log = LoggerFactory.getLogger(SampleJobApplication .class);
private final Environment env;
public SampleJobApplication(Environment env) {
this.env = env;
}
public static void main(String[] args) {
SpringApplication app = new SpringApplication(SampleJobApplication.class);
DefaultProfileUtil.addDefaultProfile(app);
Environment env = app.run(args).getEnvironment();
}
private static void logApplicationStartup(Environment env) {
String protocol = "http";
if (env.getProperty("server.ssl.key-store") != null) {
protocol = "https";
}
String serverPort = env.getProperty("server.port");
String contextPath = env.getProperty("server.servlet.context-path");
if (StringUtils.isBlank(contextPath)) {
contextPath = "/";
}
String hostAddress = "localhost";
try {
hostAddress = InetAddress.getLocalHost().getHostAddress();
} catch (UnknownHostException e) {
log.warn("The host name could not be determined, using `localhost` as fallback");
}
log.info(
"\n----------------------------------------------------------\n\t" + "Application '{}' is running! Access URLs:\n\t"
+ "Local: \t\t{}://localhost:{}{}\n\t" + "External: \t{}://{}:{}{}\n\t"
+ "Profile(s): \t{}\n----------------------------------------------------------",
env.getProperty("spring.application.name"), protocol, serverPort, contextPath, protocol, hostAddress, serverPort, contextPath,
env.getActiveProfiles());
}
}
SpringCloudFunction
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import org.apache.commons.collections.MapUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@Component("springCloudFunctionOne")
public class SpringCloudFunctionOne implements Function<Map<String, Object>, Map<String, Object>>{
@Override
public Map<String, Object> apply(Map<String, Object> t) {
Map<String, Object> response = new HashMap<>();
response.put("status", "success");
return response;
}
}
Here is the AWS Lambda execution output
2024-03-26 14:46:35.588 INFO 8 --- [ main] o.s.nativex.NativeListener : AOT mode enabled
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.7.1)
INIT_REPORT Init Duration: 10002.90 ms Phase: init Status: timeout
2024-03-26 14:46:36.081 INFO 9 --- [ main] o.s.nativex.NativeListener : AOT mode enabled
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.7.1)
2024-03-26 14:46:36.114 INFO 9 --- [ main] c.g.c.CredentialingJobApplication : Starting CredentialingJobApplication using Java 11.0.19 on 169.254.55.13 with PID 9 (/workspace/com.ghx.credentialing.CredentialingJobApplication started by sbx_user1051 in /workspace)
2024-03-26 14:46:36.114 INFO 9 --- [ main] c.g.c.CredentialingJobApplication : The following 1 profile is active: "dev"
2024-03-26 14:46:36.240 WARN 9 --- [ main] w.s.c.ServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'enableEncryptablePropertySourcesPostProcessor': Unsatisfied dependency expressed through method 'enableEncryptablePropertySourcesPostProcessor' parameter 1; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'encryptablePropertySourceConverter': Unexpected exception during bean creation; nested exception is java.lang.IllegalArgumentException: Invalid jasypt.encryptor.skip-property-sources: Class org.springframework.boot.context.properties.source.ConfigurationPropertySourcesPropertySource not found
2024-03-26 14:46:36.283 ERROR 9 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
Native reflection configuration for org.springframework.boot.context.properties.source.ConfigurationPropertySourcesPropertySource is missing.
Action:
Native configuration for a class accessed reflectively is likely missing.
You can try to configure native hints in order to specify it explicitly.
See https://docs.spring.io/spring-native/docs/current/reference/htmlsingle/#native-hints for more details.
INIT_REPORT Init Duration: 337.49 ms Phase: invoke Status: error Error Type: Runtime.ExitError
START RequestId: 90bab59f-bb33-4346-b129-c3fd1da25e23 Version: $LATEST
RequestId: 90bab59f-bb33-4346-b129-c3fd1da25e23 Error: Runtime exited with error: exit status 1
Runtime.ExitError
END RequestId: 90bab59f-bb33-4346-b129-c3fd1da25e23
REPORT RequestId: 90bab59f-bb33-4346-b129-c3fd1da25e23 Duration: 338.37 ms Billed Duration: 339 ms Memory Size: 512 MB Max Memory Used: 35 MB