Starting the execution of the Step Function State Machine via AWS Console to call the DynamoDB APIs from a Task state. The State Machine accepts values in a JSON format (please see sample payload) and will execute the specific DynamoDB API depending on the input received.
{
"StartAt": "transaction-type",
"States": {
"transaction-type": {
"Type": "Choice",
"Choices": [
{
"Variable": "$.transaction_type",
"StringEquals": "delete",
"Next": "delete-user"
},
{
"Variable": "$.transaction_type",
"StringEquals": "insert",
"Next": "insert-user"
},
{
"Variable": "$.transaction_type",
"StringEquals": "update:username",
"Next": "update-username"
},
{
"Variable": "$.transaction_type",
"StringEquals": "update:password",
"Next": "update-password"
}
]
},
"delete-user": {
"End": true,
"Type": "Task",
"ResultPath": null,
"Resource": "arn:aws:states:::dynamodb:deleteItem",
"Parameters": {
"Key": {
"ID": {
"S.$": "$.id"
}
},
"TableName": "users-table"
}
},
"insert-user": {
"End": true,
"Type": "Task",
"Resource": "arn:aws:states:::dynamodb:putItem",
"Parameters": {
"Item": {
"ID": {
"S.$": "$.id"
},
"Username": {
"S.$": "$.username"
},
"Password": {
"S.$": "$.password"
},
"FirstName": {
"S.$": "$.first_name"
},
"LastName": {
"S.$": "$.last_name"
},
"Role": {
"S.$": "$.role"
}
},
"TableName": "users-table"
}
},
"update-username": {
"End": true,
"Type": "Task",
"Resource": "arn:aws:states:::dynamodb:updateItem",
"Parameters": {
"Key": {
"ID": {
"S.$": "$.id"
}
},
"TableName": "users-table",
"ConditionExpression": "attribute_exists(ID)",
"ExpressionAttributeValues": {
":username": {
"S.$": "$.username"
}
},
"UpdateExpression": "SET Username = :username"
}
},
"update-password": {
"End": true,
"Type": "Task",
"Resource": "arn:aws:states:::dynamodb:updateItem",
"Parameters": {
"Key": {
"ID": {
"S.$": "$.id"
}
},
"TableName": "users-table",
"ConditionExpression": "attribute_exists(ID)",
"ExpressionAttributeValues": {
":password": {
"S.$": "$.password"
}
},
"UpdateExpression": "SET Password = :password"
}
}
}
}
{
"transaction_type": "insert",
"id": "1642023-92618",
"username": "j.doe",
"password": "JohnDoe12345",
"first_name": "John",
"last_name": "Doe",
"role": "Admin"
}
{
"transaction_type": "update:username",
"id": "1642023-92618",
"username": "j.doenut.27"
}
{
"transaction_type": "update:password",
"id": "1642023-92618",
"password": "doenut.john"
}
{
"transaction_type": "delete",
"id": "1642023-92618"
}
- States
- Amazon States Language
- AWS Step Function Guides
- Input and Output Processing in Step Functions
npm run build
compile typescript to jsnpm run watch
watch for changes and compilenpm run test
perform the jest unit testscdk deploy
deploy this stack to your default AWS account/regioncdk diff
compare deployed stack with current statecdk synth
emits the synthesized CloudFormation template
-
Install all the dependencies, bootstrap your project, and synthesized CloudFormation template.
# Without passing "profile" parameter dev@dev:~:aws-cdk-samples/step-functions/step-functions-dynamodb$ make init # With "profile" parameter dev@dev:~:aws-cdk-samples/step-functions/step-functions-dynamodb$ make init profile=[profile_name]
-
Deploy the project.
# Without passing "profile" parameter dev@dev:~:aws-cdk-samples/step-functions/step-functions-dynamodb$ make deploy # With "profile" parameter dev@dev:~:aws-cdk-samples/step-functions/step-functions-dynamodb$ make deploy profile=[profile_name]