What should the dockerfile for a kotline project look like for AWS Lambda?

Viewed 124

I'm deploying some Kotlin code via a container and running it via AWS Lambda. However, I keep running into an issue where when I invoke the Lambda, it cannot find the main class or handler.

This is what my Dockefile look like currently

# This builder image will not be used at runtime
# See https://docs.docker.com/develop/develop-images/multistage-build/
FROM gradle:6.7.1 as builder

# Copy sourcecode into build image
COPY app/build.gradle ./app/
COPY app/src/ ./app/src/
COPY settings.gradle ./
COPY gradle.properties ./
COPY entrypoint.sh ./


ENV ARTIFACTORY_CREDENTIALS_USR=njohnson
ENV ARTIFACTORY_CREDENTIALS_PSW=[redacted]

RUN gradle clean build --no-daemon --stacktrace

# Now switch to the runtime image; base it on the latest Java, in a "slim" variant.
FROM adoptopenjdk/openjdk13:debianslim-jre
# Put the one necessary class files, with all dependencies, into the into the runtime.


CMD ["java", "-jar", "./app.jar"]
CMD ["readCartMessageDBLambda.Handler::handler"]

This is a small snippet from my build.gradle file

application {
    // Define the main class for the application.
    mainClass = 'readCartMessageDBLambda.Handlerkt'
}
sourceSets.main.java.srcDirs = ['src/main/kotlin']




jar {
    zip64 true
    manifest {
        attributes 'Main-Class': application.mainClass
    }
    from {
        configurations.compileClasspath.collect {
            it.isDirectory() ? it : zipTree(it)
        }
    }
}

Is this the proper format for the dockerfile or am I missing something? Currently I'm getting this error:

Error: Could not find or load main class readCartMessageDBLambda.Handlerkt
Caused by: java.lang.ClassNotFoundException: readCartMessageDBLambda.Handlerkt

I've been unable to find a lot of examples for Kotlin w/ AWS Lambda and Docker so I'm hoping someone can help me.

0 Answers
Related