无法在MacOS Catalina上本地调用AWS Lambda函数中的Quarkus函数。

huangapple go评论77阅读模式
英文:

Unable to Invoke Quarkus Functions Natively in an AWS Lambda function with MacOS Catalina

问题

我按照 https://quarkus.io/guides/amazon-lambda 教程,在 AWS 中运行我的 Quarkus 应用程序作为 Lambda 函数。

在以下命令之前,一切都正常,我可以成功地在 AWS 中调用我的 Lambda 函数:

    sh target/manage.sh invoke

但是,当我尝试使用以下命令本地安装代码时:

    mvn clean install -Pnative -Dnative-image.docker-build=true

我遇到了以下错误:

    [ERROR] Failed to execute goal io.quarkus:quarkus-maven-plugin:1.7.3.Final:native-image (default) on project quarkus-lambda: Failed to generate native image: io.quarkus.builder.BuildException: Build failure: Build failed due to errors
    ...

我还尝试了以下命令,这个命令也可以正常工作:

    mvn package -Pnative

当我运行上述命令时,这是最终的日志:

    ...
    [INFO] BUILD SUCCESS
    ...

当我尝试本地创建 Lambda 函数时,如下日志所示,也成功运行:

    target/manage.sh native create
    ...

但是,当我尝试调用 Lambda 函数时,出现以下错误:

    target/manage.sh invoke       
    ...
    An error occurred (ResourceNotFoundException) when calling the Invoke operation: Function not found: arn:aws:lambda:eu-west-1:661273428467:function:QuarkusLambda

我已配置以下变量:

    GRAALVM_HOME=/Library/Java/JavaVirtualMachines/graalvm-ce-java11-20.2.0/Contents/Home
    JAVA_HOME=/Users/rafadelnero/.jenv/versions/graalvm64-11.0.8

我的 Mac 计算机版本如下:
**MacOS Catalina 10.15.6**

有什么办法可以解决这个问题吗?
英文:

I followed the https://quarkus.io/guides/amazon-lambda tutorial to run my Quarkus application in a Lambda function with AWS.

Until the following command, everything works fine, I can invoke my Lambda function in AWS successfuly:

sh target/manage.sh invoke

But when I try to install the code natively by using the following command:

mvn clean install -Pnative -Dnative-image.docker-build=true

I get the following error:

[ERROR] Failed to execute goal io.quarkus:quarkus-maven-plugin:1.7.3.Final:native-image (default) on project quarkus-lambda: Failed to generate native image: io.quarkus.builder.BuildException: Build failure: Build failed due to errors
[ERROR]         [error]: Build step io.quarkus.deployment.pkg.steps.NativeImageBuildStep#build threw an exception: java.lang.RuntimeException: Failed to build native image
[ERROR]         at io.quarkus.deployment.pkg.steps.NativeImageBuildStep.build(NativeImageBuildStep.java:389)
[ERROR]         at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[ERROR]         at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
[ERROR]         at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[ERROR]         at java.base/java.lang.reflect.Method.invoke(Method.java:566)
[ERROR]         at io.quarkus.deployment.ExtensionLoader$2.execute(ExtensionLoader.java:932)
[ERROR]         at io.quarkus.builder.BuildContext.run(BuildContext.java:277)
[ERROR]         at org.jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35)
[ERROR]         at org.jboss.threads.EnhancedQueueExecutor.safeRun(EnhancedQueueExecutor.java:2046)
[ERROR]         at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.doRunTask(EnhancedQueueExecutor.java:1578)
[ERROR]         at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1452)
[ERROR]         at java.base/java.lang.Thread.run(Thread.java:834)
[ERROR]         at org.jboss.threads.JBossThread.run(JBossThread.java:479)
[ERROR] Caused by: java.lang.RuntimeException: Image generation failed. Exit code: 125
[ERROR]         at io.quarkus.deployment.pkg.steps.NativeImageBuildStep.imageGenerationFailed(NativeImageBuildStep.java:491)
[ERROR]         at io.quarkus.deployment.pkg.steps.NativeImageBuildStep.build(NativeImageBuildStep.java:367)
[ERROR]         ... 12 more
[ERROR] -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.

What I also tried is the following command and this one works fine:

mvn package -Pnative

This is the final log when I run the above command:

