DEV Community

Shivang Chauhan
Shivang Chauhan

Posted on • Originally published at devswisdom.com on

AWS Step Functions Most Used Nodejs SDK APIs

Introduction

In this post, I will be listing some of the most important AWS Nodejs SDK APIs for AWS Step Functions, we will go through the syntax and brief explanation of each of these APIs.

You might want to check out this AWS Step Functions Cheatsheet to know about the most used AWS CLI Commands used with explanations.

Most Important APIs

APIs syntax will be given in a format of Lambda function so it can be directly used.

Create State Machine

exports.createStateMachine = async (event) => {
  try {
    const params = {
      definition: '<String>',
      name: '<String>',
      roleArn: '<String>'
    };
    const data = await stepfunctions.createStateMachine(params).promise();
    console.log(data);
  }
  catch (error) {
    console.log(error)
    // Do something with the error
  }
};
Enter fullscreen mode Exit fullscreen mode

Explanation

createStateMachine API is used to create a state machine.

name – This is the name of the state machine.

definition – This is the stringified JSON which will contain all the configuration and state machine steps with their respective configuration.

role-arn – This is the ARN of the role which you need to create, role policies will depend on what actions you want to perform in your state machine.

Know more

Describe The Execution

exports.describeExecution = async (event) => {
  try {
    const params = {
      executionArn: '<String>'
    };
    const data = await stepfunctions.describeExecution(params).promise();
    console.log(data);
  }
  catch (error) {
    console.log(error)
    // Do something with the error
  }
};
Enter fullscreen mode Exit fullscreen mode

Explanation

describeExecution API returns the execution details of any executed state machine, it returns important data like inputs passed while starting the execution, the current status of the execution, start date and end date of the execution, and other data as well.

Know more

Start The State Machine Execution

exports.startExecution = async (event) => {
  try {
    const params = {
      stateMachineArn: '<string>',
      input: '<string>',
      name: '<string>'

    };
    const data = await stepfunctions.startExecution(params).promise();
    console.log(data);
  }
  catch (error) {
    console.log(error)
    // Do something with the error
  }
};
Enter fullscreen mode Exit fullscreen mode

Explanation

startExecution API is used to start the execution of any state machine which will run our AWS Step Functions, it has some of the important parameters

state-machine-arn - This is our ARN for the created state machine.

input - This is the initial stringified JSON that is passed to our state machine as input data.

Know more

Stop The State Machine Execution

exports.stopExecution = async (event) => {
  try {
    const params = {
      executionArn: '<string>',
      cause: '<string>'
    };
    const data = await stepfunctions.stopExecution(params).promise();
    console.log(data);
  }
  catch (error) {
    console.log(error)
    // Do something with the error
  }
};
Enter fullscreen mode Exit fullscreen mode

Explanation

stopExecution API is used to stop any running state machine.

execution-arn – This is our ARN of the execution of the state machine, when we start any state machine this ARN gets returned to us.

Know more

Conclusion

These are some of the most important and most used AWS Step Functions Nodejs SDK APIs, I tried to keep it as simple as I could, to know more about these APIs please visit the official AWS documentation links mentioned in this post.

To learn about a practical application of AWS Step Functions using Nodejs and AWS Serverless Framework read this guide

Extract text with AWS Textract using AWS Step functions

Check out more posts like AWS Cognito Pricing and Features – 2021

The post AWS Step Functions Most Used Nodejs SDK APIs appeared first on DevsWisdom.

Top comments (0)