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
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
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
The following parameters are available on the Serverless Rollback step.
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
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:
Reads the CloudFormation stack state captured before the Deploy step ran.
Sets up AWS credentials from the connector in the infrastructure definition.
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
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
Go to Serverless deployment to review the full execution flow
Last updated
Was this helpful?