简体   繁体   English

AWS Lambda Java:Lambda 无法解压缩文件

[英]AWS Lambda Java: Lambda was not able to unzip the file

I'm trying to use Java with AWS Lambda.我正在尝试将 Java 与 AWS Lambda 结合使用。 I created a jar file with all dependencies (using maven-assembly-plugin).我创建了一个包含所有依赖项的 jar 文件(使用 maven-assembly-plugin)。 Upon uploading, I cannot call the lambda.上传后,我无法调用 lambda。 I receive the error Calling the Invoke API failed with message: Lambda was not able to unzip the file .我收到错误Calling the Invoke API failed with message: Lambda was not able to unzip the file The jar file is 11 MB. jar 文件为 11 MB。 I can execute the jar with java -jar我可以用java -jar执行 jar

maven-assemply-plugin needs to be told to output a zip , not a jar .需要告诉maven-assemply-plugin输出zip ,而不是jar (I didn't even know there was a difference!) (我什至不知道有区别!)

Add this to its configuration:将此添加到其配置中:

<plugin>
     <groupId>org.apache.maven.plugins</groupId>
     <artifactId>maven-assembly-plugin</artifactId>
     ...
     <configuration>
         ...
         <formats>
            <format>zip</format>
         </formats>
     </configuration>
</plugin>

I ran into this because a JAR packed with the Shade plugin generated both the file and directory META-INF\\version\\9 .我遇到了这个问题,因为一个装有 Shade 插件的 JAR 生成了文件和目录META-INF\\version\\9

By excluding these files the JAR could be run again.通过排除这些文件,JAR 可以再次运行。 The following is the configuration section for the maven-shade-plugin.以下是 maven-shade-plugin 的配置部分。

    <configuration>            
      <filters>
        <filter>
          <artifact>*:*</artifact>
          <excludes>
            <exclude>META-INF/*.SF</exclude>
            <exclude>META-INF/*.DSA</exclude>
            <exclude>META-INF/*.RSA</exclude>
            <exclude>META-INF/versions/9</exclude>
            <exclude>META-INF/versions/9/*</exclude>
          </excludes>
        </filter>
      </filters>
    </configuration>

The suffered from the same issue.遭受同样的问题。

Generally, This error occurred if .zip or .jar file size of a lambda function is more than 50MB after unzipping it通常,如果 lambda 函数的 .zip 或 .jar 文件大小在解压后超过50MB ,则会出现此错误

Make the sure that size of a lambda function code is less than 50MB确保 lambda 函数代码的大小小于50MB

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

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