Quarkus and DynamoDBMapper - Failing to build a native executable - Error Random/SplittableRandom

348 views Asked by At

I've got a Quarkus project where DynamoDBMapper is also being used. Everything runs perfectly in dev mode.

But when running this command mvn package -Pnative -pl my-module -DskipTests it gives me this error

[my-module-1.0-SNAPSHOT-runner:61]      [total]: Error: Unsupported features in 2 methods
Detailed message:
Error: Detected an instance of Random/SplittableRandom class in the image heap. Instances created during image generation have cached seed values and don't behave as expected.  To see how this object got instantiated use --trace-object-instantiation=java.util.Random. The object was probably created by a class initializer and is reachable from a static field. You can request class initialization at image runtime by using the option --initialize-at-run-time=<class-name>. Or you can write your own initialization methods and call them explicitly from your main entry point.
Trace: Object was reached by 
    reading field com.amazonaws.retry.PredefinedBackoffStrategies$EqualJitterBackoffStrategy.random of
        constant com.amazonaws.retry.PredefinedBackoffStrategies$EqualJitterBackoffStrategy@2ad70ff4 reached by 
    reading field com.amazonaws.retry.PredefinedBackoffStrategies$SDKDefaultBackoffStrategy.equalJitterBackoffStrategy of
        constant com.amazonaws.retry.PredefinedBackoffStrategies$SDKDefaultBackoffStrategy@64d81db reached by 
    reading field com.amazonaws.retry.RetryPolicy.backoffStrategy of
        constant com.amazonaws.retry.RetryPolicy@7ce3fed7 reached by 
    scanning method com.amazonaws.services.dynamodbv2.AmazonDynamoDBClientConfigurationFactory.getDefaultConfig(AmazonDynamoDBClientConfigurationFactory.java:31)
Call path from entry point to com.amazonaws.services.dynamodbv2.AmazonDynamoDBClientConfigurationFactory.getDefaultConfig(): 
    at com.amazonaws.services.dynamodbv2.AmazonDynamoDBClientConfigurationFactory.getDefaultConfig(AmazonDynamoDBClientConfigurationFactory.java:31)
    at com.amazonaws.ClientConfigurationFactory.getConfig(ClientConfigurationFactory.java:36)
    at com.amazonaws.client.builder.AwsClientBuilder.resolveClientConfiguration(AwsClientBuilder.java:169)
    at com.amazonaws.client.builder.AwsClientBuilder.access$000(AwsClientBuilder.java:54)
    at com.amazonaws.client.builder.AwsClientBuilder$SyncBuilderParams.<init>(AwsClientBuilder.java:505)
    at com.amazonaws.client.builder.AwsClientBuilder.getSyncClientParams(AwsClientBuilder.java:441)
    at com.amazonaws.client.builder.AwsSyncClientBuilder.build(AwsSyncClientBuilder.java:46)
    at integration.common.config.DynamoDBConfig.dynamoDBMapper(DynamoDBConfig.java:23)
    at integration.common.config.DynamoDBConfig_ProducerMethod_dynamoDBMapper_f166ddedc44150bc6c5ef50fafe7a64b599d849a_Bean.create(Unknown Source)
    at integration.common.config.DynamoDBConfig_ProducerMethod_dynamoDBMapper_f166ddedc44150bc6c5ef50fafe7a64b599d849a_Bean.create(Unknown Source)
    at io.quarkus.arc.impl.AbstractSharedContext.createInstanceHandle(AbstractSharedContext.java:111)
    at io.quarkus.arc.impl.AbstractSharedContext$1.get(AbstractSharedContext.java:35)
    at io.quarkus.arc.impl.AbstractSharedContext$1.get(AbstractSharedContext.java:32)
    at com.oracle.svm.core.jdk.SystemPropertiesSupport.initializeLazyValue(SystemPropertiesSupport.java:216)
    at com.oracle.svm.core.jdk.SystemPropertiesSupport.getProperty(SystemPropertiesSupport.java:169)
    at com.oracle.svm.core.jdk.Target_java_lang_System.getProperty(JavaLangSubstitutions.java:287)
    at com.oracle.svm.jni.JNIJavaCallWrappers.jniInvoke_ARRAY_System_getProperty_deeeaa72a006d330408a3b7d002c7533e108bc28(generated:0)

The dependency for DynamoDBMapper in pom.xml

    <dependency>
        <groupId>com.amazonaws</groupId>
        <artifactId>aws-java-sdk-dynamodb</artifactId>
        <version>1.12.205</version>
    </dependency>

The configuration class

@ApplicationScoped
public class DynamoDBConfig {

    @ConfigProperty(name = "DYNAMO_DB_TABLE_NAME")
    String tableName;

    @Produces
    public DynamoDBMapper dynamoDBMapper() {

        return new DynamoDBMapper(
                AmazonDynamoDBClientBuilder.standard().build(),
                tableNameConfig()
        );
    }

    private DynamoDBMapperConfig tableNameConfig() {

        return new DynamoDBMapperConfig.Builder()
                       .withTableNameOverride(TableNameOverride.withTableNameReplacement(
                tableName)).build();
    }
}

I've found out that this AmazonDynamoDBClientBuilder.standard().build() specific line is causing this issue.

I've tried adding com.amazonaws to application.properties to solve this issue. Which it does locally with the previous command but fails in a aws lambda when it runs.

quarkus.native.additional-build-args=--initialize-at-run-time=org.apache.http.impl.auth.NTLMEngineImpl\
    \\,io.netty.util.internal.logging.Log4JLogger\
    \\,com.amazonaws
0

There are 0 answers