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!
The Lambda service also provides AWS SDKs for your chosen runtime.
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.
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.
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.
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.
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With