Can't Delete Empty S3 Bucket - amazon-web-services

I have an S3 bucket that is 100% empty. Versioning was never enabled on the bucket. However, I still cannot remove the bucket. I have tried via the Console and the CLI tool. On the console it just says "Error" with no error message. From the cli and api it tells me: "An error occurred (BucketNotEmpty) when calling the DeleteBucket operation: The bucket you tried to delete is not empty". I have tried all of the following:
aws s3 rb s3://<bucket_name> --force -> BucketNotEmpty
aws s3 rm s3://<bucket_name> --recursive -> No output (because it's already empty)
aws s3api list-object-versions --bucket <bucket_name> -> No output (because versioning was never enabled)
aws s3api list-multipart-uploads --bucket <bucket_name> -> No outputs
aws s3api list-objects --delimiter=/ --prefix= --bucket <bucket_name> -> No Output (because it's empty)
It has no dependencies (it's not used by cloudfront or anything else that I'm aware of).
The bucket has been empty for approximately 5 days.
I was able to delete another very similar bucket with the same IAM user. Additionally my IAM user has Admin access.

I was facing this same problem. I was able to fix the issue by going into the bucket and deleting the "Bucket Policy" for the bucket. After that, deleting the bucket worked correctly.
I did this through the AWS console, for an S3 bucket created by Elastic Beanstalk (ie elasticbeanstalk-us-west-2-861587641234). I imagine the creation script includes a policy to prevent people from accidentally deleting the bucket.

I had a similar issue and was able to delete the bucket after waiting overnight.
It's a pretty weak solution but may save you and other some time from pounding on it.
If it's still not deleting after all the actions in the comments there are some things that only AWS support can fix properly. Again a weak answer but register a ticket with AWS support and then post their response here as an answer for others.

To delete an Elastic Beanstalk storage bucket (console)
1. Open the Amazon S3 Management Console
2. Select the Elastic Beanstalk storage bucket.
3. Choose Properties.
4. Choose Permissions.
5. Choose Edit Bucket Policy - Allow to delete and make it public.
6. Save.
7. Choose Actions and then choose Delete Bucket.
8, Type the name of the bucket and then choose Delete.

This is what had worked for me. I didn't have versioning enabled on the bucket. When you delete an object from s3 bucket, it puts a 'delete marker' on that object and hides it from the listing. When you click 'show' version button you will see your deleted objects with the delete marker. Select this object (with delete marker) and delete again. This is a permanent delete. Now your object is really gone and your bucket is really empty. After this I was able to delete my bucket.
I guess, versioning=true only means that s3 will create versions of the object if you upload with the same name.

For users who are facing similar issue.
I tried #Federico solution still no success. There was an other option "Empty" next to delete.
So I emptied the bucket first and then tried delete, it worked.

I was facing an issue with deleting the Elastic Beanstalk storage bucket.
Follow the below steps:
1. Select the Elastic Beanstalk storage bucket.
2. Choose Permissions.
3. Delete the bucket policy
4. Save.
If your bucket is empty, you can delete the bucket.

Sometimes after attempting to delete a bucket, it's not actually deleted, but the permissions are lost.
In my case, I went to the "permissions" tab, re-granted permissions to myself, and was then able to remove it

I had the same issue and there was not a policy, so added permission for the email I was logged in with and saved. After granting myself permission I was able to delete the bucket. I also had another bucket that had a policy, so I delete the policy and was able to delete that bucket as well.

Using aws cli :
# delete contents of a bucket
aws s3api delete-objects --bucket nameOfYourBucket --delete "$(aws s3api list-object-versions --bucket nameOfYourBucket --query='{Objects: Versions[].{Key:Key,VersionId:VersionId}}')"
# delete older version files from bucket
aws s3api delete-objects --bucket nameOfYourBucket --delete "$(aws s3api list-object-versions --bucket nameOfYourBucket --query='{Objects: DeleteMarkers[].{Key:Key,VersionId:VersionId}}')"
And then you can delete the bucket.

i made the s3 bucket permission to public, and gave access to everyone. Then i was able to delete the Bucket from the AWS console.

I am using the AWS Console to perform deletion of the bucket.
had the same problem and I tried all the above solutions and not worked for me then I figured out another way.
My bucket was used by ElasticBean and whenever I deleted the bucket the ElasticBean created one automatically. I then deleted the ElasticBean service and tried to delete the bucket again but not worked again this time, the bucket was empty but was not allowing to delete.
I tried to change permissions but the bucket was still there.
Finally I deleted the bucket policy and came back and deleted the bucket and it was gone.
Problem solved

I tried to look at many of the solutions mentioned. The only thing that worked for me is deleting it through Cyberduck (I neither work for nor am promoting Cyberduck, i genuinely used it and it worked). Here are the steps of what I did:
1 - Download and install Cyberduck.
2 - Click on Open Connection
3 - Select Amazon S3 from the dropdown (default would be FTP)
4 - Enter your access key ID and secret Access key (if you dont have one then you need to create one on your s3 bucket through IAM on AWS)
5 - You will see a list your S3 buckets. Select the file or folder or bucket you want to delete, right click and delete. Even files with 0kb show up here and can be deleted.
Hope this helps

Related

Bucket created by EBS (Elastic Beanstalk) cannot be deleted

I tried the Elastic Beanstalk(EBS) to practice my learning and quickly I deleted it. However, I see there is an S3 bucket created by this EBS service during its launch, is still existing though everything else (like Ec2) is deleted on its on while I deleted the EBS in my account. I want to delete this S3 too, but it gives error while deleting: "Insufficient permissions to delete bucket" After you or your AWS admin have updated your IAM permissions to allow s3:DeleteBucket, choose delete bucket. API response -Access Denied
I created EBS and deleted under my root account. I am still under my root account while trying to delete S3 but I get this error. Can someone pls advise, what I am missing here because I did not used any S3 Role as it points in its error message. Any help pls?
In the S3 dashboard, select the bucket you want to delete
Select the "Permissions" tab.
Navigate to the Bucket Policies & delete the policy
It is the bucket policy created by EB that denies its deletion.
Once the policy is deleted, you will be able to delete the bucket as well.
**
To delete the bucket created by Beanstalk we need to modify the attached bucket policy created by beanstalk as it denies the delete action.
To allow the delete action we can either modify the policy and allow
the delete action or the easy way is to directly delete/remove the
policy.
If you want to delete the policy using python code you can check the
example given below.
Note: The below python code will delete all the buckets from your account. You can modify the code if you want to delete any specific bucket. You can download the credentials needed from the IAM service
import boto3
# authenticate s3 = boto3.resource('s3',
aws_access_key_id='ACCESS_KEY',
aws_secret_access_key='SECRET_ACCESS',
)
bucket = 'bucket_name'
# delete policy if bucket is created by beanstalk
bucket.Policy().delete()
# delete object versions
bucket.object_versions.delete()
# delete all the objects inside the bucket
bucket.objects.all().delete()
# delete the bucket
bucket.delete()
print(bucket, ' deleted successfully!')

