> For the complete documentation index, see [llms.txt](https://developer.harness.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developer.harness.io/continuous-delivery/3.0/use-deployments/overview-2/serverless-package/serverless-rollback.md).

# Serverless Rollback

Restore a Serverless Lambda CloudFormation stack to its previous state when a deployment fails.

The Serverless Rollback step restores the AWS CloudFormation stack for your Serverless service to the state it was in before the failed deployment. Harness adds this step to the rollback section of the stage automatically when you select the **Serverless Deployment With Rollback Strategy**. Toggle **Rollback** in the stage **Execution** view to see and configure it.

***

### What you will learn <a href="#what-you-will-learn" id="what-you-will-learn"></a>

* The parameters available on the Serverless Rollback step.
* How the Rollback step restores the CloudFormation stack to its pre-deployment state.
* The difference between Harness rollback and `serverless rollback`.

***

### Before you begin <a href="#before-you-begin" id="before-you-begin"></a>

Ensure the following are in place before adding this step to your stage:

* The stage must have a failure strategy set to **Stage Rollback** (the default when using the rollback strategy). Without this, the Rollback step is never triggered.
* The Deploy step must have started. The platform captures the prior stack state automatically before the Deploy step runs. Without this, there is nothing to roll back to.

***

### Configure the step <a href="#configure-the-step" id="configure-the-step"></a>

The following parameters are available on the Serverless Rollback step.

| Parameter                 | Required | Description                                                                                   |
| ------------------------- | -------- | --------------------------------------------------------------------------------------------- |
| **Name**                  | Yes      | Display name for this step in the stage canvas. Default: `Serverless Aws Lambda Rollback V2`. |
| **Container Registry**    | Yes      | A Harness Docker Registry connector pointing to the registry that hosts the step image.       |
| **Image**                 | Yes      | The `harness/serverless-plugin` image and tag to use. Use the same image as the Deploy step.  |
| **Pre-Execute Command**   | No       | Shell command that runs before the step logic, for example `npm install`.                     |
| **Environment Variables** | No       | Key-value pairs injected into the container.                                                  |

***

### How the step works <a href="#how-it-works" id="how-it-works"></a>

Before the Deploy step runs, the platform automatically captures the current CloudFormation stack state. If the Deploy step fails, Harness triggers the Rollback step, which:

1. Reads the CloudFormation stack state captured before the Deploy step ran.
2. Sets up AWS credentials from the connector in the infrastructure definition.
3. Calls the AWS CloudFormation API to restore the stack to the saved state, including stack parameters, policy, capabilities, and role ARN.

The following special cases apply:

* **First deployment:** If no prior CloudFormation stack existed when the Deploy step ran (first-time deployment), there is no stack state to restore. The Rollback step logs a message and exits without taking action. Delete the incomplete stack manually from the AWS CloudFormation console before retrying.
* **Deploy step never reached:** If the pipeline was cancelled or failed before the Deploy step started, no stack state was captured. The Rollback step skips with a message indicating the deploy phase did not run.

***

### Rollback vs Serverless CLI rollback <a href="#comparison" id="comparison"></a>

The Serverless CLI `serverless rollback --timestamp` command requires you to identify the deployment timestamp manually. With multiple developers deploying to the same stage, this can produce the wrong rollback target.

Harness eliminates this by capturing the exact stack state before each deployment begins and using that saved state as the rollback target automatically. No timestamp is needed.

***

### Next steps <a href="#next-steps" id="next-steps"></a>

* Go to [Serverless deployment](/continuous-delivery/3.0/use-deployments/overview-2/serverless-deployment.md) to review the full execution flow

{% @harness-feedback/feedback %}
