AWS Lambda

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

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

Reported issues

Tagged issues at Github

Artifacts

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

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: AWSLambdaAsync = AWSLambdaAsyncClientBuilder
  .standard()
  .withCredentials(new AWSStaticCredentialsProvider(credentials))
  .build();
Full source at GitHub
Java
BasicAWSCredentials credentials = new BasicAWSCredentials("x", "x");
AWSLambdaAsync awsLambdaClient =
    AWSLambdaAsyncClientBuilder.standard()
        .withCredentials(new AWSStaticCredentialsProvider(credentials))
        .build();
Full source at GitHub

We will also need an ActorSystem and an ActorMaterializer.

Scala
implicit val system = ActorSystem()
implicit val mat = ActorMaterializer()
Full source at GitHub
Java
ActorSystem system = ActorSystem.create();
ActorMaterializer materializer = ActorMaterializer.create(system);
Full source at GitHub

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)
Full source at GitHub
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);
Full source at GitHub

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.