2
votes

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

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

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;
    }

}

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

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.

3
Can you post what your POM dependencies look like? 35 MB seems a bit large if all you are interacting with is DynamoDB. You should be able to get that down to just 11 MB based on my experience.JaredHatfield

3 Answers

5
votes

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.

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.

0
votes

The larger JAR file that is being generated includes all of the library dependencies baked in. This is the one you will want to upload to S3 for use by AWS Lambda as these dependencies are required to run.

If you want to make this file smaller you can ensure you are only including libraries you need and remove any unnecessary ones. A common way to do this is with the AWS SDK only include the libraries for the specific services you need to call such as DynamoDB instead of including the entire AWS SDK.

0
votes

It seems standalone jar file built using shade plugin is sufficient as per this AWS documentation