28

I am trying the Java code example in the Getting Started (Authoring AWS Lambda Code in Java) page, but am stuck as com.amazonaws.services.lambda.runtime pacakge seems to be missing

Here is the sample code:

package example;

import com.amazonaws.services.lambda.runtime.Context;      //package does not exist error
import com.amazonaws.services.lambda.runtime.LambdaLogger; // package does not exist error
import com.amazonaws.services.s3.AmazonS3;       // import works (not needed, I've put them in for testing import)
import com.amazonaws.services.s3.model.S3Object; // import works (not needed, I've put them in for testing import)

public class Hello {
    public String myHandler(int myCount, Context context) {
        LambdaLogger logger = context.getLogger();
        logger.log("received : " + myCount);
        return String.valueOf(myCount);
    }
}

I encounter the same error both in Netbeans and through command line (specifying the aws sdk thorugh -cp argument) from the first two imports of the code:

package com.amazonaws.services.lambda.runtime does not exist

Note importing other packages from the SDK works fine, as per third and fourth imports from the above code (the s3 imports which i put in just to test).

I am using version 1.10.2 (aws-java-sdk-1.10.2.zip) of the AWS Java SDK, downloaded from http://sdk-for-java.amazonwebservices.com/latest/aws-java-sdk.zip

Any directions/suggestions would be much appreciated. Thanks!

Arthur
  • 595
  • 1
  • 7
  • 17

7 Answers7

44

Both of those classes are contained in the aws-lambda-java-core jar, which is distributed separately from the AWS SDK. You can download it from maven central at the link above if you're not using maven/gradle/some other build system that can natively pull from maven central.

David Murray
  • 4,475
  • 1
  • 14
  • 16
  • Thanks David - I struggled to find the download link from AWS, but was able to get it from Maven as per your advice and the import not works! Cheers. – Arthur Jul 02 '15 at 10:25
  • @David- I am also facing a similar problem. When I am staring the app from the terminal using the cmd - 'sam local start-api' . It works fine but when I start by right clicking on the 'template.yml' file. It gives this error – Sunny Jul 03 '19 at 03:19
8
  1. Add AWS plugins within eclipse from market place, make aws lambda project.
  2. Use below three dependencies to make fat jar.

    <dependency>
        <groupId>com.amazonaws</groupId>
        <artifactId>aws-java-sdk-lambda</artifactId>
        <version>1.11.76</version>
    </dependency>
    <dependency>
        <groupId>com.amazonaws</groupId>
        <artifactId>aws-lambda-java-core</artifactId>
        <version>1.1.0</version>
    </dependency> 
    <dependency>
        <groupId>com.amazonaws</groupId>
        <artifactId>aws-lambda-java-events</artifactId>
        <version>1.3.0</version>
    </dependency>
    
kartik
  • 2,097
  • 3
  • 21
  • 31
3

After some searching I found com.amazonaws.services.lambda.runtime.Context in http://mvnrepository.com/artifact/com.amazonaws/aws-lambda-java-core/1.1.0 . (I prefer this site to search.maven.org. mvnrepository.com gets right to the heart of my problem by supplying the sbt build line.)

The class is not in aws-java-sdk-lambda , nor is it in aws-java-sdk-core, or aws-java-sdk .

dwalend
  • 103
  • 6
2

For those who are using sbt:

libraryDependencies ++= Seq(
  "com.amazonaws" % "aws-java-sdk" % "1.11.241",
  "com.amazonaws" % "aws-lambda-java-core" % "1.2.0"
)

Check the links for the lastest version:

Yuchen
  • 30,852
  • 26
  • 164
  • 234
1

Arthur,

You trying use java code sample from AWS Lambda for another product Amazon AWS SDK For Java.

Please read AWS Lambda welcome-page and maybe after steps for (create account and others) you can to download package with your classes (Context, LambdaLogger)

Baatr
  • 21
  • 5
  • Link-only answers are highly discouraged here because the links may become dead in the future. I suggest you edit your answer with quotes from the sources you cite. – Anirudh Sharma Jul 01 '15 at 07:26
  • Thanks Battr for clarifying the difference between AWS SDK library and AWS Lambda library. – Arthur Jul 02 '15 at 10:27
1

For me, the solution for intellij was delete all .iml files and invalidate cache/restart.

0

I found com.amazonaws.services.lambda.runtime.LambdaLogger in: https://mvnrepository.com/artifact/com.amazonaws/aws-lambda-java-log4j/1.0.0

<dependency>
    <groupId>com.amazonaws</groupId>
    <artifactId>aws-lambda-java-log4j</artifactId>
    <version>1.0.0</version>
</dependency>
ljcundiff
  • 1,159
  • 1
  • 9
  • 14
  • In addition, this is the package you need to include if you want the sample Lamba Functions from the Alexa skills SDK to log to CloudWatch. – Nantoka May 10 '17 at 12:19