Using Groovy on the AWS Lambda Java8 Runtime

AWS Lambda is a service for running code in the cloud that manages its resources automatically. Since it provides a full Java 8 runtime, it is possible to use groovy to write your Lambda services.

When you deploy a Lambda service, you need to bundle up all your resources into a single jar file. To run groovy, you simply need to include the groovy runtime in your jar.

Gradle makes this easy. First declare groovy as a compile dependency:

dependencies {
    compile 'org.codehaus.groovy:groovy-all:2.4.4'

Next, update the jar target to include all the runtime dependencies in the jar:

jar {
    dependsOn configurations.runtime
    from {
        configurations.runtime.collect {
            it.isDirectory() ? it : zipTree(it)

This bundles all the “compile” and “runtime” dependencies into one big “fat jar”.

For a full working example, check out groovy-aws-lambda on github.

Leave a Reply