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

  1. aws:
  2. lambda:
  3. functions:
  4. hello:
  5. functionName: hello-world
  6. qualifer: foo
  7. 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

  1. import io.reactivex.*;
  2. @FunctionClient
  3. interface HelloClient {
  4. Single<String> hello(String name);
  5. }