我想为AWS SAM当地的Kinesis消费者创建概念证明, 以下是我的Kinesis Consumer Java文件
import com.amazonaws.services.lambda.runtime.Context; import
com.amazonaws.services.lambda.runtime.RequestHandler; import
com.amazonaws.services.lambda.runtime.events.KinesisEvent; import
com.amazonaws.services.lambda.runtime.events.KinesisEvent.KinesisEventRecord;
public class LambdaFunctionHandler implements
RequestHandler<KinesisEvent, Integer> {
@Override
public Integer handleRequest(KinesisEvent event, Context context) {
context.getLogger().log("Input: " + event);
for (KinesisEventRecord record : event.getRecords()) {
String payload = new String(record.getKinesis().getData().array());
context.getLogger().log("Payload: " + payload);
}
return event.getRecords().size();
} }
这是我的template.yaml文件
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: A function that processes data from a Kinesis stream.
Resources:
LambdaFunction:
Type: AWS::Serverless::Function
Properties:
Handler: com.example.handler.LambdaFunctionHandler
CodeUri: ./target/demo-1.0.0.jar
Runtime: java8
Timeout: 10
Tracing: Active
Events:
Stream:
Type: Kinesis
Properties:
Stream: !GetAtt StreamConsumer.ConsumerARN
StartingPosition: LATEST
BatchSize: 100
ListProducts:
Type: Api
Properties:
Path: /lambda
Method: post
KinesisStream:
Type: "AWS::Kinesis::Stream"
Properties:
ShardCount: 1
Outputs:
FunctionName:
Description: "Function name"
Value: !Ref LambdaFunction
StreamARN:
Description: "Stream ARN"
Value: !GetAtt KinesisStream.Arn
首先,如何运行和使用sample.json文件,如果我这样运行,我将遇到错误
在共享凭据文件中找到凭据:〜/ .aws / credentials 找不到LambdaFunctionHandler。模板中的可能选项: ['LambdaFunction']
Error: Function LambdaFunctionHandler not found in template