Search code examples
aws-lambdaaws-serverlessspring-cloud-function

How to run a spring cloud function as AWS lambda using custom java 17 base image?


Java 17 is not supported by aws lambda. I need to create a lambda function using spring cloud and java 17 as base image. What dependencies I must install in my java 17 base image?

I have used this docker file.

FROM adoptopenjdk:17-jre-hotspot as base
LABEL MAINTAINER=uniphore.com

# configure the build environment


FROM base as build
\#RUN yum install -y maven
WORKDIR /src

# cache and copy dependencies

ADD pom.xml .
RUN mvn dependency:go-offline dependency:copy-dependencies

# compile the function

ADD . .
RUN mvn package

# copy the function artifact and dependencies onto a clean base

FROM base
WORKDIR /function

COPY --from=build /src/target/dependency/*.jar ./
COPY --from=build /src/target/*.jar ./

# configure the runtime startup as main

ENTRYPOINT \[ "/usr/bin/java", "-cp", "./\*", "com.amazonaws.services.lambda.runtime.api.client.AWSLambda" \]

# pass the name of the function handler as an argument to the runtime

CMD \[ "org.springframework.cloud.function.adapter.aws.FunctionInvoker::handleRequest" \]\`

Solution

  • Here is an example with java 19 and GrallVM native - https://github.com/spring-cloud/spring-cloud-function/tree/main/spring-cloud-function-samples/function-sample-aws-native