Serverless Framework で deploy したサービスを全て削除する方法

Serverless Framework で deploy したサービスを削除するコマンドは serverless remove です。

Serverless Framework

serverless remove 利用例

serverless remove コマンドの実行例は以下の通りです。

$ 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

DELETE_SKIPPED, DELETE_FAILED の出力が表示されている通り、

  • DELETE_SKIPPED: DeletionPolicy: Retain を設定済みの DynamoDB Table
  • DELETE_FAILED: Lambda function 内でファイル保存先に利用していた S3 Bucket
  • DELETE_FAILED: CloudFormation のスタック

の3つは削除できませんでした。

リソース系が削除できず、削除できないため CloudFormation のスタックも削除できなかったという状況です。

削除できなかった AWS の対応方法

削除できなかった DynamoDB Table, S3 Bucket, CloudFormation はそれぞれ AWS Console から削除しました。

AWS Console から削除せず、これらも serverless コマンドから削除できる方法があれば、ぜひ教えてください。

以上、Serverless Framework で deploy したサービスを全て削除したい現場からお送りしました。