Package software.amazon.awscdk.services.pipes.targets.alpha


@Stability(Experimental) package software.amazon.awscdk.services.pipes.targets.alpha

Amazon EventBridge Pipes Targets Construct Library

---

cdk-constructs: Experimental

The APIs of higher level constructs in this module are experimental and under active development. They are subject to non-backward compatible changes or removal in any future version. These are not subject to the Semantic Versioning model and breaking changes will be announced in the release notes. This means that while you may use them, you may need to update your source code when upgrading to a newer version of this package.


EventBridge Pipes Targets let you create a target for a EventBridge Pipe.

For more details see the service documentation:

Documentation

Targets

Pipe targets are the end point of a EventBridge Pipe.

The following targets are supported:

  1. targets.SqsTarget: Send event source to a Queue
  2. targets.SfnStateMachine: Invoke a State Machine from an event source
  3. targets.LambdaFunction: Send event source to a Lambda Function
  4. targets.ApiDestinationTarget: Send event source to an EventBridge API Destination
  5. targets.KinesisTarget: Send event source to a Kinesis data stream

Amazon SQS

A SQS message queue can be used as a target for a pipe. Messages will be pushed to the queue.

 Queue sourceQueue;
 Queue targetQueue;
 
 
 SqsTarget pipeTarget = new SqsTarget(targetQueue);
 
 Pipe pipe = Pipe.Builder.create(this, "Pipe")
         .source(new SomeSource(sourceQueue))
         .target(pipeTarget)
         .build();
 

The target input can be transformed:

 Queue sourceQueue;
 Queue targetQueue;
 
 
 SqsTarget pipeTarget = SqsTarget.Builder.create(targetQueue)
         .inputTransformation(InputTransformation.fromObject(Map.of(
                 "SomeKey", DynamicInput.fromEventPath("$.body"))))
         .build();
 
 Pipe pipe = Pipe.Builder.create(this, "Pipe")
         .source(new SomeSource(sourceQueue))
         .target(pipeTarget)
         .build();
 

AWS Step Functions State Machine

A State Machine can be used as a target for a pipe. The State Machine will be invoked with the (enriched) source payload.

 Queue sourceQueue;
 IStateMachine targetStateMachine;
 
 
 SfnStateMachine pipeTarget = SfnStateMachine.Builder.create(targetStateMachine).build();
 
 Pipe pipe = Pipe.Builder.create(this, "Pipe")
         .source(new SomeSource(sourceQueue))
         .target(pipeTarget)
         .build();
 

Specifying the Invocation Type when the target State Machine is invoked:

 Queue sourceQueue;
 IStateMachine targetStateMachine;
 
 
 SfnStateMachine pipeTarget = SfnStateMachine.Builder.create(targetStateMachine)
         .invocationType(StateMachineInvocationType.FIRE_AND_FORGET)
         .build();
 
 Pipe pipe = Pipe.Builder.create(this, "Pipe")
         .source(new SomeSource(sourceQueue))
         .target(pipeTarget)
         .build();
 

The input to the target State Machine can be transformed:

 Queue sourceQueue;
 IStateMachine targetStateMachine;
 
 
 SfnStateMachine pipeTarget = SfnStateMachine.Builder.create(targetStateMachine)
         .inputTransformation(InputTransformation.fromObject(Map.of("body", "<$.body>")))
         .invocationType(StateMachineInvocationType.FIRE_AND_FORGET)
         .build();
 
 Pipe pipe = Pipe.Builder.create(this, "Pipe")
         .source(new SomeSource(sourceQueue))
         .target(pipeTarget)
         .build();
 

AWS Lambda Function

A Lambda Function can be used as a target for a pipe. The Lambda Function will be invoked with the (enriched) source payload.

 Queue sourceQueue;
 IFunction targetFunction;
 
 
 LambdaFunction pipeTarget = LambdaFunction.Builder.create(targetFunction).build();
 
 Pipe pipe = Pipe.Builder.create(this, "Pipe")
         .source(new SomeSource(sourceQueue))
         .target(pipeTarget)
         .build();
 

The target Lambda Function is invoked synchronously by default. You can also choose to invoke the Lambda Function asynchronously by setting invocationType property to FIRE_AND_FORGET.

 Queue sourceQueue;
 IFunction targetFunction;
 
 
 LambdaFunction pipeTarget = LambdaFunction.Builder.create(targetFunction)
         .invocationType(LambdaFunctionInvocationType.FIRE_AND_FORGET)
         .build();
 
 Pipe pipe = Pipe.Builder.create(this, "Pipe")
         .source(new SomeSource(sourceQueue))
         .target(pipeTarget)
         .build();
 

The input to the target Lambda Function can be transformed:

 Queue sourceQueue;
 IFunction targetFunction;
 
 
 LambdaFunction pipeTarget = LambdaFunction.Builder.create(targetFunction)
         .inputTransformation(InputTransformation.fromObject(Map.of("body", "👀")))
         .build();
 
 Pipe pipe = Pipe.Builder.create(this, "Pipe")
         .source(new SomeSource(sourceQueue))
         .target(pipeTarget)
         .build();
 

Amazon EventBridge API Destination

An EventBridge API destination can be used as a target for a pipe. The API destination will receive the (enriched/filtered) source payload.

 Queue sourceQueue;
 ApiDestination dest;
 
 
 ApiDestinationTarget apiTarget = new ApiDestinationTarget(dest);
 
 Pipe pipe = Pipe.Builder.create(this, "Pipe")
         .source(new SqsSource(sourceQueue))
         .target(apiTarget)
         .build();
 

The input to the target API destination can be transformed:

 Queue sourceQueue;
 ApiDestination dest;
 
 
 ApiDestinationTarget apiTarget = ApiDestinationTarget.Builder.create(dest)
         .inputTransformation(InputTransformation.fromObject(Map.of("body", "👀")))
         .build();
 
 Pipe pipe = Pipe.Builder.create(this, "Pipe")
         .source(new SqsSource(sourceQueue))
         .target(apiTarget)
         .build();
 

Amazon Kinesis Data Stream

A data stream can be used as a target for a pipe. The data stream will receive the (enriched/filtered) source payload.

 Queue sourceQueue;
 Stream targetStream;
 
 
 KinesisTarget streamTarget = KinesisTarget.Builder.create(targetStream)
         .partitionKey("pk")
         .build();
 
 Pipe pipe = Pipe.Builder.create(this, "Pipe")
         .source(new SqsSource(sourceQueue))
         .target(streamTarget)
         .build();
 

The input to the target data stream can be transformed:

 Queue sourceQueue;
 Stream targetStream;
 
 
 KinesisTarget streamTarget = KinesisTarget.Builder.create(targetStream)
         .partitionKey("pk")
         .inputTransformation(InputTransformation.fromObject(Map.of("body", "👀")))
         .build();
 
 Pipe pipe = Pipe.Builder.create(this, "Pipe")
         .source(new SqsSource(sourceQueue))
         .target(streamTarget)
         .build();