AWS S3 sync creates objects with different permissions than bucket

I'm trying to use an S3 bucket to upload files to as part of a build, it is configured to provide files as a static site and the content is protected using a Lambda and CloudFront. When I manually create files in the bucket they are all visible and everything is happy, but when the files are uploaded what is created are not available, resulting in an access denied response.
The user that's pushing to the bucket does not belong in the same AWS environment, but it has been set up with an ACL that allows it to push to the bucket, and the bucket with a policy that allows it to be pushed to by that user.
The command that I'm using is:
aws s3 sync --no-progress --delete docs/_build/html "s3://my-bucket" --acl bucket-owner-full-control
Is there something else that I can try that basically uses the bucket permissions for anything that's created?
According to OP's feedback in the comment section, setting Object Ownership to Bucket owner preferred fixed the issue.

Unable to delete S3 bucket as it does not exist

Brand new AWS account today, created a bucket to host static webpages.
Created via the web interface and configured it to be open to public (could access the page through "bucket-name.s3-website.eu-west-2.amazonaws.com")
I clicked to delete the bucket via the interface and nothing happened.
It's worth noting that since then clicking the bucket and navigating through the config no shows "No data" errors on the UI. The bucket policy section is empty.
Trying to add myself back into the properties as per -Unable to delete S3 bucket
gives me "an unexpected error occurred".
It shows the following properties when you click on the bucket
Events 0 Active notifications
Versioning -
MFA delete -
Logging Disabled
Static web hosting Disabled
Tags 0 Tags
Requester pays Disabled
Object lock Disabled
Transfer acceleration Disabled
Permissions
Owner REDACTED
Block public access Disabled
Bucket policy No
Access control list 0 Grantees
CORS configuration No
Management
Lifecycle Disabled
Replication Disabled
Analytics Disabled
Inventory Disabled
Metrics Disabled
Tried via the cli
aws s3 rb s3://bucket-name --force --debug
aws s3api delete-bucket --bucket bucket-name
aws s3api get-bucket-policy-status --bucket bucket-name
which tells me the bucket does not exist
fatal error: An error occurred (NoSuchBucket) when calling the ListObjectsV2 operation: The specified bucket does not exist
remove_bucket failed: Unable to delete all objects in the bucket, bucket will not be deleted.
Back to the web interface I have tried creating a new bucket with the same name but it blocks me as it already exists.
Looking around online seems to indicate it's either because there is no longer a region specified or alternatley that it is simply taking a while to reflect that it has been deleted, but I have since created and deleted other buckets without issue.
Update: Bucket disappeared of its own accord after around 20 hours. For anyone experiencing similar problems it appears patience is your only option.

