How to delete all services deployed with Serverless Framework

Tadashi Shigeoka ·  Tue, January 8, 2019

The command to delete services deployed with Serverless Framework is serverless remove.

Serverless Framework

serverless remove usage example

Here’s an example of executing the serverless remove command:

$ serverless remove --verbose

Serverless: Getting all objects in S3 bucket...
Serverless: Removing objects in S3 bucket...
Serverless: Removing Stack...
Serverless: Checking Stack removal progress...
CloudFormation - DELETE_IN_PROGRESS - AWS::CloudFormation::Stack - sample-dev
CloudFormation - DELETE_SKIPPED - AWS::Lambda::Version - SampleLambdaVersionherATbCzQsAa56CUCz1peOcJkoURkXVhc6y5bou9s8
CloudFormation - DELETE_IN_PROGRESS - AWS::Lambda::Permission - SampleLambdaPermissionEventsRuleSchedule1
CloudFormation - DELETE_SKIPPED - AWS::DynamoDB::Table - WebsitesTable
CloudFormation - DELETE_IN_PROGRESS - AWS::S3::Bucket - S3BucketResource
CloudFormation - DELETE_FAILED - AWS::S3::Bucket - S3BucketResource
CloudFormation - DELETE_COMPLETE - AWS::Lambda::Permission - SampleLambdaPermissionEventsRuleSchedule1
CloudFormation - DELETE_IN_PROGRESS - AWS::Events::Rule - SampleEventsRuleSchedule1
CloudFormation - DELETE_COMPLETE - AWS::Events::Rule - SampleEventsRuleSchedule1
CloudFormation - DELETE_IN_PROGRESS - AWS::Lambda::Function - SampleLambdaFunction
CloudFormation - DELETE_COMPLETE - AWS::Lambda::Function - SampleLambdaFunction
CloudFormation - DELETE_IN_PROGRESS - AWS::IAM::Role - IamRoleLambdaExecution
CloudFormation - DELETE_IN_PROGRESS - AWS::S3::Bucket - ServerlessDeploymentBucket
CloudFormation - DELETE_IN_PROGRESS - AWS::Logs::LogGroup - SampleLogGroup
CloudFormation - DELETE_COMPLETE - AWS::S3::Bucket - ServerlessDeploymentBucket
CloudFormation - DELETE_COMPLETE - AWS::Logs::LogGroup - SampleLogGroup
CloudFormation - DELETE_COMPLETE - AWS::IAM::Role - IamRoleLambdaExecution
CloudFormation - DELETE_FAILED - AWS::CloudFormation::Stack - sample-dev
Serverless: Operation failed!
 
  Serverless Error ---------------------------------------
 
  An error occurred: S3BucketResource - The bucket you tried to delete is not empty (Service: Amazon S3; Status Code: 409; Error Code: BucketNotEmpty; Request ID: xxxx; S3 Extended Request ID: xxxx).
 
  Get Support --------------------------------------------
     Docs:          docs.serverless.com
     Bugs:          github.com/serverless/serverless/issues
     Issues:        forum.serverless.com
 
  Your Environment Information -----------------------------
     OS:                     darwin
     Node Version:           8.10.0
     Serverless Version:     1.35.1

As shown in the DELETE_SKIPPED and DELETE_FAILED output, these three couldn’t be deleted:

  • DELETE_SKIPPED: DynamoDB Table with DeletionPolicy: Retain already set
  • DELETE_FAILED: S3 Bucket used as file storage destination in Lambda function
  • DELETE_FAILED: CloudFormation stack

The resources couldn’t be deleted, so the CloudFormation stack also couldn’t be deleted as a result.

How to handle AWS resources that couldn't be deleted

I deleted the DynamoDB Table, S3 Bucket, and CloudFormation that couldn’t be deleted from the AWS Console respectively.

If there’s a way to delete these from serverless commands without deleting from the AWS Console, please let me know.

That’s all from the Gemba where I want to delete all services deployed with Serverless Framework.