Maven部署包并上传到AWS-Lambda [英] Maven Deployment package and upload to AWS-Lambda

查看:205
本文介绍了Maven部署包并上传到AWS-Lambda的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在将maven部署包上传到Amazon s3时遇到了问题。

I'm facing issue in uploading the maven deployment package to Amazon s3.

从Eclipse中,我能够成功生成.jar文件,但是我上传到服务器时遇到问题。

From Eclipse, I'm able to generate the .jar file successfully, however I'm facing issue in uploading to server.

这是我的Java代码:

Here is my Java code:

package main.java.mavantestproj;

import java.util.Map;

import com.amazonaws.auth.profile.ProfileCredentialsProvider;
import com.amazonaws.regions.Regions;
import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient;
import com.amazonaws.services.lambda.runtime.Context;

public class LambdaFunctionHandler {


    public String handleRequest(Map<String,Object> input, Context context) {
        context.getLogger().log("Input: " + input);

        AmazonDynamoDBClient client = new AmazonDynamoDBClient(new ProfileCredentialsProvider("mytest"));

        client.setRegion(com.amazonaws.regions.Region.getRegion(Regions.US_WEST_2));

        client.describeTable("ProductCatalog");
        // TODO: implement your handler
        return null;
    }

}

目标文件夹我有2个罐子的。即lambda-java-example-1.0-SNAPSHOT.jar& original-lambda-java-example-1.0-SNAPSHOT.jar

in target folder i have got 2 jar's. ie lambda-java-example-1.0-SNAPSHOT.jar & original-lambda-java-example-1.0-SNAPSHOT.jar

在这第一个jar中是35MB&第二个是4KB。我没有得到哪一个上传到S3来运行我的lambda函数。

In this first jar is 35MB & second one is 4KB. I'm not getting which one to upload to S3 to run my lambda function.

推荐答案

你肯定需要大的 uber-jar 所以您的依赖类将被包含在内,但是有另一种方法可以打包使用Maven 程序集插件而不是 Shade 插件为AWS-Lambda提供支持。最终得到的是.zip格式的AWS lambda部署包,而不是单个.jar文件。它看起来有点像JEE .war文件,其中所有原始.jar依赖项保持不变,并且您可以包含其他内容,例如属性文件,最终在lambda运行的文件系统中解压缩(可能有点更容易找到并加载代码)。如果您对这些细节感兴趣,可以在此处发布一篇博文: http://whirlysworld.blogspot.com/2016/03/aws-lambda-java-deployment-maven-build.html 此外,以这种方式打包Lambda功能应用程序更容易查看zip文件并找出包含哪些依赖项,然后确定您可以排除的那些。

You definitely need the large "uber-jar" so your dependency classes will be included, but there is an alternative way to package things up for AWS-Lambda using the Maven assembly plugin instead of the Shade plugin. You end up with an AWS lambda deployment package in .zip format instead of a single .jar file. It will look a little more like a JEE .war file with all the original .jar dependencies kept intact, and you can include other stuff like properties files that end up unpacked in the file-system where the lambda runs (which may be a little easier to find and load in your code). If you're interested in the details, there's a blog post about it here: http://whirlysworld.blogspot.com/2016/03/aws-lambda-java-deployment-maven-build.html Also, packaging a Lambda function app this way makes it WAY easier to peek into the zip file and figure out which dependency jars are being included, and then identify the ones you might be able to exclude.

这仍然无法获得Maven将处理包的实际部署到AWS(创建或更新)。部署和捕获部署信息(ARN,API网关app-id-url等)似乎是亚马逊未能提供非常明确答案或解决方案的下一步。

This still doesn't get Maven to handle the actual deployment of the package to AWS (create or update). Deploying, and capturing the deployment info (ARN, API-gateway app-id-url, etc.), seems to be the next thing for which Amazon hasn't provided a very clear answer or solution.

这篇关于Maven部署包并上传到AWS-Lambda的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