quarkiverse / quarkus-amazon-alexa

Quarkus Amazon Alexa extension
Apache License 2.0
5 stars 2 forks source link

Native Lambda Zip in AWS Lambda - Cannot create an instance of com.amazonaws.auth.AWS4Signer #53

Closed timguy closed 2 years ago

timguy commented 2 years ago

I have a skill, wich I "quarkified" for faster runtime (just overwrite everything from the zip I got from https://code.quarkus.io/?b=GRADLE&e=io.quarkiverse.amazonalexa%3Aquarkus-amazon-alexa&extension-search=origin:platform%20alexa)

Following error:
by Quarkus 2.12.1.Final) started in 0.069s. 
2022-09-14 13:04:43,175 INFO  [io.quarkus] (main) Profile prod activated. 
2022-09-14 13:04:43,175 INFO  [io.quarkus] (main) Installed features: [amazon-alexa, amazon-lambda, cdi]
START RequestId: 49fd4fb6-c3b9-479f-b8bd-a06bb7eee3cc Version: $LATEST
2022-09-14 13:04:43,535 ERROR [io.qua.ama.lam.run.AbstractLambdaPollLoop] (Lambda Thread (NORMAL)) Failed to run lambda (NORMAL): java.lang.IllegalStateException: Cannot create an instance of com.amazonaws.auth.AWS4Signer
at com.amazonaws.auth.SignerFactory.createSigner(SignerFactory.java:172)
at com.amazonaws.auth.SignerFactory.createSigner(SignerFactory.java:126)
at com.amazonaws.auth.SignerFactory.lookupAndCreateSigner(SignerFactory.java:114)
at com.amazonaws.auth.SignerFactory.getSigner(SignerFactory.java:83)
at com.amazonaws.AmazonWebServiceClient.computeSignerByServiceRegion(AmazonWebServiceClient.java:399)
at com.amazonaws.AmazonWebServiceClient.computeSignerByURI(AmazonWebServiceClient.java:371)
at com.amazonaws.AmazonWebServiceClient.setEndpoint(AmazonWebServiceClient.java:264)
at com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient.init(AmazonDynamoDBClient.java:362)
at com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient.<init>(AmazonDynamoDBClient.java:335)
at com.amazonaws.services.dynamodbv2.AmazonDynamoDBClientBuilder.build(AmazonDynamoDBClientBuilder.java:109)
at com.amazonaws.services.dynamodbv2.AmazonDynamoDBClientBuilder.build(AmazonDynamoDBClientBuilder.java:30)
at com.amazonaws.client.builder.AwsSyncClientBuilder.build(AwsSyncClientBuilder.java:46)
at com.amazon.ask.attributes.persistence.impl.DynamoDbPersistenceAdapter.<init>(DynamoDbPersistenceAdapter.java:114)
at com.amazon.ask.attributes.persistence.impl.DynamoDbPersistenceAdapter.<init>(DynamoDbPersistenceAdapter.java:46)
at com.amazon.ask.attributes.persistence.impl.DynamoDbPersistenceAdapter$Builder.build(DynamoDbPersistenceAdapter.java:350)
at com.amazon.ask.module.StandardSdkModule$Builder.build(StandardSdkModule.java:206)
at com.amazon.ask.builder.StandardSkillBuilder.getConfigBuilder(StandardSkillBuilder.java:100)
at com.amazon.ask.builder.StandardSkillBuilder.build(StandardSkillBuilder.java:109)
at github.timguy.theskill.StreamHandler.getSkill(StreamHandler.java:86)
at github.timguy.theskill.StreamHandler.<init>(StreamHandler.java:90)
at github.timguy.theskill.StreamHandler_Bean.create(Unknown Source)
at github.timguy.theskill.StreamHandler_Bean.get(Unknown Source)
at github.timguy.theskill.StreamHandler_Bean.get(Unknown Source)

at io.quarkus.arc.impl.ArcContainerImpl.beanInstanceHandle(ArcContainerImpl.java:468)
at io.quarkus.arc.impl.ArcContainerImpl.beanInstanceHandle(ArcContainerImpl.java:481)
at io.quarkus.arc.impl.ArcContainerImpl$1.get(ArcContainerImpl.java:285)
at io.quarkus.arc.impl.ArcContainerImpl$1.get(ArcContainerImpl.java:282)
at io.quarkus.arc.runtime.BeanContainerImpl$1.create(BeanContainerImpl.java:36)
at io.quarkus.arc.runtime.BeanContainer.instance(BeanContainer.java:19)
at io.quarkus.amazon.lambda.runtime.AmazonLambdaRecorder$1.processRequest(AmazonLambdaRecorder.java:191)
at io.quarkus.amazon.lambda.runtime.AbstractLambdaPollLoop$1.run(AbstractLambdaPollLoop.java:117)
at java.lang.Thread.run(Thread.java:833)
at com.oracle.svm.core.thread.PlatformThreads.threadStartRoutine(PlatformThreads.java:705)
at com.oracle.svm.core.posix.thread.PosixPlatformThreads.pthreadStartRoutine(PosixPlatformThreads.java:202)
Caused by: java.lang.InstantiationException: com.amazonaws.auth.AWS4Signer
at java.lang.Class.newInstance(DynamicHub.java:639)
at com.amazonaws.auth.SignerFactory.createSigner(SignerFactory.java:169)
... 33 more
Caused by: java.lang.NoSuchMethodException: com.amazonaws.auth.AWS4Signer.<init>()
at java.lang.Class.getConstructor0(DynamicHub.java:3585)
at java.lang.Class.newInstance(DynamicHub.java:626)
... 34 more
END RequestId: 49fd4fb6-c3b9-479f-b8bd-a06bb7eee3cc
REPORT RequestId: 49fd4fb6-c3b9-479f-b8bd-a06bb7eee3cc  Duration: 636.16 ms Billed Duration: 919 ms Memory Size: 128 MB Max Memory Used: 70 MB  Init Duration: 282.58 ms    

The AmazonDynamoDBClient is fetched because of my StreamHandler class and configuration withTableName("theskill_userData").

public class StreamHandler extends SkillStreamHandler {

