AWS Step Functions Most Used Nodejs SDK APIs
Tags: aws, serverless, node, programming
Published: 2021-11-18 10:35:54

---
title: AWS Step Functions Most Used Nodejs SDK APIs
published: true
date: 2021-11-18 09:24:05 UTC
tags: AWS,serverless,nodejs,programming
canonical_url: https://devswisdom.com/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](https://devswisdom.com/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**

```javascript
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
  }
};
```

#### **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](https://docs.aws.amazon.com/step-functions/latest/apireference/API_CreateStateMachine.html)

### **Describe The Execution**

```javascript
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
  }
};
```

#### **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](https://docs.aws.amazon.com/step-functions/latest/apireference/API_DescribeExecution.html)

### **Start The State Machine Execution**

```javascript
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
  }
};
```

#### **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](https://docs.aws.amazon.com/step-functions/latest/apireference/API_StartExecution.html)

### **Stop The State Machine Execution**

```javascript
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
  }
};
```

#### **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](https://docs.aws.amazon.com/step-functions/latest/apireference/API_StopExecution.html)

## **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](https://devswisdom.com/extract-text-with-aws-textract-using-aws-step-functions/)

Check out more posts like [AWS Cognito Pricing and Features – 2021](https://devswisdom.com/aws-cognito-pricing-and-features-2021/)

The post [AWS Step Functions Most Used Nodejs SDK APIs](https://devswisdom.com/aws-step-functions-most-used-nodejs-sdk-apis/) appeared first on [DevsWisdom](https://devswisdom.com).