I try to deploy a function on AWS Lambda by a container image, but I cannot find an example of how to build it with the AWS lambda base image. Does Spring Cloud Function support this deploy method or only support deploying by a jar?
CodePudding user response:
I think what you are asking is closely related to AWS Custom Runtime and indeed we do have support and sample for it - https://github.com/spring-cloud/spring-cloud-function/tree/main/spring-cloud-function-samples/function-sample-aws-custom
CodePudding user response:
Yes, Spring Cloud Functions will work deployed as a container image. The process will be the same whether you use Spring Cloud Functions or another framework.
Here is an example Dockerfile from lambda-libs GitHub project.
# we'll use Amazon Linux 2 Corretto 11 as our base
FROM public.ecr.aws/amazoncorretto/amazoncorretto:11 as base
# 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
# in this case it'll be the special Spring Cloud Function handler
CMD [ "example.App::sayHello" ]