[quarkus-lambda-1.0-SNAPSHOT-runner:10879]    (compile):  15,386.61 ms,  3.51 GB
[quarkus-lambda-1.0-SNAPSHOT-runner:10879]      compile:  26,031.26 ms,  3.51 GB
[quarkus-lambda-1.0-SNAPSHOT-runner:10879]        image:   2,312.47 ms,  3.51 GB
[quarkus-lambda-1.0-SNAPSHOT-runner:10879]        write:     765.22 ms,  3.51 GB
[quarkus-lambda-1.0-SNAPSHOT-runner:10879]      [total]:  60,426.97 ms,  3.51 GB
[INFO] [io.quarkus.deployment.QuarkusAugmentor] Quarkus augmentation completed in 63483ms
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  01:10 min
[INFO] Finished at: 2020-09-21T08:47:39+01:00
[INFO] ------------------------------------------------------------------------

When I try to create my Lambda function natively it also works successfully as the following log shows:

target/manage.sh native create
Creating function
++ aws lambda create-function --function-name QuarkusLambdaNative --zip-file fileb:///Users/rafadelnero/Desktop/dev/java/work/quarkus-lambda/target/function.zip --handler io.quarkus.amazon.lambda.runtime.QuarkusStreamHandler::handleRequest --runtime provided --role arn:aws:iam::661273428467:role/lambda-role --timeout 15 --memory-size 256 --environment 'Variables={DISABLE_SIGNAL_HANDLERS=true}'
{
    "FunctionName": "QuarkusLambdaNative", 
    "LastModified": "2020-09-21T07:51:40.327+0000", 
    "RevisionId": "f703cd6d-60a7-409a-8c9b-f5ce47719f44", 
    "MemorySize": 256, 
    "Environment": {
        "Variables": {
            "DISABLE_SIGNAL_HANDLERS": "true"
        }
    }, 
    "Version": "$LATEST", 
    "Role": "arn:aws:iam::661273428467:role/lambda-role", 
    "Timeout": 15, 
    "Runtime": "provided", 
    "TracingConfig": {
        "Mode": "PassThrough"
    }, 
    "CodeSha256": "lNXMPlOuQt4id0+W8okeTm+NlHvAUw8f7suQatSOXJ8=", 
    "Description": "", 
    "CodeSize": 8230977, 
    "FunctionArn": "arn:aws:lambda:eu-west-1:661273428467:function:QuarkusLambdaNative", 
    "Handler": "io.quarkus.amazon.lambda.runtime.QuarkusStreamHandler::handleRequest"
}

My function is in AWS but when I try to invoke it, I get the following error:

target/manage.sh invoke       
Invoking function
aws-cli/1.16.96 Python/2.7.16 Darwin/19.6.0 botocore/1.12.86
target/manage.sh: line 29: [: -ge: unary operator expected
++ aws lambda invoke response.txt --function-name QuarkusLambda --payload file://payload.json --log-type Tail --query LogResult --output text
++ base64 --decode

An error occurred (ResourceNotFoundException) when calling the Invoke operation: Function not found: arn:aws:lambda:eu-west-1:661273428467:function:QuarkusLambda
cat: response.txt: No such file or directory

I have the following variables configured:

GRAALVM_HOME=/Library/Java/JavaVirtualMachines/graalvm-ce-java11-20.2.0/Contents/Home
JAVA_HOME=/Users/rafadelnero/.jenv/versions/graalvm64-11.0.8

My Mac computer version is the following:
MacOS Catalina 10.15.6

Any idea of what can be done to solve this problem?

答案1

得分: 2

谢谢,Rowing!你的建议是解决方案的一部分!

为了使其生效,我采取了以下两步:

  • pom文件中将Quarkus版本更新为1.8.2.Final
  • 由于我在使用Mac,需要使用以下命令:
    mvn clean install -Dnative -Dquarkus.native.container-build=true

然后,我按照上面提到的指定步骤进行操作。

另一个重要的要点是,在我之前使用的版本1.7.3.Final中,命令mvn clean install -Dnative -Dquarkus.native.container-build=true无法工作,这使得解决这个问题变得更加困难。

英文:

Thanks, Rowing! Your suggestion was part of the solution!

To make it work, I followed two steps:

  • Updated the Quarkus version to 1.8.2.Final in the pom file
  • Since I am using Mac, it's necessary to use the following command:
    mvn clean install -Dnative -Dquarkus.native.container-build=true

Then I followed the specified steps as mentioned above.

Another important point to mention is that in the version I was using before 1.7.3.Final the command mvn clean install -Dnative -Dquarkus.native.container-build=true wasn't working, this made things a bit more difficult to troubleshoot this problem.

huangapple
  • 本文由 发表于 2020年9月21日 15:57:24
  • 转载请务必保留本文链接:https://go.coder-hub.com/63988221.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定