简体   繁体   English

无法在使用 MacOS Catalina 的 AWS Lambda function 中原生调用 Quarkus 函数

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

I followed the https://quarkus.io/guides/amazon-lambda tutorial to run my Quarkus application in a Lambda function with AWS.我按照https://quarkus.io/guides/amazon-lambda教程使用 AWS 在 Lambda function 中运行我的 Quarkus 应用程序。

Until the following command, everything works fine, I can invoke my Lambda function in AWS successfuly:在执行以下命令之前,一切正常,我可以在 AWS 中成功调用我的 Lambda function:

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:当我尝试在本机创建我的 Lambda function 时,它也成功运行,如以下日志所示:

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:我的 function 在 AWS 中,但当我尝试调用它时,出现以下错误:

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我的Mac电脑版本如下: MacOS Catalina 10.15.6

Any idea of what can be done to solve this problem?知道可以做些什么来解决这个问题吗?

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 filepom文件中将 Quarkus 版本更新为 1.8.2.Final
  • Since I am using Mac, it's necessary to use the following command: mvn clean install -Dnative -Dquarkus.native.container-build=true由于我使用的是 Mac,因此有必要使用以下命令: 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.另一个需要提及的重点是,在我使用的1.7.3.Final之前的版本中,命令mvn clean install -Dnative -Dquarkus.native.container-build=true不起作用,这使得故障排除变得更加困难这个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM