How do I implement human approval steps in automated workflows with AWS Step Functions activities?
In this guide, we will implement human approval steps in an automated workflow using AWS Step Functions activities. AWS Step Functions allow you to coordinate multiple AWS services into serverless workflows, and by incorporating human approval steps, you can ensure that critical decisions are reviewed by a human before proceeding.
The workflow will include an activity that requires human approval. This activity will pause the execution of the workflow until an external signal (human approval) is received.
Key Points:
- Define an AWS Step Functions activity.
- Create a state machine that includes a human approval step.
- Demonstrate how to signal the activity to resume execution.
import * as aws from "@pulumi/aws";
import * as awsNative from "@pulumi/aws-native";
import * as pulumi from "@pulumi/pulumi";
// Create an IAM role for Step Functions
const role = new aws.iam.Role("stepFunctionsRole", {
assumeRolePolicy: aws.iam.assumeRolePolicyForPrincipal({
Service: "states.amazonaws.com",
}),
});
// Attach the AWS managed policy for Step Functions to the role
new aws.iam.RolePolicyAttachment("stepFunctionsRolePolicy", {
role: role.name,
policyArn: "arn:aws:iam::aws:policy/service-role/AWSStepFunctionsFullAccess",
});
// Create a Step Functions activity for human approval
const approvalActivity = new awsNative.stepfunctions.Activity("approvalActivity", {
name: "HumanApprovalActivity",
});
// Define the state machine
const stateMachineDefinition = {
Comment: "A state machine that includes a human approval step",
StartAt: "ApprovalStep",
States: {
ApprovalStep: {
Type: "Task",
Resource: approvalActivity.id.apply(id => `arn:aws:states:::lambda:invokeActivity:${id}`),
TimeoutSeconds: 300,
HeartbeatSeconds: 60,
Next: "NextStep",
},
NextStep: {
Type: "Pass",
End: true,
},
},
};
// Create the state machine
const stateMachine = new awsNative.stepfunctions.StateMachine("stateMachine", {
roleArn: role.arn,
definitionString: JSON.stringify(stateMachineDefinition),
stateMachineName: "HumanApprovalStateMachine",
});
// Export the ARN of the state machine
export const stateMachineArn = stateMachine.arn;
Summary
In this guide, we created an AWS Step Functions activity and a state machine that includes a human approval step. The state machine pauses execution at the approval step until a human provides the necessary approval, ensuring critical decisions are reviewed before proceeding. The use of Pulumi simplifies the deployment and management of this infrastructure.
Deploy this code
Want to deploy this code? Sign up for a free Pulumi account to deploy in a few clicks.
Sign upNew to Pulumi?
Want to deploy this code? Sign up with Pulumi to deploy in a few clicks.
Sign upThank you for your feedback!
If you have a question about how to use Pulumi, reach out in Community Slack.
Open an issue on GitHub to report a problem or suggest an improvement.