26

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!

4

7 回答 7

43

这两个类都包含在aws-lambda-java-core jar 中,该 jar 与 AWS 开发工具包分开分发。如果您不使用 maven/gradle/其他可以从 maven Central 本地提取的构建系统,您可以从上面的链接中的 maven Central 下载它。

于 2015-07-01T06:42:12.257 回答
6
  1. 在 Eclipse 中从市场添加 AWS 插件,制作 aws lambda 项目。
  2. 使用以下三个依赖项来制作 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>
    
于 2017-01-09T17:34:11.867 回答
3

经过一番搜索,我在http://mvnrepository.com/artifact/com.amazonaws/aws-lambda-java-core/1.1.0中找到了 com.amazonaws.services.lambda.runtime.Context 。(我更喜欢这个站点而不是 search.maven.org。mvnrepository.com 通过提供 sbt 构建行来解决我的问题的核心。)

该类不在 aws-java-sdk-lambda 中,也不在 aws-java-sdk-core 或 aws-java-sdk 中。

于 2016-04-08T14:09:15.060 回答
2

对于那些使用 sbt 的人:

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

检查最新版本的链接:

于 2017-08-16T18:18:14.570 回答
1

亚瑟,

您尝试将AWS Lambda中的 java 代码示例用于另一种产品 Amazon AWS SDK For Java

请阅读 AWS Lambda 欢迎页面,也许在(创建帐户和其他)步骤之后,您可以下载包含您的课程的包(上下文,LambdaLogger)

于 2015-07-01T07:18:10.147 回答
1

对我来说,intellij 的解决方案是删除所有.iml文件和invalidate cache/restart.

于 2022-01-14T12:44:53.640 回答
0

我在以下位置找到了 com.amazonaws.services.lambda.runtime.LambdaLogger: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>
于 2016-11-27T04:56:06.920 回答