Skip to content

Commit

Permalink
feat(stepfunctions-tasks): Support `DynamoAttributeValue.listFromJson…
Browse files Browse the repository at this point in the history
…Path` (#17376)

Add `DynamoAttributeValue.listFromJsonPath(value: string)` to allow specifying a list/array from the state input as a parameter in a DynamoDB PutItem or UpdateItem optimized integration in stepfunctions-tasks.

Closes #17375 

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
rogerchi committed Nov 9, 2021
1 parent 69f5f3a commit bc10e6f
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 1 deletion.
Expand Up @@ -219,6 +219,16 @@ export class DynamoAttributeValue {
return new DynamoAttributeValue({ L: value.map((val) => val.toObject()) });
}

/**
* Sets an attribute of type List. For example: "L": [ {"S": "Cookies"} , {"S": "Coffee"}, {"S", "Veggies"}]
*
* @param value Json path that specifies state input to be used
*/
public static listFromJsonPath(value: string) {
validateJsonPath(value);
return new DynamoAttributeValue({ L: value });
}

/**
* Sets an attribute of type Null. For example: "NULL": true
*/
Expand Down
Expand Up @@ -193,7 +193,7 @@
{
"Ref": "AWS::Partition"
},
":states:::dynamodb:putItem\",\"Parameters\":{\"Item\":{\"MessageId\":{\"S\":\"1234\"},\"Text\":{\"S.$\":\"$.bar\"},\"TotalCount\":{\"N\":\"18\"},\"Activated\":{\"BOOL.$\":\"$.foo\"}},\"TableName\":\"",
":states:::dynamodb:putItem\",\"Parameters\":{\"Item\":{\"MessageId\":{\"S\":\"1234\"},\"Text\":{\"S.$\":\"$.bar\"},\"TotalCount\":{\"N\":\"18\"},\"Activated\":{\"BOOL.$\":\"$.foo\"},\"List\":{\"L.$\":\"$.list\"}},\"TableName\":\"",
{
"Ref": "Messages804FA4EB"
},
Expand Down
Expand Up @@ -37,6 +37,7 @@ class CallDynamoDBStack extends cdk.Stack {
Text: tasks.DynamoAttributeValue.fromString(sfn.JsonPath.stringAt('$.bar')),
TotalCount: tasks.DynamoAttributeValue.fromNumber(firstNumber),
Activated: tasks.DynamoAttributeValue.booleanFromJsonPath(sfn.JsonPath.stringAt('$.foo')),
List: tasks.DynamoAttributeValue.listFromJsonPath(sfn.JsonPath.stringAt('$.list')),
},
table,
});
Expand Down
Expand Up @@ -222,6 +222,22 @@ describe('DynamoAttributeValue', () => {
});
});

test('from list with json path', () => {
// GIVEN
const m = '$.path';
// WHEN
const attribute = tasks.DynamoAttributeValue.listFromJsonPath(
sfn.JsonPath.stringAt(m),
);

// THEN
expect(sfn.FieldUtils.renderObject(attribute)).toEqual({
attributeValue: {
'L.$': m,
},
});
});

test('from null', () => {
// WHEN
const attribute = tasks.DynamoAttributeValue.fromNull(true);
Expand Down

0 comments on commit bc10e6f

Please sign in to comment.