-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
create INSERT ddb query for step function
- Loading branch information
Showing
4 changed files
with
156 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import { merge } from "lodash"; | ||
|
||
import { incStream } from "./itemStream"; | ||
import { itemStream } from "./itemStream"; | ||
|
||
export const stepFunctions = merge(incStream); | ||
export const stepFunctions = merge(itemStream); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,115 @@ | ||
export const incStream = { | ||
import { WeddingTable } from "../resources/ddb"; | ||
import { getRef, idHelper, nameHelper } from "../types/extendedSlsTypes"; | ||
|
||
export const ItemStream = "ItemStream"; | ||
|
||
export const itemStream = { | ||
stateMachines: { | ||
incStream: { | ||
name: "incStream", | ||
definition: {}, | ||
[ItemStream]: { | ||
id: idHelper(ItemStream), | ||
name: nameHelper(ItemStream), | ||
type: "EXPRESS", | ||
useExactVersion: true, | ||
definition: { | ||
Comment: "Update List totals ( price and total items )", | ||
StartAt: "Check event type", | ||
States: { | ||
"Check event type": { | ||
Type: "Choice", | ||
Choices: [ | ||
{ | ||
Variable: "$.eventName", | ||
StringEquals: "INSERT", | ||
Next: "Increment totalPrice and totalItems", | ||
}, | ||
{ | ||
Variable: "$.eventName", | ||
StringEquals: "MODIFY", | ||
Next: "Compute price difference", | ||
}, | ||
{ | ||
Variable: "$.eventName", | ||
StringEquals: "REMOVE", | ||
Next: "Decrease totalPrice and totalItems", | ||
}, | ||
], | ||
OutputPath: "$.dynamodb", | ||
Default: "Fail", | ||
}, | ||
"Compute price difference": { | ||
Type: "Pass", | ||
Next: "Update totalPrice", | ||
}, | ||
"Increment totalPrice and totalItems": { | ||
Type: "Task", | ||
Resource: "arn:aws:states:::dynamodb:updateItem", | ||
Parameters: { | ||
TableName: getRef(WeddingTable), | ||
Key: { | ||
pk: { | ||
"S.$": "States.Format('LIST#{}',$.NewImage.listId.S)", | ||
}, | ||
sk: { | ||
"S.$": "States.Format('LIST#{}',$.NewImage.listId.S)", | ||
}, | ||
}, | ||
UpdateExpression: | ||
"SET totalPrice = totalPrice + :itemPrice, totalItems = totalItems + :addOne", | ||
ExpressionAttributeValues: { | ||
":itemPrice": { | ||
"N.$": "$.NewImage.price.N", | ||
}, | ||
":addOne": { | ||
N: "1", | ||
}, | ||
}, | ||
}, | ||
End: true, | ||
}, | ||
Fail: { | ||
Type: "Fail", | ||
Error: "Missing EventType", | ||
}, | ||
"Update totalPrice": { | ||
Type: "Task", | ||
Resource: "arn:aws:states:::dynamodb:updateItem", | ||
Parameters: { | ||
TableName: "MyDynamoDBTable", | ||
Key: { | ||
Column: { | ||
S: "MyEntry", | ||
}, | ||
}, | ||
UpdateExpression: "SET MyKey = :myValueRef", | ||
ExpressionAttributeValues: { | ||
":myValueRef": { | ||
S: "MyValue", | ||
}, | ||
}, | ||
}, | ||
End: true, | ||
}, | ||
"Decrease totalPrice and totalItems": { | ||
Type: "Task", | ||
Resource: "arn:aws:states:::dynamodb:updateItem", | ||
Parameters: { | ||
TableName: "MyDynamoDBTable", | ||
Key: { | ||
Column: { | ||
S: "MyEntry", | ||
}, | ||
}, | ||
UpdateExpression: "SET MyKey = :myValueRef", | ||
ExpressionAttributeValues: { | ||
":myValueRef": { | ||
S: "MyValue", | ||
}, | ||
}, | ||
}, | ||
End: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters