使用 DynamoDB 和 Graal 自定义运行时的 Micronaut 无服务器应用程序抛出无法构造 com.amazonaws.partitions.model.Partitions 的实例

Posted

技术标签:

【中文标题】使用 DynamoDB 和 Graal 自定义运行时的 Micronaut 无服务器应用程序抛出无法构造 com.amazonaws.partitions.model.Partitions 的实例【英文标题】:Micronaut serverless application using DynamoDB and Graal custom runtime throws Cannot construct instance of com.amazonaws.partitions.model.Partitions 【发布时间】:2019-07-22 16:46:06 【问题描述】:

此处提供示例项目: https://github.com/codependent/micronaut-aws-lambda-proxy-graal

我在 Amazon AWS 上部署了一个 Micronaut 应用程序作为 Lambda 函数。它被编译成 GraalVM 原生镜像并使用 AWS Lambda Custom Runtime 运行。

如果应用程序不使用 DynamoDB,它会顺利运行。当配置它并作为一个普通的 Java 应用程序启动时,它也可以正常工作。但是,当将其用作在 AWS 上运行的 Graal 本机映像时,它会失败并显示:

io.micronaut.context.exceptions.BeanInstantiationException:错误 实例化类型的bean [com.amazonaws.services.dynamodbv2.document.DynamoDB] 消息:无法 从加载分区元数据 com/amazonaws/partitions/endpoints.json

我正在使用这个依赖:compile 'com.amazonaws:aws-java-sdk-dynamodb:1.11.504'

如何解决无法加载分区元数据错误?

完整日志:

Caused by: 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:256)
at com.amazonaws.client.builder.AwsClientBuilder.withRegion(AwsClientBuilder.java:245)
at com.amazonaws.client.builder.AwsClientBuilder.withRegion(AwsClientBuilder.java:232)
at com.codependent.micronaut.awslambda.configuration.DynamoDbConfiguration.dynamoDbClient(DynamoDbConfiguration.kt:18)
at com.codependent.micronaut.awslambda.configuration.$DynamoDbConfiguration$DynamoDbClientDefinition.build(Unknown Source)
at io.micronaut.context.DefaultBeanContext.doCreateBean(DefaultBeanContext.java:1385)

更新:

我错过了以下嵌套的异常原因:Caused by: com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of com.amazonaws.partitions.model.Partitions (no Creators, like default construct, exist): cannot deserialize from Object value (no delegate- or property-based Creator)

这是完整的堆栈跟踪:

