Skip to content

Commit

Permalink
add remove and update function
Browse files Browse the repository at this point in the history
  • Loading branch information
ebisbe committed Jul 11, 2024
1 parent 8e37a21 commit c557e39
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 12 deletions.
38 changes: 26 additions & 12 deletions src/stepFunctions/itemStream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,23 @@ export const itemStream = {
Type: "Task",
Resource: "arn:aws:states:::dynamodb:updateItem",
Parameters: {
TableName: "MyDynamoDBTable",
TableName: getRef(WeddingTable),
Key: {
Column: {
S: "MyEntry",
pk: {
"S.$": "States.Format('LIST#{}',$.NewImage.listId.S)",
},
sk: {
"S.$": "States.Format('LIST#{}',$.NewImage.listId.S)",
},
},
UpdateExpression: "SET MyKey = :myValueRef",
UpdateExpression:
"SET totalPrice = totalPrice - :oldPrice + :newPrice",
ExpressionAttributeValues: {
":myValueRef": {
S: "MyValue",
":newPrice": {
"N.$": "$.NewImage.price.N",
},
":oldPrice": {
"N.$": "$.OldImage.price.N",
},
},
},
Expand All @@ -93,16 +100,23 @@ export const itemStream = {
Type: "Task",
Resource: "arn:aws:states:::dynamodb:updateItem",
Parameters: {
TableName: "MyDynamoDBTable",
TableName: getRef(WeddingTable),
Key: {
Column: {
S: "MyEntry",
pk: {
"S.$": "States.Format('LIST#{}',$.NewImage.listId.S)",
},
sk: {
"S.$": "States.Format('LIST#{}',$.NewImage.listId.S)",
},
},
UpdateExpression: "SET MyKey = :myValueRef",
UpdateExpression:
"SET totalPrice = totalPrice - :itemPrice, totalItems = totalItems - :one",
ExpressionAttributeValues: {
":myValueRef": {
S: "MyValue",
":itemPrice": {
"N.$": "$.NewImage.price.N",
},
":one": {
N: "1",
},
},
},
Expand Down
5 changes: 5 additions & 0 deletions src/types/extendedSlsTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ export function getJoin(delimiter: string, stringsList: string[]): string {
return { "Fn::Join": [delimiter, stringsList] } as unknown as string;
}

/**
* Returns a CF reference as string
* @param name string
* @returns string
*/
export function getRef(name: string): string {
return { Ref: name } as unknown as string;
}
Expand Down

0 comments on commit c557e39

Please sign in to comment.