AWS Lambda Connector

The AWS Lambda Connector provides Akka Flow for AWS Lambda integration.

For more information about AWS Lambda please visit the official documentation.

Artifacts

sbt
libraryDependencies += "com.lightbend.akka" %% "akka-stream-alpakka-awslambda" % "0.11"
Maven
<dependency>
  <groupId>com.lightbend.akka</groupId>
  <artifactId>akka-stream-alpakka-awslambda_2.12</artifactId>
  <version>0.11</version>
</dependency>
Gradle
dependencies {
  compile group: "com.lightbend.akka", name: "akka-stream-alpakka-awslambda_2.12", version: "0.11"
}

Usage

Flow provided by this connector need a prepared AWSLambdaAsyncClient to be able to invoke lambda functions.

Scala
val credentials = new BasicAWSCredentials("x", "x")
implicit val lambdaClient: AWSLambdaAsyncClient =
  new AWSLambdaAsyncClient(credentials, Executors.newFixedThreadPool(1))
Java
BasicAWSCredentials credentials = new BasicAWSCredentials("x", "x");
AWSLambdaAsyncClient awsLambdaClient = new AWSLambdaAsyncClient(credentials, Executors.newFixedThreadPool(50));

We will also need an ActorSystem and an ActorMaterializer.

Scala
implicit val system = ActorSystem()
implicit val mat = ActorMaterializer()
Java
ActorSystem system = ActorSystem.create();
ActorMaterializer materializer = ActorMaterializer.create(system);

This is all preparation that we are going to need.

Flow messages to AWS Lambda

Now we can stream AWS Java SDK Lambda InvokeRequest to AWS Lambda functions AwsLambdaFlow factory.

Scala
val request = new InvokeRequest().withFunctionName("lambda-function-name").withPayload("test-payload")
Source.single(request).via(AwsLambdaFlow(1)).runWith(Sink.seq)
Java
InvokeRequest request = new InvokeRequest()
        .withFunctionName("lambda-function-name")
        .withPayload("test-payload");
Flow<InvokeRequest, InvokeResult, NotUsed> flow = AwsLambdaFlow.create(awsLambdaClient, 1);
final CompletionStage<List<InvokeResult>> stage = Source.single(request).via(flow).runWith(Sink.seq(), materializer);

AwsLambdaFlow configuration

Options:

  • parallelism - Number of parallel executions. Should be less or equal to number of threads in ExecutorService for AWSLambdaAsyncClient
Warning

AWSLambdaAsyncClient uses blocking http client for Lambda function invocation, make sure that there is enough threads for execution in AWSLambdaAsyncClient.

The source code for this page can be found here.