0

I have defined a function in my Spring Cloud Function project, but after executing function (ScanQrCode) as AS Lambda I get:

2020-07-13 10:19:04.592  INFO 1 --- [           main] lambdainternal.LambdaRTEntry             : Started LambdaRTEntry in 26.357 seconds (JVM running for 27.777)
2020-07-13 10:19:04.653  INFO 1 --- [           main] o.s.c.f.c.c.SimpleFunctionRegistry       : Looking up function 'function' with acceptedOutputTypes: []
2020-07-13 10:19:04.731  INFO 1 --- [           main] o.s.c.f.c.c.SimpleFunctionRegistry       : Looking up function 'consumer' with acceptedOutputTypes: []
2020-07-13 10:19:04.734  INFO 1 --- [           main] o.s.c.f.c.c.SimpleFunctionRegistry       : Looking up function 'supplier' with acceptedOutputTypes: []
2020-07-13 10:19:04.754  INFO 1 --- [           main] o.s.c.f.c.c.SimpleFunctionRegistry       : Looking up function '' with acceptedOutputTypes: []
2020-07-13 10:19:04.811  INFO 1 --- [           main] o.s.c.f.c.c.SimpleFunctionRegistry       : Looking up function '' with acceptedOutputTypes: []
2020-07-13 10:19:04.811  INFO 1 --- [           main] o.s.c.f.c.c.SimpleFunctionRegistry       : Looking up function '' with acceptedOutputTypes: []
No function defined: java.lang.IllegalStateException
java.lang.IllegalStateException: No function defined
    at org.springframework.cloud.function.context.AbstractSpringFunctionAdapterInitializer.apply(AbstractSpringFunctionAdapterInitializer.java:187)
    at org.springframework.cloud.function.adapter.aws.SpringBootRequestHandler.handleRequest(SpringBootRequestHandler.java:51)

The weired thing here is that I have commented out the consume, supplier and function functions...I don“t know why Spring or AWS Lambda considered them...

Here are my classes:

Spring Boot App

@SpringBootApplication
public class FoodhatQrApplication {

    public static void main(String[] args) {
        SpringApplication.run(FoodhatQrApplication.class, args);
    }
        
//  @Bean
//  public Function<String, String> function(){
//      return input -> input;
//  }
//  
//  @Bean
//  public Consumer<String> consume(){
//      return input -> System.out.println("Input: " + input);
//  }
//
//  @Bean
//  public Supplier<String> supply(){
//      return () -> "Hello World";
//  }

}

Function class

@Component
    public class ScanQrCode implements Function<APIGatewayProxyRequestEvent, APIGatewayProxyResponseEvent>{
    
        @Autowired
        private QrCodeRepository qrCodeRepository;
    
        @Override
        public APIGatewayProxyResponseEvent apply(APIGatewayProxyRequestEvent request) {
              APIGatewayProxyResponseEvent response = new APIGatewayProxyResponseEvent();
              response.setStatusCode(302);
              response.setHeaders(Collections.singletonMap("location" , "http://www.google.de"));
              return response;
    
        }
    
    }

What am I missing?

skm
  • 559
  • 1
  • 6
  • 22

2 Answers2

0

Function Component Scan Adding spring.cloud.function.scan.packages might help.

Reference: https://cloud.spring.io/spring-cloud-function/reference/html/spring-cloud-function.html#_function_component_scan

Procrastinator
  • 2,526
  • 30
  • 27
  • 36
surajmali14
  • 1
  • 1
  • 3
-1

You definitely need to add your function name in our case it "ScanQrCode" to AWS lambda env variables. FUNCTION_NAME: ScanQrCode

Trybel
  • 1