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. |
Flag | Description | Example |
---|---|---|
| Language to use for the function (one of |
|
| Test framework to use for the function (one of |
|
| Build tool (one of |
|
| Features to use for the function, comma-separated |
or
|
| Provider to use for the function (currently the only supported provider is |
|
| If present, generates the function in the current directory (function name is optional if this flag is set) |
|
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.
$ 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.
$ ./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.
$ ./mvnw package
For further details, consult the AWS Lambda Documentation.