START RequestId: c5998c1d-490b-4794-814e-82afbeb70fea Version: $LATEST
[36m23:10:58.905[0;39m [1;30m[main][0;39m [1;31mERROR[0;39m [35mi.m.f.a.p.AbstractLambdaContainerHandler[0;39m - Error while handling request
io.micronaut.context.exceptions.BeanInstantiationException: Error instantiating bean of type [com.amazonaws.services.dynamodbv2.document.DynamoDB]

Message: Error while loading partitions file from com/amazonaws/partitions/endpoints.json
Path Taken: new WarmUpController([PingService pingService]) --> new PingService([PingRepository pingRepository]) --> new PingRepository(Environment environment,[DynamoDB dynamoDb],DynamoDBMapper dynamoDbMapper) --> DynamoDB.dynamoDb([AmazonDynamoDB dynamoDbClient])
at io.micronaut.context.DefaultBeanContext.doCreateBean(DefaultBeanContext.java:1399)
at io.micronaut.context.DefaultBeanContext.createAndRegisterSingleton(DefaultBeanContext.java:1972)
at io.micronaut.context.DefaultBeanContext.getBeanForDefinition(DefaultBeanContext.java:1693)
at io.micronaut.context.DefaultBeanContext.getBeanInternal(DefaultBeanContext.java:1673)
at io.micronaut.context.DefaultBeanContext.getBean(DefaultBeanContext.java:941)
at io.micronaut.context.AbstractBeanDefinition.getBeanForConstructorArgument(AbstractBeanDefinition.java:981)
at com.codependent.micronaut.awslambda.configuration.$DynamoDbConfiguration$DynamoDbDefinition.build(Unknown Source)
at io.micronaut.context.DefaultBeanContext.doCreateBean(DefaultBeanContext.java:1385)
at io.micronaut.context.DefaultBeanContext.createAndRegisterSingleton(DefaultBeanContext.java:1972)
at io.micronaut.context.DefaultBeanContext.getBeanForDefinition(DefaultBeanContext.java:1693)
at io.micronaut.context.DefaultBeanContext.getBeanInternal(DefaultBeanContext.java:1673)
at io.micronaut.context.DefaultBeanContext.getBean(DefaultBeanContext.java:941)
at io.micronaut.context.AbstractBeanDefinition.getBeanForConstructorArgument(AbstractBeanDefinition.java:981)
at com.codependent.micronaut.awslambda.repository.$PingRepositoryDefinition.build(Unknown Source)
at io.micronaut.context.DefaultBeanContext.doCreateBean(DefaultBeanContext.java:1385)
at io.micronaut.context.DefaultBeanContext.createAndRegisterSingleton(DefaultBeanContext.java:1972)
at io.micronaut.context.DefaultBeanContext.getBeanForDefinition(DefaultBeanContext.java:1693)
at io.micronaut.context.DefaultBeanContext.getBeanInternal(DefaultBeanContext.java:1673)
at io.micronaut.context.DefaultBeanContext.getBean(DefaultBeanContext.java:941)
at io.micronaut.context.AbstractBeanDefinition.getBeanForConstructorArgument(AbstractBeanDefinition.java:981)
at com.codependent.micronaut.awslambda.service.$PingServiceDefinition.build(Unknown Source)
at io.micronaut.context.DefaultBeanContext.doCreateBean(DefaultBeanContext.java:1385)
at io.micronaut.context.DefaultBeanContext.createAndRegisterSingleton(DefaultBeanContext.java:1972)
at io.micronaut.context.DefaultBeanContext.getBeanForDefinition(DefaultBeanContext.java:1693)
at io.micronaut.context.DefaultBeanContext.getBeanInternal(DefaultBeanContext.java:1673)
at io.micronaut.context.DefaultBeanContext.getBean(DefaultBeanContext.java:941)
at io.micronaut.context.AbstractBeanDefinition.getBeanForConstructorArgument(AbstractBeanDefinition.java:981)
at com.codependent.micronaut.awslambda.web.$WarmUpControllerDefinition.build(Unknown Source)
at io.micronaut.context.DefaultBeanContext.doCreateBean(DefaultBeanContext.java:1385)
at io.micronaut.context.DefaultBeanContext.createAndRegisterSingleton(DefaultBeanContext.java:1972)
at io.micronaut.context.DefaultBeanContext.getBeanForDefinition(DefaultBeanContext.java:1693)
at io.micronaut.context.DefaultBeanContext.getBeanInternal(DefaultBeanContext.java:1673)
at io.micronaut.context.DefaultBeanContext.getBean(DefaultBeanContext.java:550)
at io.micronaut.context.DefaultBeanContext$BeanExecutionHandle.getTarget(DefaultBeanContext.java:2522)
at io.micronaut.context.DefaultBeanContext$BeanExecutionHandle.invoke(DefaultBeanContext.java:2543)
at io.micronaut.web.router.AbstractRouteMatch.execute(AbstractRouteMatch.java:236)
at io.micronaut.web.router.RouteMatch.execute(RouteMatch.java:122)
at io.micronaut.function.aws.proxy.MicronautLambdaContainerHandler.lambda$null$1(MicronautLambdaContainerHandler.java:240)
at io.reactivex.internal.operators.flowable.FlowableDefer.subscribeActual(FlowableDefer.java:35)
at io.reactivex.Flowable.subscribe(Flowable.java:14805)
at io.reactivex.Flowable.subscribe(Flowable.java:14752)
at io.micronaut.reactive.rxjava2.RxInstrumentedFlowable.subscribeActual(RxInstrumentedFlowable.java:68)
at io.reactivex.Flowable.subscribe(Flowable.java:14805)
at io.reactivex.Flowable.subscribe(Flowable.java:14752)
at io.reactivex.internal.operators.flowable.FlowableSubscribeOn$SubscribeOnSubscriber.run(FlowableSubscribeOn.java:82)
at io.micronaut.http.context.ServerRequestContext.with(ServerRequestContext.java:52)
at io.micronaut.http.context.ServerRequestContext.lambda$instrument$0(ServerRequestContext.java:68)
at io.reactivex.internal.schedulers.ExecutorScheduler$ExecutorWorker$BooleanRunnable.run(ExecutorScheduler.java:288)
at io.reactivex.internal.schedulers.ExecutorScheduler$ExecutorWorker.run(ExecutorScheduler.java:253)
at io.micronaut.http.context.ServerRequestContext.with(ServerRequestContext.java:52)
at io.micronaut.http.context.ServerRequestContext.lambda$instrument$0(ServerRequestContext.java:68)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at io.micronaut.http.context.ServerRequestContext.with(ServerRequestContext.java:52)
at io.micronaut.http.context.ServerRequestContext.lambda$instrument$0(ServerRequestContext.java:68)
at java.lang.Thread.run(Thread.java:748)
at com.oracle.svm.core.thread.JavaThreads.threadStartRoutine(JavaThreads.java:481)
at com.oracle.svm.core.posix.thread.PosixJavaThreads.pthreadStartRoutine(PosixJavaThreads.java:193)
Caused by: com.amazonaws.SdkClientException: Error while loading partitions file from com/amazonaws/partitions/endpoints.json
at com.amazonaws.partitions.PartitionsLoader.loadPartitionFromStream(PartitionsLoader.java:95)
at com.amazonaws.partitions.PartitionsLoader.build(PartitionsLoader.java:84)
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:256)
at com.amazonaws.client.builder.AwsClientBuilder.withRegion(AwsClientBuilder.java:245)
at com.amazonaws.client.builder.AwsClientBuilder.withRegion(AwsClientBuilder.java:232)
at com.codependent.micronaut.awslambda.configuration.DynamoDbConfiguration.dynamoDbClient(DynamoDbConfiguration.kt:18)
at com.codependent.micronaut.awslambda.configuration.$DynamoDbConfiguration$DynamoDbClientDefinition.build(Unknown Source)
at io.micronaut.context.DefaultBeanContext.doCreateBean(DefaultBeanContext.java:1385)
... 57 common frames omitted
Caused by: com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of `com.amazonaws.partitions.model.Partitions` (no Creators, like default construct, exist): cannot deserialize from Object value (no delegate- or property-based Creator)
at [Source: (ByteArrayInputStream); line: 2, column: 3]
at com.fasterxml.jackson.databind.DeserializationContext.reportBadDefinition(DeserializationContext.java:1452)
at com.fasterxml.jackson.databind.DeserializationContext.handleMissingInstantiator(DeserializationContext.java:1028)
at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.deserializeFromObjectUsingNonDefault(BeanDeserializerBase.java:1297)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:326)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:159)
at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:4013)
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3070)
at com.amazonaws.partitions.PartitionsLoader.loadPartitionFromStream(PartitionsLoader.java:92)
... 68 common frames omitted
[36m23:10:58.905[0;39m [1;30m[main][0;39m [1;31mERROR[0;39m [35mc.a.s.proxy.AwsProxyExceptionHandler[0;39m - Called exception handler for:
io.micronaut.context.exceptions.BeanInstantiationException: Error instantiating bean of type [com.amazonaws.services.dynamodbv2.document.DynamoDB]

Message: Error while loading partitions file from com/amazonaws/partitions/endpoints.json
Path Taken: new WarmUpController([PingService pingService]) --> new PingService([PingRepository pingRepository]) --> new PingRepository(Environment environment,[DynamoDB dynamoDb],DynamoDBMapper dynamoDbMapper) --> DynamoDB.dynamoDb([AmazonDynamoDB dynamoDbClient])
at io.micronaut.context.DefaultBeanContext.doCreateBean(DefaultBeanContext.java:1399)
at io.micronaut.context.DefaultBeanContext.createAndRegisterSingleton(DefaultBeanContext.java:1972)
at io.micronaut.context.DefaultBeanContext.getBeanForDefinition(DefaultBeanContext.java:1693)
at io.micronaut.context.DefaultBeanContext.getBeanInternal(DefaultBeanContext.java:1673)
at io.micronaut.context.DefaultBeanContext.getBean(DefaultBeanContext.java:941)
at io.micronaut.context.AbstractBeanDefinition.getBeanForConstructorArgument(AbstractBeanDefinition.java:981)
at com.codependent.micronaut.awslambda.configuration.$DynamoDbConfiguration$DynamoDbDefinition.build(Unknown Source)
at io.micronaut.context.DefaultBeanContext.doCreateBean(DefaultBeanContext.java:1385)
at io.micronaut.context.DefaultBeanContext.createAndRegisterSingleton(DefaultBeanContext.java:1972)
at io.micronaut.context.DefaultBeanContext.getBeanForDefinition(DefaultBeanContext.java:1693)
at io.micronaut.context.DefaultBeanContext.getBeanInternal(DefaultBeanContext.java:1673)
at io.micronaut.context.DefaultBeanContext.getBean(DefaultBeanContext.java:941)
at io.micronaut.context.AbstractBeanDefinition.getBeanForConstructorArgument(AbstractBeanDefinition.java:981)
at com.codependent.micronaut.awslambda.repository.$PingRepositoryDefinition.build(Unknown Source)
at io.micronaut.context.DefaultBeanContext.doCreateBean(DefaultBeanContext.java:1385)
at io.micronaut.context.DefaultBeanContext.createAndRegisterSingleton(DefaultBeanContext.java:1972)
at io.micronaut.context.DefaultBeanContext.getBeanForDefinition(DefaultBeanContext.java:1693)
at io.micronaut.context.DefaultBeanContext.getBeanInternal(DefaultBeanContext.java:1673)
at io.micronaut.context.DefaultBeanContext.getBean(DefaultBeanContext.java:941)
at io.micronaut.context.AbstractBeanDefinition.getBeanForConstructorArgument(AbstractBeanDefinition.java:981)
at com.codependent.micronaut.awslambda.service.$PingServiceDefinition.build(Unknown Source)
at io.micronaut.context.DefaultBeanContext.doCreateBean(DefaultBeanContext.java:1385)
at io.micronaut.context.DefaultBeanContext.createAndRegisterSingleton(DefaultBeanContext.java:1972)
at io.micronaut.context.DefaultBeanContext.getBeanForDefinition(DefaultBeanContext.java:1693)
at io.micronaut.context.DefaultBeanContext.getBeanInternal(DefaultBeanContext.java:1673)
at io.micronaut.context.DefaultBeanContext.getBean(DefaultBeanContext.java:941)
at io.micronaut.context.AbstractBeanDefinition.getBeanForConstructorArgument(AbstractBeanDefinition.java:981)
at com.codependent.micronaut.awslambda.web.$WarmUpControllerDefinition.build(Unknown Source)
at io.micronaut.context.DefaultBeanContext.doCreateBean(DefaultBeanContext.java:1385)
at io.micronaut.context.DefaultBeanContext.createAndRegisterSingleton(DefaultBeanContext.java:1972)
at io.micronaut.context.DefaultBeanContext.getBeanForDefinition(DefaultBeanContext.java:1693)
at io.micronaut.context.DefaultBeanContext.getBeanInternal(DefaultBeanContext.java:1673)
at io.micronaut.context.DefaultBeanContext.getBean(DefaultBeanContext.java:550)
at io.micronaut.context.DefaultBeanContext$BeanExecutionHandle.getTarget(DefaultBeanContext.java:2522)
at io.micronaut.context.DefaultBeanContext$BeanExecutionHandle.invoke(DefaultBeanContext.java:2543)
at io.micronaut.web.router.AbstractRouteMatch.execute(AbstractRouteMatch.java:236)
at io.micronaut.web.router.RouteMatch.execute(RouteMatch.java:122)
at io.micronaut.function.aws.proxy.MicronautLambdaContainerHandler.lambda$null$1(MicronautLambdaContainerHandler.java:240)
at io.reactivex.internal.operators.flowable.FlowableDefer.subscribeActual(FlowableDefer.java:35)
at io.reactivex.Flowable.subscribe(Flowable.java:14805)
at io.reactivex.Flowable.subscribe(Flowable.java:14752)
at io.micronaut.reactive.rxjava2.RxInstrumentedFlowable.subscribeActual(RxInstrumentedFlowable.java:68)
at io.reactivex.Flowable.subscribe(Flowable.java:14805)
at io.reactivex.Flowable.subscribe(Flowable.java:14752)
at io.reactivex.internal.operators.flowable.FlowableSubscribeOn$SubscribeOnSubscriber.run(FlowableSubscribeOn.java:82)
at io.micronaut.http.context.ServerRequestContext.with(ServerRequestContext.java:52)
at io.micronaut.http.context.ServerRequestContext.lambda$instrument$0(ServerRequestContext.java:68)
at io.reactivex.internal.schedulers.ExecutorScheduler$ExecutorWorker$BooleanRunnable.run(ExecutorScheduler.java:288)
at io.reactivex.internal.schedulers.ExecutorScheduler$ExecutorWorker.run(ExecutorScheduler.java:253)
at io.micronaut.http.context.ServerRequestContext.with(ServerRequestContext.java:52)
at io.micronaut.http.context.ServerRequestContext.lambda$instrument$0(ServerRequestContext.java:68)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at io.micronaut.http.context.ServerRequestContext.with(ServerRequestContext.java:52)
at io.micronaut.http.context.ServerRequestContext.lambda$instrument$0(ServerRequestContext.java:68)
at java.lang.Thread.run(Thread.java:748)
at com.oracle.svm.core.thread.JavaThreads.threadStartRoutine(JavaThreads.java:481)
at com.oracle.svm.core.posix.thread.PosixJavaThreads.pthreadStartRoutine(PosixJavaThreads.java:193)
Caused by: com.amazonaws.SdkClientException: Error while loading partitions file from com/amazonaws/partitions/endpoints.json
at com.amazonaws.partitions.PartitionsLoader.loadPartitionFromStream(PartitionsLoader.java:95)
at com.amazonaws.partitions.PartitionsLoader.build(PartitionsLoader.java:84)
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:256)
at com.amazonaws.client.builder.AwsClientBuilder.withRegion(AwsClientBuilder.java:245)
at com.amazonaws.client.builder.AwsClientBuilder.withRegion(AwsClientBuilder.java:232)
at com.codependent.micronaut.awslambda.configuration.DynamoDbConfiguration.dynamoDbClient(DynamoDbConfiguration.kt:18)
at com.codependent.micronaut.awslambda.configuration.$DynamoDbConfiguration$DynamoDbClientDefinition.build(Unknown Source)
at io.micronaut.context.DefaultBeanContext.doCreateBean(DefaultBeanContext.java:1385)
... 57 common frames omitted
Caused by: com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of `com.amazonaws.partitions.model.Partitions` (no Creators, like default construct, exist): cannot deserialize from Object value (no delegate- or property-based Creator)
at [Source: (ByteArrayInputStream); line: 2, column: 3]
at com.fasterxml.jackson.databind.DeserializationContext.reportBadDefinition(DeserializationContext.java:1452)
at com.fasterxml.jackson.databind.DeserializationContext.handleMissingInstantiator(DeserializationContext.java:1028)
at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.deserializeFromObjectUsingNonDefault(BeanDeserializerBase.java:1297)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:326)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:159)
at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:4013)
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3070)
at com.amazonaws.partitions.PartitionsLoader.loadPartitionFromStream(PartitionsLoader.java:92)
... 68 common frames omitted
io.micronaut.context.exceptions.BeanInstantiationException: Error instantiating bean of type [com.amazonaws.services.dynamodbv2.document.DynamoDB]

Message: Error while loading partitions file from com/amazonaws/partitions/endpoints.json
Path Taken: new WarmUpController([PingService pingService]) --> new PingService([PingRepository pingRepository]) --> new PingRepository(Environment environment,[DynamoDB dynamoDb],DynamoDBMapper dynamoDbMapper) --> DynamoDB.dynamoDb([AmazonDynamoDB dynamoDbClient])
at io.micronaut.context.DefaultBeanContext.doCreateBean(DefaultBeanContext.java:1399)
at io.micronaut.context.DefaultBeanContext.createAndRegisterSingleton(DefaultBeanContext.java:1972)
at io.micronaut.context.DefaultBeanContext.getBeanForDefinition(DefaultBeanContext.java:1693)
at io.micronaut.context.DefaultBeanContext.getBeanInternal(DefaultBeanContext.java:1673)
at io.micronaut.context.DefaultBeanContext.getBean(DefaultBeanContext.java:941)
at io.micronaut.context.AbstractBeanDefinition.getBeanForConstructorArgument(AbstractBeanDefinition.java:981)
at com.codependent.micronaut.awslambda.configuration.$DynamoDbConfiguration$DynamoDbDefinition.build(Unknown Source)
at io.micronaut.context.DefaultBeanContext.doCreateBean(DefaultBeanContext.java:1385)
at io.micronaut.context.DefaultBeanContext.createAndRegisterSingleton(DefaultBeanContext.java:1972)
at io.micronaut.context.DefaultBeanContext.getBeanForDefinition(DefaultBeanContext.java:1693)
at io.micronaut.context.DefaultBeanContext.getBeanInternal(DefaultBeanContext.java:1673)
at io.micronaut.context.DefaultBeanContext.getBean(DefaultBeanContext.java:941)
at io.micronaut.context.AbstractBeanDefinition.getBeanForConstructorArgument(AbstractBeanDefinition.java:981)
at com.codependent.micronaut.awslambda.repository.$PingRepositoryDefinition.build(Unknown Source)
at io.micronaut.context.DefaultBeanContext.doCreateBean(DefaultBeanContext.java:1385)
at io.micronaut.context.DefaultBeanContext.createAndRegisterSingleton(DefaultBeanContext.java:1972)
at io.micronaut.context.DefaultBeanContext.getBeanForDefinition(DefaultBeanContext.java:1693)
at io.micronaut.context.DefaultBeanContext.getBeanInternal(DefaultBeanContext.java:1673)
at io.micronaut.context.DefaultBeanContext.getBean(DefaultBeanContext.java:941)
at io.micronaut.context.AbstractBeanDefinition.getBeanForConstructorArgument(AbstractBeanDefinition.java:981)
at com.codependent.micronaut.awslambda.service.$PingServiceDefinition.build(Unknown Source)
at io.micronaut.context.DefaultBeanContext.doCreateBean(DefaultBeanContext.java:1385)
at io.micronaut.context.DefaultBeanContext.createAndRegisterSingleton(DefaultBeanContext.java:1972)
at io.micronaut.context.DefaultBeanContext.getBeanForDefinition(DefaultBeanContext.java:1693)
at io.micronaut.context.DefaultBeanContext.getBeanInternal(DefaultBeanContext.java:1673)
at io.micronaut.context.DefaultBeanContext.getBean(DefaultBeanContext.java:941)
at io.micronaut.context.AbstractBeanDefinition.getBeanForConstructorArgument(AbstractBeanDefinition.java:981)
at com.codependent.micronaut.awslambda.web.$WarmUpControllerDefinition.build(Unknown Source)
at io.micronaut.context.DefaultBeanContext.doCreateBean(DefaultBeanContext.java:1385)
at io.micronaut.context.DefaultBeanContext.createAndRegisterSingleton(DefaultBeanContext.java:1972)
at io.micronaut.context.DefaultBeanContext.getBeanForDefinition(DefaultBeanContext.java:1693)
at io.micronaut.context.DefaultBeanContext.getBeanInternal(DefaultBeanContext.java:1673)
at io.micronaut.context.DefaultBeanContext.getBean(DefaultBeanContext.java:550)
at io.micronaut.context.DefaultBeanContext$BeanExecutionHandle.getTarget(DefaultBeanContext.java:2522)
at io.micronaut.context.DefaultBeanContext$BeanExecutionHandle.invoke(DefaultBeanContext.java:2543)
at io.micronaut.web.router.AbstractRouteMatch.execute(AbstractRouteMatch.java:236)
at io.micronaut.web.router.RouteMatch.execute(RouteMatch.java:122)
at io.micronaut.function.aws.proxy.MicronautLambdaContainerHandler.lambda$null$1(MicronautLambdaContainerHandler.java:240)
at io.reactivex.internal.operators.flowable.FlowableDefer.subscribeActual(FlowableDefer.java:35)
at io.reactivex.Flowable.subscribe(Flowable.java:14805)
at io.reactivex.Flowable.subscribe(Flowable.java:14752)
at io.micronaut.reactive.rxjava2.RxInstrumentedFlowable.subscribeActual(RxInstrumentedFlowable.java:68)
at io.reactivex.Flowable.subscribe(Flowable.java:14805)
at io.reactivex.Flowable.subscribe(Flowable.java:14752)
at io.reactivex.internal.operators.flowable.FlowableSubscribeOn$SubscribeOnSubscriber.run(FlowableSubscribeOn.java:82)
at io.micronaut.http.context.ServerRequestContext.with(ServerRequestContext.java:52)
at io.micronaut.http.context.ServerRequestContext.lambda$instrument$0(ServerRequestContext.java:68)
at io.reactivex.internal.schedulers.ExecutorScheduler$ExecutorWorker$BooleanRunnable.run(ExecutorScheduler.java:288)
at io.reactivex.internal.schedulers.ExecutorScheduler$ExecutorWorker.run(ExecutorScheduler.java:253)
at io.micronaut.http.context.ServerRequestContext.with(ServerRequestContext.java:52)
at io.micronaut.http.context.ServerRequestContext.lambda$instrument$0(ServerRequestContext.java:68)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at io.micronaut.http.context.ServerRequestContext.with(ServerRequestContext.java:52)
at io.micronaut.http.context.ServerRequestContext.lambda$instrument$0(ServerRequestContext.java:68)
at java.lang.Thread.run(Thread.java:748)
at com.oracle.svm.core.thread.JavaThreads.threadStartRoutine(JavaThreads.java:481)
at com.oracle.svm.core.posix.thread.PosixJavaThreads.pthreadStartRoutine(PosixJavaThreads.java:193)
Caused by: com.amazonaws.SdkClientException: Error while loading partitions file from com/amazonaws/partitions/endpoints.json
at com.amazonaws.partitions.PartitionsLoader.loadPartitionFromStream(PartitionsLoader.java:95)
at com.amazonaws.partitions.PartitionsLoader.build(PartitionsLoader.java:84)
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:256)
at com.amazonaws.client.builder.AwsClientBuilder.withRegion(AwsClientBuilder.java:245)
at com.amazonaws.client.builder.AwsClientBuilder.withRegion(AwsClientBuilder.java:232)
at com.codependent.micronaut.awslambda.configuration.DynamoDbConfiguration.dynamoDbClient(DynamoDbConfiguration.kt:18)
at com.codependent.micronaut.awslambda.configuration.$DynamoDbConfiguration$DynamoDbClientDefinition.build(Unknown Source)
at io.micronaut.context.DefaultBeanContext.doCreateBean(DefaultBeanContext.java:1385)
... 57 more
Caused by: com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of `com.amazonaws.partitions.model.Partitions` (no Creators, like default construct, exist): cannot deserialize from Object value (no delegate- or property-based Creator)
at [Source: (ByteArrayInputStream); line: 2, column: 3]
at com.fasterxml.jackson.databind.DeserializationContext.reportBadDefinition(DeserializationContext.java:1452)
at com.fasterxml.jackson.databind.DeserializationContext.handleMissingInstantiator(DeserializationContext.java:1028)
at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.deserializeFromObjectUsingNonDefault(BeanDeserializerBase.java:1297)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:326)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:159)
at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:4013)
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3070)
at com.amazonaws.partitions.PartitionsLoader.loadPartitionFromStream(PartitionsLoader.java:92)
... 68 more
END RequestId: c5998c1d-490b-4794-814e-82afbeb70fea
REPORT RequestId: c5998c1d-490b-4794-814e-82afbeb70fea Duration: 107.89 ms Billed Duration: 200 ms Memory Size: 128 MB Max Memory Used: 59 MB 

更新 2:

我也尝试在 reflect.json 中为 Partitions 类添加一个条目:

...
, 
  "name" : "com.amazonaws.partitions.model.Partitions",
  "allPublicMethods" : true,
  "allDeclaredConstructors" : true
]

