serverless: The bucket you tried to delete is not empty.

This is a (Bug Report)

Description

When trying to deploy a lambda function with an s3 bucket based trigger, the following error was shown.

Serverless Error ---------------------------------------
  An error occurred: S3BucketNylndatestings - The bucket you tried to delete is not empty.

For bug reports:

Serverless: Packaging service...
Serverless: Excluding development dependencies...
Serverless: Uploading CloudFormation file to S3...
Serverless: Uploading artifacts...
Serverless: Uploading service .zip file to S3 (24.49 MB)...
Serverless: Validating template...
Serverless: Updating Stack...
Serverless: Checking Stack update progress...
.......
Serverless: Operation failed!
 
  Serverless Error ---------------------------------------
 
  An error occurred: S3BucketNylndatestings - The bucket you tried to delete is not empty.

The following was the yml setu used.

service: aws-nodejs 
plugins:
  - serverless-offline
  - serverless-plugin-existing-s3
provider:
  name: aws
  stage: dev
  region: us-east-1
  profile: default
  runtime: nodejs6.10
  memorySize: 256
  timeout: 30
  environment:


  iamRoleStatements:
    - Effect: "Allow"
      Action:
        - "sns:*"
      Resource: "*"
    - Effect: "Allow"
      Action:
        - "s3:*"
      Resource:
       Fn::Join:
        - ""
        - - "*"
custom:
  ACCOUNT_ID: "338135766024"
  MEDIA_BUCKET: "nylndamedia-dev-bucket"
functions:
  cool:
    handler: handler.cool
    events:
      - existingS3:
          bucket: nylnda-testing-s3
#          bucket: nylndamedia-dev-bucket
          event: s3:ObjectCreated:PUT
          rules:
            - prefix: Reaction/Videos/

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 10
  • Comments: 33 (7 by maintainers)

Most upvoted comments

This issue is present in version 1.43.0

any news?

The issue is still present in 1.66.0!

The issue is also present in version 1.54.0

Got the same issue when I’ve added provider.deploymentBucket.name to serverless.yml

An error occurred: ServerlessDeploymentBucket - The bucket you tried to delete is not empty (Service: Amazon S3; Status Code: 409; Error Code: BucketNotEmpty

Upd. upgrade serverless to 1.39.1 version solved the problem

Thanks for providing more insights @bityob - I’ve managed to reproduce it and it seems like the issue here is that the deleteObjects does not throw on errors but rather returns a valid response and includes errors there. I will prepare a PR with a fix that provides more actionable error information.

In my case I cannot delete S3 bucket @vsuzdaltsev 😦

The issue is still present in 1.67.0

In my case, the serverless deployment bucket had a lot of objects worth closer to 100 GB, and S3 won’t allow deleting a bucket unless you empty it out. Emptying a bucket is a bit time-consuming activity which I ended up doing manually.

Still happens in 3.0.1 version

user@host $ sls remove --stage testing-us-east-2
Removing service-name from stage testing-us-east-2 (us-east-2)
Environment: linux, node 16.13.2, framework 3.0.1 (local), plugin 6.0.0, SDK 4.3.0
Credentials: Local, environment variables
Docs:        docs.serverless.com
Support:     forum.serverless.com
Bugs:        github.com/serverless/serverless/issues

Error:
DELETE_FAILED: ServerlessDeploymentBucket (AWS::S3::Bucket)
The bucket you tried to delete is not empty (Service: Amazon S3; Status Code: 409; Error Code: BucketNotEmpty...```

Any known workaround without deleting the bucket?

Hi @SandeepVattapparambil . The existingS3 event type seems to be added by the serverless-plugin-existing-s3 plugin. I think the issue is related with that and there is a bug in case of removing the service. Serverless core does not handle that, so please check if there is already an issue in the plugin’s GitHub repository.