gpt4 book ai didi

java - 使用 Micronaut 和 GraalVM 创建 AWS Lambda 函数时出现问题

转载 作者:行者123 更新时间:2023-11-30 05:35:27 25 4
gpt4 key购买 nike

我正在尝试使用 Micronaut、GraalVM 和 Docker 在 Java 中创建和部署 AWS Lambda 函数。我正在关注this tutorial使用 GraalVM 运行时创建 AWS lambda。

我使用 micronaut 命令 $ mn create-app my-app --features aws-api-gateway-graal 创建了 java 项目。然后在不更改代码或配置文件的情况下,尝试使用 GraalVM native 镜像构建 Docker 镜像。在 docker build 的步骤中,当构建 graalvm native 镜像时,我收到以下警告:

Warning: Aborting stand-alone image build. No instances are allowed in the image heap for a class that is initialized or reinitialized at image runtime com.amazonaws.serverless.proxy.model.ContainerConfig. Try marking this class for build-time initialization with --initialize-at-build-time=com.amazonaws.serverless.proxy.model.ContainerConfig

Detailed message:
Trace: field io.micronaut.function.aws.proxy.AbstractLambdaContainerHandler.config

Warning: Use -H:+ReportExceptionStackTraces to print stacktrace of underlying exception*

Warning: Image 'server' is a fallback image that requires a JDK for execution (use --no-fallback to suppress fallback image generation).

构建后,我将带有 Bootstrap 文件的 docker 镜像导出到 function.zip 文件,如教程中所写。然后我将 function.zip 文件上传到我创建的 AWS lambda 函数,当我尝试测试函数时,出现此错误:

{  "errorType": "Runtime.ExitError",
"errorMessage": "RequestId: 888854d7-0e0e-42b4-a138-9a003c3455e1 Error: Runtime exited with error:
exit status 1"
}

START RequestId: 888854d7-0e0e-42b4-a138-9a003c3455e1 Version: $LATEST
Error: No bin/java and no environment variable JAVA_HOME
END RequestId: 888854d7-0e0e-42b4-a138-9a003c3455e1
REPORT RequestId: 888854d7-0e0e-42b4-a138-9a003c3455e1 Duration: 415.09 ms Billed Duration: 500 ms Memory Size: 128 MB Max Memory Used: 16 MB
RequestId: 888854d7-0e0e-42b4-a138-9a003c3455e1 Error: Runtime exited with error: exit status 1
Runtime.ExitError

我不知道出了什么问题。我还没有找到解决这个问题的方法。

最佳答案

此类调用 ContainerConfig 类的静态方法 defaultConfig

io.micronaut.function.aws.proxy.AbstractLambdaContainerHandler
com.amazonaws.serverless.proxy.internal.LambdaContainerHandler

为了解决这个问题,我们需要在运行时而不是编译时初始化这些类。

我对 GraalVM 完全陌生,目前无法解释其原因。

我的native-image配置。

native-image 
--delay-class-initialization-to-runtime=io.micronaut.function.aws.proxy.AbstractLambdaContainerHandler,com.amazonaws.serverless.proxy.internal.LambdaContainerHandler
--no-fallback
--no-server
-cp build/libs/yourJarName.jar

资源: https://medium.com/graalvm/understanding-class-initialization-in-graalvm-native-image-generation-d765b7e4d6ed

关于java - 使用 Micronaut 和 GraalVM 创建 AWS Lambda 函数时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56735749/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com