【问题讨论】:

【参考方案1】:

如果可以,您应该升级到 AWS SDK v2。升级后的库解决了大部分问题,您几乎不需要进行任何配置即可使其工作。

几乎让 AWS SDK v1 可以工作,然后我意识到我使用了错误的依赖项。

在我的 build.gradle 依赖块中,我放了这些,它开箱即用:

   implementation platform("software.amazon.awssdk:bom:2.17.+")
   implementation "io.micronaut.aws:micronaut-aws-sdk-v2:3.0.+"
   implementation "software.amazon.awssdk:lambda"

【讨论】:

【参考方案2】:

感谢from this Graal Github issue的指示,终于解决了。

总结:

    -H:IncludeResources="logback.xml|application.yml|com/amazonaws/partitions/endpoints.json".

    在 reflect.json 中添加这些条目:

反射.json:

 , 
  "name" : "com.amazonaws.partitions.model.Partitions",
  "allPublicMethods" : true,
  "allDeclaredConstructors" : true
, 
  "name" : "com.amazonaws.partitions.model.Partition",
  "allPublicMethods" : true,
  "allDeclaredConstructors" : true
, 
  "name" : "com.amazonaws.partitions.model.Endpoint",
  "allPublicMethods" : true,
  "allDeclaredConstructors" : true
