【问题标题】:AWS Lambda Java: Lambda was not able to unzip the fileAWS Lambda Java:Lambda 无法解压缩文件
【发布时间】:2023-07-17 02:11:02
【问题描述】:

我正在尝试将 Java 与 AWS Lambda 结合使用。我创建了一个包含所有依赖项的 jar 文件(使用 maven-assembly-plugin)。上传后,我无法调用 lambda。我收到错误Calling the Invoke API failed with message: Lambda was not able to unzip the file。 jar 文件为 11 MB。我可以用java -jar执行jar

【问题讨论】:

    标签: java aws-lambda


    【解决方案1】:

    maven-assemply-plugin 需要被告知输出zip,而不是jar。 (我什至不知道有区别!)

    将此添加到其配置中:

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

    【讨论】:

      【解决方案2】:

      我遇到了这个问题,因为一个包含 Shade 插件的 JAR 生成了文件和目录 META-INF\version\9

      通过排除这些文件,可以再次运行 JAR。以下是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>
      

      【讨论】:

      • 工作得很好
      【解决方案3】:

      遭受同样的问题。

      一般情况下,如果 lambda 函数的 .zip 或 .jar 文件大小在解压后大于 50MB,则会发生此错误

      确保 lambda 函数代码的大小小于 50MB

      【讨论】: