-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path40-distributed-map.ts
More file actions
40 lines (36 loc) · 1.36 KB
/
Copy path40-distributed-map.ts
File metadata and controls
40 lines (36 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
40
// Distributed Map
//
// Process large datasets (up to 10,000 concurrent iterations) with S3-based
// input/output. Compiles to ASL Map with ProcessorConfig Mode: DISTRIBUTED.
import { Steps, SimpleStepContext } from '../../packages/core/src/runtime/index';
import { Lambda } from '../../packages/core/src/runtime/services/Lambda';
const processRecord = Lambda<{ record: any }, { result: string }>(
'arn:aws:lambda:us-east-1:123456789012:function:ProcessRecord'
);
export const distributedMapWorkflow = Steps.createFunction(
async (context: SimpleStepContext, input: { bucket: string; items: any[] }) => {
const results = await Steps.distributedMap(
input.items,
async (item) => {
const result = await processRecord.call({ record: item });
return { processed: result.result };
},
{
maxConcurrency: 1000,
executionType: 'EXPRESS',
itemReader: {
Resource: 'arn:aws:states:::s3:getObject',
ReaderConfig: { InputType: 'CSV' },
Parameters: { Bucket: input.bucket, Key: 'data.csv' },
},
resultWriter: {
Resource: 'arn:aws:states:::s3:putObject',
Parameters: { Bucket: input.bucket, Prefix: 'results/' },
},
toleratedFailurePercentage: 5,
label: 'ProcessRecords',
},
);
return { processed: results.length };
},
);