, 
  "name" : "com.amazonaws.partitions.model.Region",
  "allPublicMethods" : true,
  "allDeclaredConstructors" : true
, 
  "name" : "com.amazonaws.partitions.model.Service",
  "allPublicMethods" : true,
  "allDeclaredConstructors" : true
, 
  "name" : "com.amazonaws.partitions.model.CredentialScope",
  "allPublicMethods" : true,
  "allDeclaredConstructors" : true
, 
  "name" : "java.util.HashSet",
  "allPublicMethods" : true,
  "allDeclaredConstructors" : true

【讨论】:

【参考方案3】:

静态资源不会自动包含在本机映像中。您可能必须修改本机图像命令以包含 com/amazonaws/partitions/endpoints.json-H:IncludeResources

【讨论】:

嗨 Graeme,我已经添加了该资源 (-H:IncludeResources="logback.xml|application.yml|com/amazonaws/partitions/endpoints.json"),但仍然出现错误。我已经用异常的更多细节更新了这个问题。

以上是关于使用 DynamoDB 和 Graal 自定义运行时的 Micronaut 无服务器应用程序抛出无法构造 com.amazonaws.partitions.model.Partitions 的实例的主要内容,如果未能解决你的问题,请参考以下文章

具有“自定义类型”属性的DynamoDB表的Graphql Mutation查询

「译」Graal JIT编译器是如何工作的

「译」Graal JIT编译器是如何工作的

深入浅出Java 10的实验性JIT编译器Graal

如何在 AppSync GraphQL 架构中使用自定义输入类型?

如何在运行时从 DynamoDB 获取排序结果