-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path27-lambda-patterns.ts
More file actions
39 lines (31 loc) · 1.36 KB
/
Copy path27-lambda-patterns.ts
File metadata and controls
39 lines (31 loc) · 1.36 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
34
35
36
37
38
39
// Lambda Invocation Patterns
//
// Three Lambda invocation modes: synchronous (default), asynchronous
// (fire-and-forget), and wait-for-callback (waitForTaskToken).
import { Steps, SimpleStepContext } from '../../packages/core/src/runtime/index';
import { Lambda } from '../../packages/core/src/runtime/services/Lambda';
const processOrder = Lambda<{ orderId: string }, { status: string }>(
'arn:aws:lambda:us-east-1:123456789:function:ProcessOrder',
);
const sendEmail = Lambda<{ to: string; body: string }, void>(
'arn:aws:lambda:us-east-1:123456789:function:SendEmail',
);
const longRunningJob = Lambda<{ jobId: string }, { result: string }>(
'arn:aws:lambda:us-east-1:123456789:function:LongRunningJob',
);
export const lambdaPatterns = Steps.createFunction(
async (context: SimpleStepContext, input: { orderId: string; email: string }) => {
// Synchronous — wait for result
const order = await processOrder.call({ orderId: input.orderId });
// Asynchronous — fire and forget (InvocationType: Event)
await sendEmail.callAsync({
to: input.email,
body: order.status,
});
// Wait for callback — pauses until Lambda calls SendTaskSuccess
const jobResult = await longRunningJob.callWithCallback<{ result: string }>({
jobId: input.orderId,
});
return { orderStatus: order.status, jobResult: jobResult.result };
},
);