| 1 | /** |
| 2 | * The EventBridge `detail-type`s Amazon AppFlow publishes for flow activity. |
| 3 | * Open union — AWS may add new report types. |
| 4 | */ |
| 5 | export type FlowEventDetailType = |
| 6 | | "AppFlow Start Flow Run Report" |
| 7 | | "AppFlow End Flow Run Report" |
| 8 | | "AppFlow Event Flow Report" |
| 9 | | (string & {}); |
| 10 | |
| 11 | export interface FlowEventsOptions { |
| 12 | /** |
| 13 | * Only match events for these flow names (the event detail's `flow-name`). |
| 14 | * Matches all flows when omitted. Use plain flow names (e.g. a constant |
| 15 | * `flowName` prop) — the pattern is matched again inside the running |
| 16 | * function, so unresolved `Output` values cannot be used here. |
| 17 | */ |
| 18 | flowNames?: string[]; |
| 19 | /** |
| 20 | * Only match these report types (e.g. `["AppFlow End Flow Run Report"]`). |
| 21 | * Matches every AppFlow event when omitted. |
| 22 | */ |
| 23 | detailTypes?: FlowEventDetailType[]; |
| 24 | /** |
| 25 | * Only match runs with these statuses (the event detail's `status`, e.g. |
| 26 | * `["Execution Successful"]`). |
| 27 | */ |
| 28 | statuses?: string[]; |
| 29 | } |
| 30 | |
| 31 | /** |
| 32 | * Builds an EventBridge event pattern for Amazon AppFlow flow run reports, |
| 33 | * for use with the EventBridge event source / routing helpers. AppFlow |
| 34 | * publishes start/end run reports to the default event bus (`source: |
| 35 | * "aws.appflow"`); the event detail carries `flow-name`, `execution-id`, |
| 36 | * `status`, timing, and record counts. |
| 37 | * |
| 38 | * @example Consume end-of-run reports for a flow with a Lambda handler |
| 39 | * ```typescript |
| 40 | * yield* AWS.EventBridge.consumeBusEvents( |
| 41 | * AWS.AppFlow.flowEvents({ |
| 42 | * flowNames: ["my-flow"], |
| 43 | * detailTypes: ["AppFlow End Flow Run Report"], |
| 44 | * }), |
| 45 | * (events) => |
| 46 | * events.pipe( |
| 47 | * Stream.runForEach((event) => Effect.log(event.detail)), |
| 48 | * ), |
| 49 | * ); |
| 50 | * ``` |
| 51 | * |
| 52 | * @example Route failed runs to an SQS queue |
| 53 | * ```typescript |
| 54 | * yield* AWS.EventBridge.events( |
| 55 | * AWS.AppFlow.flowEvents({ statuses: ["Execution Failed"] }), |
| 56 | * ).toQueue(alerts); |
| 57 | * ``` |
| 58 | */ |
| 59 | export const flowEvents = ({ |
| 60 | flowNames, |
| 61 | detailTypes, |
| 62 | statuses, |
| 63 | }: FlowEventsOptions = {}) => ({ |
| 64 | source: ["aws.appflow"], |
| 65 | ...(detailTypes ? { "detail-type": detailTypes } : {}), |
| 66 | ...(flowNames || statuses |
| 67 | ? { |
| 68 | detail: { |
| 69 | ...(flowNames ? { "flow-name": flowNames } : {}), |
| 70 | ...(statuses ? { status: statuses } : {}), |
| 71 | }, |
| 72 | } |
| 73 | : {}), |
| 74 | }); |