    private static Skill getSkill() {^        
        return Skills.standard()
                .addRequestHandlers(
                        new LaunchRequestHandler(),
                        ...
                .addRequestInterceptors(new LogInterceptor(),new NewSessionRequestInterceptor())
                .withTableName("theskill_userData")
                .withAutoCreateTable(true) 
                .withSkillId(appId)
                .build();

Both classes: com.amazonaws.auth.SignerFactory.createSigner(SignerFactory.java:172) com.amazonaws.auth.AWS4Signer are from aws-java-sdk-core-1.11.420

SignerFactory uses Class.newInstance which is marked as deprecated:

This method propagates any exception thrown by the

  • nullary constructor, including a checked exception. Use of
  • this method effectively bypasses the compile-time exception
  • checking that would otherwise be performed by the compiler.

Could this give a hint how to fix this with quarkus/native? Maybe this could help as well: https://github.com/oracle/graal/issues/1367#issuecomment-500517930

gsmet commented 2 years ago

Add a @RegisterForReflection(targets = com.amazonaws.auth.AWS4Signer.class) annotation on any of your application class.

If it fixes your issues, I'll incorporate it too into the extension.

timguy commented 2 years ago

Thank you, this helped.

Now I am one step further. I post it here, tell me when I should open a new issue for that:

Can you add this resources in the quarkus-amazon-alexa configuration: "com/amazonaws/partitions/endpoints.json"?


2022-09-14 18:37:19,544 INFO  [io.quarkus] (main) theskill 1.0.0-SNAPSHOT native (powered by Quarkus 2.12.1.Final) started in 0.013s. 
2022-09-14 18:37:19,548 INFO  [io.quarkus] (main) Profile prod activated. 
2022-09-14 18:37:19,548 INFO  [io.quarkus] (main) Installed features: [amazon-alexa, amazon-lambda, cdi]
START RequestId: 1db76a46-f68a-4654-9db4-ae228d3fce6f Version: $LATEST
2022-09-14 18:37:19,565 ERROR [io.qua.ama.lam.run.AbstractLambdaPollLoop] (Lambda Thread (NORMAL)) Failed to run lambda (NORMAL): com.amazonaws.SdkClientException: Unable to load partition metadata from com/amazonaws/partitions/endpoints.json
at com.amazonaws.partitions.PartitionsLoader.build(PartitionsLoader.java:82)
at com.amazonaws.regions.RegionMetadataFactory.create(RegionMetadataFactory.java:30)
at com.amazonaws.regions.RegionUtils.initialize(RegionUtils.java:64)
at com.amazonaws.regions.RegionUtils.getRegionMetadata(RegionUtils.java:52)
at com.amazonaws.regions.RegionUtils.getRegion(RegionUtils.java:105)
at com.amazonaws.client.builder.AwsClientBuilder.getRegionObject(AwsClientBuilder.java:254)
at com.amazonaws.client.builder.AwsClientBuilder.setRegion(AwsClientBuilder.java:434)
at com.amazonaws.client.builder.AwsClientBuilder.configureMutableProperties(AwsClientBuilder.java:402)
at com.amazonaws.client.builder.AwsSyncClientBuilder.build(AwsSyncClientBuilder.java:46)
at com.amazon.ask.attributes.persistence.impl.DynamoDbPersistenceAdapter.<init>(DynamoDbPersistenceAdapter.java:114)
at com.amazon.ask.attributes.persistence.impl.DynamoDbPersistenceAdapter.<init>(DynamoDbPersistenceAdapter.java:46)
at com.amazon.ask.attributes.persistence.impl.DynamoDbPersistenceAdapter$Builder.build(DynamoDbPersistenceAdapter.java:350)
at com.amazon.ask.module.StandardSdkModule$Builder.build(StandardSdkModule.java:206)
at com.amazon.ask.builder.StandardSkillBuilder.getConfigBuilder(StandardSkillBuilder.java:100)
at com.amazon.ask.builder.StandardSkillBuilder.build(StandardSkillBuilder.java:109)
at github.timguy.theskill.StreamHandler.getSkill(StreamHandler.java:84)
at github.timguy.theskill.StreamHandler.<init>(StreamHandler.java:88)
at github.timguy.theskill.StreamHandler_Bean.create(Unknown Source)
at github.timguy.theskill.StreamHandler_Bean.get(Unknown Source)
at github.timguy.theskill.StreamHandler_Bean.get(Unknown Source)
at io.quarkus.arc.impl.ArcContainerImpl.beanInstanceHandle(ArcContainerImpl.java:468)
at io.quarkus.arc.impl.ArcContainerImpl.beanInstanceHandle(ArcContainerImpl.java:481)
at io.quarkus.arc.impl.ArcContainerImpl$1.get(ArcContainerImpl.java:285)
at io.quarkus.arc.impl.ArcContainerImpl$1.get(ArcContainerImpl.java:282)
at io.quarkus.arc.runtime.BeanContainerImpl$1.create(BeanContainerImpl.java:36)
at io.quarkus.arc.runtime.BeanContainer.instance(BeanContainer.java:19)
at io.quarkus.amazon.lambda.runtime.AmazonLambdaRecorder$1.processRequest(AmazonLambdaRecorder.java:191)
at io.quarkus.amazon.lambda.runtime.AbstractLambdaPollLoop$1.run(AbstractLambdaPollLoop.java:117)
at java.lang.Thread.run(Thread.java:833)
at com.oracle.svm.core.thread.PlatformThreads.threadStartRoutine(PlatformThreads.java:705)
at com.oracle.svm.core.posix.thread.PosixPlatformThreads.pthreadStartRoutine(PosixPlatformThreads.java:202)
END RequestId: 1db76a46-f68a-4654-9db4-ae228d3fce6f
REPORT RequestId: 1db76a46-f68a-4654-9db4-ae228d3fce6f  Duration: 35.64 ms  Billed Duration: 60 ms  Memory Size: 128 MB Max Memory Used: 17 MB  Init Duration: 23.96 ms 
gsmet commented 2 years ago

OK, let's make progress in a PR and I will release once we get something working.

gsmet commented 2 years ago

1.0.5 is now available on Maven Central. Thanks for your patience and your perseverance :).