Spring cloud function application is unable to find function on AWS Lamdba

Viewed 3289

I'm trying to deploy my Spring Cloud Function on AWS Lamdba but it looks like my function is not added to the function catalog, so I assume something is wrong with my bean registration but couldn't figure it out.

My Spring App:

@SpringBootApplication
public class TranscribeEventHandlerApplication implements ApplicationContextInitializer<GenericApplicationContext> {

    public static void main(String[] args) {
      FunctionalSpringApplication.run(TranscribeEventHandlerApplication.class, args);
    }

    public Function<String, String> handle() {
      return value -> "OK";
    }

    @Override
    public void initialize(GenericApplicationContext context) {
      context.registerBean("handle", FunctionRegistration.class, 
        () -> new FunctionRegistration<>(handle())
        .type(FunctionType.from(String.class).to(String.class).getType()));
    }
}

My pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.4.7</version>
        <relativePath /> <!-- lookup parent from repository -->
    </parent>
    <groupId>ai.alabs</groupId>
    <artifactId>transcribe-event-handler</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>transcribe-event-handler</name>
    <description>Demo project for Spring Boot</description>
    <properties>
        <java.version>11</java.version>
        <spring-cloud.version>2020.0.3</spring-cloud.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-function-adapter-aws</artifactId>
        </dependency>
        <dependency>
            <groupId>com.amazonaws</groupId>
            <artifactId>aws-lambda-java-core</artifactId>
            <version>1.1.0</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.amazonaws</groupId>
            <artifactId>aws-lambda-java-events</artifactId>
            <version>2.0.2</version>
        </dependency>

        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>${spring-cloud.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-deploy-plugin</artifactId>
                <configuration>
                    <skip>true</skip>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <dependencies>
                    <dependency>
                        <groupId>org.springframework.boot.experimental</groupId>
                        <artifactId>spring-boot-thin-layout</artifactId>
                        <version>1.0.17.RELEASE</version>
                    </dependency>
                </dependencies>
                <configuration>
                    <excludes>
                        <exclude>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok</artifactId>
                        </exclude>
                    </excludes>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <configuration>
                    <createDependencyReducedPom>false</createDependencyReducedPom>
                    <shadedArtifactAttached>true</shadedArtifactAttached>
                    <shadedClassifierName>aws</shadedClassifierName>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

Lamdba config:

  • Runtime: Java 11 (Corretto)
  • Handler: org.springframework.cloud.function.adapter.aws.FunctionInvoker

From the log I can see that the application receives the test event and the defined handler handles it but it fails to find my function.

2021-07-07 01:16:12.932  INFO 8 --- [           main] o.s.c.f.adapter.aws.FunctionInvoker      : Received: {"version":"0","id":"999cccaa-eaaa-0000-1111-123456789012","detail-type":"Transcribe Job State Change","source":"aws.transcribe","account":"123456789012","time":"2016-12-16T20:57:47Z","region":"us-east-1","resources":[],"detail":{"TranscriptionJobStatus":["COMPLETED"]}}
2021-07-07 01:16:12.962  INFO 8 --- [           main] o.s.c.f.adapter.aws.AWSLambdaUtils       : Incoming JSON Event: {"version":"0","id":"999cccaa-eaaa-0000-1111-123456789012","detail-type":"Transcribe Job State Change","source":"aws.transcribe","account":"123456789012","time":"2016-12-16T20:57:47Z","region":"us-east-1","resources":[],"detail":{"TranscriptionJobStatus":["COMPLETED"]}}
2021-07-07 01:16:13.129  INFO 8 --- [           main] o.s.c.f.adapter.aws.AWSLambdaUtils       : Incoming request headers: {id=22800a64-d3b5-000e-3be9-48418b185b32, timestamp=1625620572948}

When I don't set any environment variable I get this error Failed to establish route, since neither were provided: 'spring.cloud.function.definition' as Message header or as application property or 'spring.cloud.function.routing-expression' as application property.

When I set the environment variable spring_cloud_function_routingExpression=handle then I get this error EL1008E: Property or field 'handle' cannot be found on object of type 'org.springframework.messaging.support.GenericMessage' - maybe not public or not valid?.

When I set the environment variable spring_cloud_function_definition=handle then I get this error Failed to lookup function to route based on the value of 'spring.cloud.function.definition' property 'handle'

1 Answers
Related