serverless remove Command Reference
Tear down a deployed Serverless Framework service stack.
serverless remove deletes the CloudFormation stack and associated resources for a service stage. It is the cleanup command for ephemeral preview or per-branch environments.
What it does
serverless remove deletes the CloudFormation stack for the targeted stage, removing functions, events, and managed resources. It is the inverse of serverless deploy and is commonly wired to PR-close events for preview cleanup.
Common flags and usage
- --stage STAGE: the stage to remove (be deliberate here)
- --region REGION: target AWS region
- --verbose: stream detailed removal progress
- --conceal: hide secrets from output
Example
- name: Tear down preview env
if: github.event.action == 'closed'
env:
AWS_REGION: us-east-1
run: npx serverless remove --stage "pr-${{ github.event.number }}" --region us-east-1In CI
Trigger serverless remove on pull-request close to clean up per-branch preview stacks and avoid orphaned resources accruing cost. Always pass --stage explicitly and guard the job so it can never run against prod; a stray removal is destructive and not reversible.
Key takeaways
- serverless remove deletes the entire service stack for a stage.
- Wire it to PR-close events to clean up ephemeral preview environments.
- Guard --stage carefully; removal is destructive and not reversible.