Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

package com.amazonaws.services.lambda.runtime does not exist in AWS java sdk 1.10.2

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!

like image 391
Arthur Avatar asked Jul 01 '15 04:07

Arthur


People also ask

Is AWS SDK available in Lambda?

The Lambda service also provides AWS SDKs for your chosen runtime.

Does AWS Lambda support Java 17?

For example, the Lambda runtime for Java supports the LTS versions Java 8 Corretto and Java 11 Corretto as of April 2022. The Java 17 Corretto version is pending. In addition, there is no provided runtime for non LTS versions like Java 15 Corretto, Java 16 Corretto, or Java 18 Corretto.

What is runtime in AWS Lambda?

Lambda re-uses the execution environment from a previous invocation if one is available, or it can create a new execution environment. A runtime can support a single version of a language, multiple versions of a language, or multiple languages.

What is Maven in AWS?

You can use Apache Maven to configure and build AWS SDK for Java projects, or to build the SDK itself. You must have Maven installed to use the guidance in this topic.


2 Answers

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.

like image 173
David Murray Avatar answered Sep 20 '22 08:09

David Murray


  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> 
like image 33
kartik Avatar answered Sep 17 '22 08:09

kartik