-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathworkflow.ts
43 lines (36 loc) · 1.11 KB
/
workflow.ts
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
40
41
42
43
import { workflow } from "../src/workflow.js";
import {
S3Client,
PutObjectCommand,
GetObjectCommand,
} from "@aws-sdk/client-s3";
const bucketName = process.env.BUCKET_NAME!;
const s3Client = new S3Client({});
// a workflow is implemented as a simple function accepting context and arbitrary parameters
export const uploadObjectWorkflow = workflow(
"uploadObjectWorkflow",
async (ctx, key: string, data: string) => {
// ctx.sleep will sleep (pause the workflow) for 1 second
await ctx.sleep(1);
// ctx.task will asynchronously (and durably, with at-least-once delivery) run the provided function in the worker Lambda Function
await ctx.task(async () => {
await s3Client.send(
new PutObjectCommand({
Bucket: bucketName,
Key: key,
Body: data,
}),
);
});
const response = await ctx.task(async () => {
const response = await s3Client.send(
new GetObjectCommand({
Bucket: bucketName,
Key: key,
}),
);
return response.Body?.transformToString() ?? "";
});
return response;
},
);