Skip to content

Commit

Permalink
fix(stepfunctions): item batcher doesn't properly render json paths
Browse files Browse the repository at this point in the history
The ItemBatcher property of DistributedMap supports json path fields,
but the new DistributedMap construct doesn't call
FieldUtils.renderObject when rendering the ItemBatcher.

Make sure to call `FieldUtils.renderObject()` when rendering this
property.

Added an integration test to ensure that the json path field resolves to
the actual value from the state in the input by checking the output from
the results writer in S3.
  • Loading branch information
noseworthy committed Mar 31, 2024
1 parent df48fd7 commit 03ec32f
Show file tree
Hide file tree
Showing 15 changed files with 35,319 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/* eslint-disable no-console */

import {
S3Client,
ListObjectsV2Command,
GetObjectCommand,
} from '@aws-sdk/client-s3';

const client = new S3Client({});

type ResultObject ={
ExecutionArn: string;
Input: string;
InputDetails: { Included: boolean };
Name: string;
Output: string;
OutputDetails: { Included: boolean };
RedriveCount: number;
RedriveStatus: string;
RedriveStatusReason: string;
StartDate: string;
StateMachineArn: string;
Status: string;
StopDate: string;
};

export async function handler(event: { bucket: string; prefix: string }) {
console.log('handling event', event);

console.log('getting key for results writer succeeded file');
const listObjectsCommandOutput = await client.send(new ListObjectsV2Command({
Bucket: event.bucket,
Prefix: event.prefix,
}));

if (!listObjectsCommandOutput.Contents) {
throw new Error('No objects found');
}

const succeedKey = listObjectsCommandOutput.Contents.find((object) => object?.Key?.endsWith('SUCCEEDED_0.json'));

if (!succeedKey) {
throw new Error('No SUCCEEDED_0.json found');
}
console.log('found key', succeedKey.Key);

console.log('getting object');
const object = await client.send(new GetObjectCommand({
Bucket: event.bucket,
Key: succeedKey.Key,
}));

if (!object?.Body) {
throw new Error('No object body found');
}

const body: ResultObject[] = JSON.parse(await object.Body.transformToString());
console.log('got succeeded object body', body);

return JSON.parse(body[0].Input);
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 03ec32f

Please sign in to comment.