Deleting Versions in S3 Bucket AWS

I am unable to delete a bucket with 160million+ versions that were created by a bug that was updating a profile picture and since we had versioning set up it caused a heap of a mess. I tried to use the AWS website to delete the versions and delete the s3 bucket but the auth token expires before it runs through all the files and signs me out of AWS. I then tried to use AWS CLI and am confronted with another issue. The command and error can be found below.
aws s3api delete-bucket --bucket pinch-profile-picture --region us-east-2
and received the following error:
An error occurred (BucketNotEmpty) when calling the DeleteBucket operation: The bucket you tried to delete is not empty. You must delete all versions in the bucket.
AWS does not want to touch or delete the bucket for us because they would be held liable for deleting something.
The following steps I might be able to take are:
1)Create a script to delete everything.
2)Figure out how to delete all the versions from CLI
3)Figure out how to not prevent our token from expiring on the site
4)"Insert your suggestion here"
..
99)manually delete but this is limited to 300 per page which would mean i would be required to delete 300 items 666,666 times if we created 200million versions. So thats a no-go.
But I am open to suggestions, what are your tips to getting the S3 bucket deleted along with the versions. If you've been in the situation before or have experience building scripts please help a brotha out.
Best Regards,
Akshay Kumar
If force-deleting the bucket doesn't work, you could Create a Lifecycle Policy for an S3 Bucket.
Configure it to delete all versions of objects and then, within 24 hours, the objects and versions will be gone!
You can then delete the bucket.
The remove bucket command with force option on a bucket that has versioning enabled will only add a delete marker to the version history and retains all other versions of that object. Your bucket will not be completely empty as object versions are still there and delete bucket command will fail.
To delete all object versions, you can turn show version option on and delete them individually. Of course, in your case with millions of versions in the bucket deleting individual version is not practical.
The following python code will do the job:
import boto3
session = boto3.Session()
s3 = session.resource(service_name='s3')
bucket = s3.Bucket('your-bucket-name')
bucket.object_versions.delete()
You can try this command:
aws s3 rb s3://mybucket --force
Force parameter: Remove all objects in the bucket and finally it
remove itself.
Read More

Get ARN of S3 Bucket with aws cli

Is it possible to get the ARN of an S3 bucket via the AWS command line?
I have looked through the documentation for aws s3api ... and aws s3 ... and have not found a way to do this.
It's always arn:PARTITION:s3:::NAME-OF-YOUR-BUCKET. If you know the name of the bucket and in which partition it's located, you know the ARN. No need to 'get' it from anywhere.
The PARTITION will be aws, aws-us-gov, or aws-cndepending on whether you're in general AWS, GovCloud, or China resepectively.
You can also select your S3 bucket ARN by selecting it using the tick mark at the s3 management console, which will pop up a Side bar. where there is a provision to copy your S3 bucket ARN.S3 management console with bucket ARN
aws articles spell out the arn format but never say go here to see it. Highlighting my s3 bucket and seeing that Copy Bucket ARN kept me sane for a few more hours.