Remote Functions
Once functions have been deployed to a cloud provider, you can specify endpoints in your client configuration. Micronaut will then create FunctionDefinitions
for these remote functions, allowing you to access them through FunctionClient
interfaces just as you would with local functions.
AWS Lambda
The configuration key path aws.lambda.functions
can be used to specify function endpoints in an AWS Lambda environment.
application.yml
aws:
lambda:
functions:
hello:
functionName: hello-world
qualifer: foo
region: us-east-1
In the above case a function named hello
is mapped to the remote lambda function called hello-world
. You can define multiple named functions under the aws.lambda.functions
configuration. Each is configured by AWSInvokeRequestDefinition that allows setting any property on the underlying com.amazonaws.services.lambda.model.InvokeRequest
.
To configure credentials for invoking the function you can either define a ~/.aws/credentials
file or use application.yml
. Micronaut registers a EnvironmentAWSCredentialsProvider that resolves AWS credentials from the Micronaut Environment.
To invoke a function Micronaut configures a AWSLambdaAsyncClient using AWSLambdaConfiguration that allows configuring any of the properties of the AWSLambdaAsyncClientBuilder class. |
You can now write FunctionClient
interfaces against the remote function, as shown below.
HelloClient.groovy
import io.reactivex.*;
@FunctionClient
interface HelloClient {
Single<String> hello(String name);
}