Create-Function

The create-function command will generate a Micronaut function project, optimized for serverless environments, with optional flags to specify language, test framework, features and build tool. The project will include a *Function class (based on the project name - e.g., hello-world will generate HelloWorldFunction), and an associated test which will instantiate the function and verify that it can receive requests.

Currently AWS Lambda is the only supported cloud provider for Micronaut functions, so some of the information below will be specific to that platform. Other cloud providers will be added soon and this section will be updated accordingly.
Table 4. Create-Function Flags
FlagDescriptionExample

-l, —lang

Language to use for the function (one of java, groovy, kotlin - default is java)

—lang groovy

-t, —test

Test framework to use for the function (one of junit, spock - default is junit)

—test spock

-b, —build

Build tool (one of gradle, maven - default is gradle)

—build maven

-f, —features

Features to use for the function, comma-separated

  1. features security-jwt,mongo-gorm

or

  1. -f security-jwt -f mongo-gorm

-p, —provider

Provider to use for the function (currently the only supported provider is aws for AWS Lambda - this is the default)

—provider aws

-i, —inplace

If present, generates the function in the current directory (function name is optional if this flag is set)

—inplace

Language

Setting the language using the lang flag will generate a *Function file in the appropriate language. For Java/Kotlin, this will generate a class annotated with @FunctionBean. For Groovy, a Groovy function script will be generated. See Writing Functions for more details on how to write and test Micronaut functions.

Depending on language choice, an appropriate test will also be generated. By default, a Java function will include a JUnit test, a Groovy function will include a Spock test, and a Kotlin function will include a KotlinTest test. However, you can override the chosen test framework with the test flag.

  1. $ mn create-function hello-world --lang java --test spock

Build Tool

Depending upon the build tool selected, the project will include various tasks for building/deploying the function.

Gradle

Functions with a Gradle build are preconfigured with the Gradle AWS Plugin. The configuration can be seen in the build.gradle file (see the section on Deploying Functions to AWS Lambda). Assuming valid AWS credentials under ~/.aws/credentials, the application can be deployed using the deploy task.

  1. $ ./gradlew deploy

Maven

Functions with a Maven build are preconfigured with the Maven Shade Plugin, which will generate an executable JAR suitable for uploading to AWS Lambda. The JAR file can be built using the package phase.

  1. $ ./mvnw package

For further details, consult the AWS Lambda Documentation.