Spring Cloud函数和SQSEvent触发的AWS Lambda函数

时间:2019-05-27 12:23:09

标签: spring-cloud spring-cloud-function

我无法获得具有SQS消息触发器的基于Spring-Cloud的AWS Lambda函数。我正在使用Spring Cloud Function AWS适配器版本2.0.1.RELEASE,并尝试将其部署到AWS EU-WEST-2区域。

我的SpringBootRequestHandler定义如下:

    import org.springframework.cloud.function.adapter.aws.SpringBootRequestHandler;

    import com.amazonaws.services.lambda.runtime.events.SQSEvent;
    public class ReplicationHandler extends SpringBootRequestHandler<SQSEvent, String>{

}

我的@Bean函数如下所示:

    @Bean
    public Function<SQSEvent, String> handleEvent() {   
        return value -> processEvent((SQSEvent)value);
    }

我通过以下测试事件来提供该信息:

{
  "Records": [
    {
      "messageId": "02a4e04b-a1d2-417a-b073-56123be35ac6",
      "receiptHandle": "AQEB0fsSc76vU9Y6vQEz",
      "body": "hello world",
      "attributes": {
        "ApproximateReceiveCount": "1",
        "SentTimestamp": "1553860061037",
        "SenderId": "AIDAIVEA3AGEU7NF6DRAG",
        "ApproximateFirstReceiveTimestamp": "1553860061042"
      },
      "messageAttributes": {},
      "md5OfBody": "a4d19d8b1019e01bb875eea6232bf2f1",
      "eventSource": "aws:sqs",
      "eventSourceARN": "arn:aws:sqs:eu-west-2:XXXXX:YYYYY",
      "awsRegion": "eu-west-2"
    }
  ]
}


运行此命令时,出现以下错误:

{
  "errorMessage": "reactor.core.publisher.FluxJust cannot be cast to com.amazonaws.services.lambda.runtime.events.SQSEvent",
  "errorType": "java.lang.ClassCastException",
  "stackTrace": [
    "org.springframework.cloud.function.adapter.aws.SpringFunctionInitializer.apply(SpringFunctionInitializer.java:132)",
    "org.springframework.cloud.function.adapter.aws.SpringBootRequestHandler.handleRequest(SpringBootRequestHandler.java:48)"
  ]
}

有人对这里出什么问题有任何建议吗?另外,如果在我的确切情况下网络上有任何可行的样本,那也将很好。

0 个答案:

没有答案