Skip to content

Commit 893769e

Browse files
authored
feat(pipes-targets): add CloudWatch Logs (#30665)
Add CloudWatch Logs as a Pipe target.
1 parent 1557793 commit 893769e

16 files changed

+33984
-99
lines changed

packages/@aws-cdk/aws-pipes-targets-alpha/README.md

+132-99
Original file line numberDiff line numberDiff line change
@@ -17,118 +17,161 @@
1717
<!--END STABILITY BANNER-->
1818

1919

20-
EventBridge Pipes Targets let you create a target for a EventBridge Pipe.
20+
EventBridge Pipes Targets let you create a target for an EventBridge Pipe.
2121

22-
For more details see the service documentation:
23-
24-
[Documentation](https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-pipes-event-target.html)
22+
For more details see the [service documentation](https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-pipes-event-target.html).
2523

2624
## Targets
2725

28-
Pipe targets are the end point of a EventBridge Pipe.
26+
Pipe targets are the end point of an EventBridge Pipe. The following targets are supported:
27+
28+
* `targets.ApiDestinationTarget`: [Send event source to an EventBridge API destination](#amazon-eventbridge-api-destination)
29+
* `targets.CloudWatchLogsTarget`: [Send event source to a CloudWatch Logs log group](#amazon-cloudwatch-logs-log-group)
30+
* `targets.EventBridgeTarget`: [Send event source to an EventBridge event bus](#amazon-eventbridge-event-bus)
31+
* `targets.KinesisTarget`: [Send event source to a Kinesis data stream](#amazon-kinesis-data-stream)
32+
* `targets.LambdaFunction`: [Send event source to a Lambda function](#aws-lambda-function)
33+
* `targets.SfnStateMachine`: [Invoke a Step Functions state machine from an event source](#aws-step-functions-state-machine)
34+
* `targets.SqsTarget`: [Send event source to an SQS queue](#amazon-sqs)
35+
36+
### Amazon EventBridge API Destination
2937

30-
The following targets are supported:
38+
An EventBridge API destination can be used as a target for a pipe.
39+
The API destination will receive the (enriched/filtered) source payload.
3140

32-
1. `targets.SqsTarget`: [Send event source to an SQS queue](#amazon-sqs)
33-
2. `targets.SfnStateMachine`: [Invoke a State Machine from an event source](#aws-step-functions-state-machine)
34-
3. `targets.LambdaFunction`: [Send event source to a Lambda function](#aws-lambda-function)
35-
4. `targets.ApiDestinationTarget`: [Send event source to an EventBridge API destination](#amazon-eventbridge-api-destination)
36-
5. `targets.KinesisTarget`: [Send event source to a Kinesis data stream](#amazon-kinesis-data-stream)
37-
6. `targets.EventBridgeTarget`: [Send event source to an EventBridge event bus](#amazon-eventbridge-event-bus)
41+
```ts
42+
declare const sourceQueue: sqs.Queue;
43+
declare const dest: events.ApiDestination;
44+
45+
const apiTarget = new targets.ApiDestinationTarget(dest);
3846

39-
### Amazon SQS
47+
const pipe = new pipes.Pipe(this, 'Pipe', {
48+
source: new SqsSource(sourceQueue),
49+
target: apiTarget,
50+
});
51+
```
4052

41-
A SQS message queue can be used as a target for a pipe. Messages will be pushed to the queue.
53+
The input to the target API destination can be transformed:
4254

4355
```ts
4456
declare const sourceQueue: sqs.Queue;
45-
declare const targetQueue: sqs.Queue;
57+
declare const dest: events.ApiDestination;
4658

47-
const pipeTarget = new targets.SqsTarget(targetQueue);
59+
const apiTarget = new targets.ApiDestinationTarget(dest, {
60+
inputTransformation: pipes.InputTransformation.fromObject({ body: "👀" }),
61+
});
4862

4963
const pipe = new pipes.Pipe(this, 'Pipe', {
5064
source: new SqsSource(sourceQueue),
51-
target: pipeTarget
65+
target: apiTarget,
5266
});
5367
```
5468

55-
The target input can be transformed:
69+
### Amazon CloudWatch Logs Log Group
70+
71+
A CloudWatch Logs log group can be used as a target for a pipe.
72+
The log group will receive the (enriched/filtered) source payload.
5673

5774
```ts
5875
declare const sourceQueue: sqs.Queue;
59-
declare const targetQueue: sqs.Queue;
76+
declare const targetLogGroup: logs.LogGroup;
6077

61-
const pipeTarget = new targets.SqsTarget(targetQueue,
62-
{
63-
inputTransformation: pipes.InputTransformation.fromObject(
64-
{
65-
"SomeKey": pipes.DynamicInput.fromEventPath('$.body')
66-
})
67-
}
68-
);
78+
const logGroupTarget = new targets.CloudWatchLogsTarget(targetLogGroup);
6979

7080
const pipe = new pipes.Pipe(this, 'Pipe', {
7181
source: new SqsSource(sourceQueue),
72-
target: pipeTarget
82+
target: logGroupTarget,
7383
});
7484
```
7585

76-
### AWS Step Functions State Machine
86+
The input to the target log group can be transformed:
87+
88+
```ts
89+
declare const sourceQueue: sqs.Queue;
90+
declare const targetLogGroup: logs.LogGroup;
91+
92+
const logGroupTarget = new targets.CloudWatchLogsTarget(targetLogGroup, {
93+
inputTransformation: pipes.InputTransformation.fromObject({ body: "👀" }),
94+
});
7795

78-
A State Machine can be used as a target for a pipe. The State Machine will be invoked with the (enriched) source payload.
96+
const pipe = new pipes.Pipe(this, 'Pipe', {
97+
source: new SqsSource(sourceQueue),
98+
target: logGroupTarget,
99+
});
100+
```
101+
102+
### Amazon EventBridge Event Bus
103+
104+
An EventBridge event bus can be used as a target for a pipe.
105+
The event bus will receive the (enriched/filtered) source payload.
79106

80107
```ts
81108
declare const sourceQueue: sqs.Queue;
82-
declare const targetStateMachine: sfn.IStateMachine;
109+
declare const targetEventBus: events.EventBus;
83110

84-
const pipeTarget = new targets.SfnStateMachine(targetStateMachine,{});
111+
const eventBusTarget = new targets.EventBridgeTarget(targetEventBus);
85112

86113
const pipe = new pipes.Pipe(this, 'Pipe', {
87114
source: new SqsSource(sourceQueue),
88-
target: pipeTarget
115+
target: eventBusTarget,
89116
});
90117
```
91118

92-
Specifying the Invocation Type when the target State Machine is invoked:
119+
The input to the target event bus can be transformed:
93120

94121
```ts
95122
declare const sourceQueue: sqs.Queue;
96-
declare const targetStateMachine: sfn.IStateMachine;
123+
declare const targetEventBus: events.EventBus;
97124

98-
const pipeTarget = new targets.SfnStateMachine(targetStateMachine,
99-
{
100-
invocationType: targets.StateMachineInvocationType.FIRE_AND_FORGET,
101-
}
102-
);
125+
const eventBusTarget = new targets.EventBridgeTarget(targetEventBus, {
126+
inputTransformation: pipes.InputTransformation.fromObject({ body: "👀" }),
127+
});
103128

104129
const pipe = new pipes.Pipe(this, 'Pipe', {
105130
source: new SqsSource(sourceQueue),
106-
target: pipeTarget
131+
target: eventBusTarget,
107132
});
108133
```
109134

110-
The input to the target State Machine can be transformed:
135+
### Amazon Kinesis Data Stream
136+
137+
A Kinesis data stream can be used as a target for a pipe.
138+
The data stream will receive the (enriched/filtered) source payload.
111139

112140
```ts
113141
declare const sourceQueue: sqs.Queue;
114-
declare const targetStateMachine: sfn.IStateMachine;
142+
declare const targetStream: kinesis.Stream;
115143

116-
const pipeTarget = new targets.SfnStateMachine(targetStateMachine,
117-
{
118-
inputTransformation: pipes.InputTransformation.fromObject({ body: '<$.body>' }),
119-
invocationType: targets.StateMachineInvocationType.FIRE_AND_FORGET,
120-
}
121-
);
144+
const streamTarget = new targets.KinesisTarget(targetStream, {
145+
partitionKey: 'pk',
146+
});
122147

123148
const pipe = new pipes.Pipe(this, 'Pipe', {
124149
source: new SqsSource(sourceQueue),
125-
target: pipeTarget
150+
target: streamTarget,
151+
});
152+
```
153+
154+
The input to the target data stream can be transformed:
155+
156+
```ts
157+
declare const sourceQueue: sqs.Queue;
158+
declare const targetStream: kinesis.Stream;
159+
160+
const streamTarget = new targets.KinesisTarget(targetStream, {
161+
partitionKey: 'pk',
162+
inputTransformation: pipes.InputTransformation.fromObject({ body: "👀" }),
163+
});
164+
165+
const pipe = new pipes.Pipe(this, 'Pipe', {
166+
source: new SqsSource(sourceQueue),
167+
target: streamTarget,
126168
});
127169
```
128170

129171
### AWS Lambda Function
130172

131-
A Lambda Function can be used as a target for a pipe. The Lambda Function will be invoked with the (enriched) source payload.
173+
A Lambda function can be used as a target for a pipe.
174+
The Lambda function will be invoked with the (enriched/filtered) source payload.
132175

133176
```ts
134177
declare const sourceQueue: sqs.Queue;
@@ -142,7 +185,7 @@ const pipe = new pipes.Pipe(this, 'Pipe', {
142185
});
143186
```
144187

145-
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`.
188+
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`.
146189

147190
```ts
148191
declare const sourceQueue: sqs.Queue;
@@ -174,102 +217,92 @@ const pipe = new pipes.Pipe(this, 'Pipe', {
174217
});
175218
```
176219

177-
### Amazon EventBridge API Destination
220+
### AWS Step Functions State Machine
178221

179-
An EventBridge API destination can be used as a target for a pipe.
180-
The API destination will receive the (enriched/filtered) source payload.
222+
A Step Functions state machine can be used as a target for a pipe.
223+
The state machine will be invoked with the (enriched/filtered) source payload.
181224

182225
```ts
183226
declare const sourceQueue: sqs.Queue;
184-
declare const dest: events.ApiDestination;
227+
declare const targetStateMachine: sfn.IStateMachine;
185228

186-
const apiTarget = new targets.ApiDestinationTarget(dest);
229+
const pipeTarget = new targets.SfnStateMachine(targetStateMachine,{});
187230

188231
const pipe = new pipes.Pipe(this, 'Pipe', {
189232
source: new SqsSource(sourceQueue),
190-
target: apiTarget,
233+
target: pipeTarget
191234
});
192235
```
193236

194-
The input to the target API destination can be transformed:
237+
You can specify the invocation type when the target state machine is invoked:
195238

196239
```ts
197240
declare const sourceQueue: sqs.Queue;
198-
declare const dest: events.ApiDestination;
241+
declare const targetStateMachine: sfn.IStateMachine;
199242

200-
const apiTarget = new targets.ApiDestinationTarget(dest, {
201-
inputTransformation: pipes.InputTransformation.fromObject({ body: "👀" }),
243+
const pipeTarget = new targets.SfnStateMachine(targetStateMachine, {
244+
invocationType: targets.StateMachineInvocationType.FIRE_AND_FORGET,
202245
});
203246

204247
const pipe = new pipes.Pipe(this, 'Pipe', {
205248
source: new SqsSource(sourceQueue),
206-
target: apiTarget,
207-
});
208-
```
209-
210-
### Amazon Kinesis Data Stream
211-
212-
A data stream can be used as a target for a pipe. The data stream will receive the (enriched/filtered) source payload.
213-
214-
```ts
215-
declare const sourceQueue: sqs.Queue;
216-
declare const targetStream: kinesis.Stream;
217-
218-
const streamTarget = new targets.KinesisTarget(targetStream, {
219-
partitionKey: 'pk',
220-
});
221-
222-
const pipe = new pipes.Pipe(this, 'Pipe', {
223-
source: new SqsSource(sourceQueue),
224-
target: streamTarget,
249+
target: pipeTarget
225250
});
226251
```
227252

228-
The input to the target data stream can be transformed:
253+
The input to the target state machine can be transformed:
229254

230255
```ts
231256
declare const sourceQueue: sqs.Queue;
232-
declare const targetStream: kinesis.Stream;
257+
declare const targetStateMachine: sfn.IStateMachine;
233258

234-
const streamTarget = new targets.KinesisTarget(targetStream, {
235-
partitionKey: 'pk',
236-
inputTransformation: pipes.InputTransformation.fromObject({ body: "👀" }),
237-
});
259+
const pipeTarget = new targets.SfnStateMachine(targetStateMachine,
260+
{
261+
inputTransformation: pipes.InputTransformation.fromObject({ body: '<$.body>' }),
262+
invocationType: targets.StateMachineInvocationType.FIRE_AND_FORGET,
263+
}
264+
);
238265

239266
const pipe = new pipes.Pipe(this, 'Pipe', {
240267
source: new SqsSource(sourceQueue),
241-
target: streamTarget,
268+
target: pipeTarget
242269
});
243270
```
244271

245-
### Amazon EventBridge Event Bus
272+
### Amazon SQS Queue
246273

247-
An event bus can be used as a target for a pipe. The event bus will receive the (enriched/filtered) source payload.
274+
An SQS queue can be used as a target for a pipe.
275+
The queue will receive the (enriched/filtered) source payload.
248276

249277
```ts
250278
declare const sourceQueue: sqs.Queue;
251-
declare const targetEventBus: events.EventBus;
279+
declare const targetQueue: sqs.Queue;
252280

253-
const eventBusTarget = new targets.EventBridgeTarget(targetEventBus);
281+
const pipeTarget = new targets.SqsTarget(targetQueue);
254282

255283
const pipe = new pipes.Pipe(this, 'Pipe', {
256284
source: new SqsSource(sourceQueue),
257-
target: eventBusTarget,
285+
target: pipeTarget
258286
});
259287
```
260288

261-
The input to the target event bus can be transformed:
289+
The target input can be transformed:
262290

263291
```ts
264292
declare const sourceQueue: sqs.Queue;
265-
declare const targetEventBus: events.EventBus;
293+
declare const targetQueue: sqs.Queue;
266294

267-
const eventBusTarget = new targets.EventBridgeTarget(targetEventBus, {
268-
inputTransformation: pipes.InputTransformation.fromObject({ body: "👀" }),
269-
});
295+
const pipeTarget = new targets.SqsTarget(targetQueue,
296+
{
297+
inputTransformation: pipes.InputTransformation.fromObject(
298+
{
299+
"SomeKey": pipes.DynamicInput.fromEventPath('$.body')
300+
})
301+
}
302+
);
270303

271304
const pipe = new pipes.Pipe(this, 'Pipe', {
272305
source: new SqsSource(sourceQueue),
273-
target: eventBusTarget,
306+
target: pipeTarget
274307
});
275308
```

0 commit comments

Comments
 (0)