2

I'm unable to get a Spring-Cloud based AWS Lambda Function with an SQS Message trigger to work. I'm using the Spring Cloud Function AWS adapter version 2.0.1.RELEASE and attempting to deploy to the AWS EU-WEST-2 Region.

My SpringBootRequestHandler is defined as follows:

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

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

}

My @Bean function looks as follows:

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

I feed this with the following test event:

{
  "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"
    }
  ]
}


When I run this , I get the following error:

{
  "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)"
  ]
}

Anyone have any suggestions around what's going wrong here? Alternatively, if there are any working samples on the web for my exact scenario, that would be good as well.

majafri
  • 21
  • 4
  • Sorry for getting back so late. This looks like a bug. Would you mind opening an issue [here](https://github.com/spring-cloud/spring-cloud-function/issues). Feel free to link this post – Oleg Zhurakousky Jun 03 '19 at 13:02
  • For anyone stumbling across this same issue, I've raised it on github here https://github.com/spring-cloud/spring-cloud-function/issues/373 – majafri Jun 17 '19 at 14:27

0 Answers0