-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path26-step-function-nested.ts
More file actions
33 lines (26 loc) · 1.14 KB
/
26-step-function-nested.ts
File metadata and controls
33 lines (26 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// Nested Step Function Execution
//
// Start a child state machine and wait for it to complete (sync),
// fire-and-forget (async), or wait for callback.
import { Steps, SimpleStepContext } from '../../packages/core/src/runtime/index';
import { StepFunction } from '../../packages/core/src/runtime/services/StepFunction';
const validationWorkflow = new StepFunction<
{ data: string },
{ valid: boolean; score: number }
>('arn:aws:states:us-east-1:123456789:stateMachine:ValidationWorkflow');
const notifyWorkflow = new StepFunction<
{ message: string },
void
>('arn:aws:states:us-east-1:123456789:stateMachine:NotifyWorkflow');
export const nestedExecution = Steps.createFunction(
async (context: SimpleStepContext, input: { data: string }) => {
// Synchronous — waits for child to complete
const result = await validationWorkflow.startExecution({ data: input.data });
if (!result.valid) {
return { status: 'INVALID', score: result.score };
}
// Asynchronous — fire and forget
await notifyWorkflow.startExecutionAsync({ message: 'Validation passed' });
return { status: 'VALID', score: result.score };
},
);