AWS Lambda Java: Lambda was not able to unzip the file

大城市里の小女人 提交于 2020-01-15 07:06:26

问题


I'm trying to use Java with AWS Lambda. I created a jar file with all dependencies (using maven-assembly-plugin). Upon uploading, I cannot call the lambda. I receive the error Calling the Invoke API failed with message: Lambda was not able to unzip the file. The jar file is 11 MB. I can execute the jar with java -jar


回答1:


maven-assemply-plugin needs to be told to output a zip, not a 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>



回答2:


I ran into this because a JAR packed with the Shade plugin generated both the file and directory META-INF\version\9.

By excluding these files the JAR could be run again. The following is the configuration section for the 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>


来源:https://stackoverflow.com/questions/50910812/aws-lambda-java-lambda-was-not-able-to-unzip-the-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!