본문 바로가기

운영체제

[aws] s3 버킷 삭제 안될때 python 사용

목표 : 버킷 삭제

문제점

 - 홈페이지에서 삭제시 객체가 있어서 삭제가 안된다고 나옴

 - 객체 삭제 실행해도 삭제가 안됨

 - 홈페이지에서 삭제 실패


OS

macOS 12.3.1 ( M1 )


 

최종 해결 방법

 - aws cli 접근을 위해 사용자 발급

 - awscli 설치 

 - awscli 연결 설정

 - python3.6 설치

 - python 라이브러리 AWS SDK (boto3==1.9.66) 사용

 - 아래 python 코드 실행

#!/usr/bin/env python
import boto3

s3 = boto3.resource('s3')
bucket = s3.Bucket('photo-album') # 자신의 버킷 이름
bucket.object_versions.all().delete()
 - aws 들어가면 모든 폴더 등은 사라지고 버킷만 남아 있음
 - photo-album만 있어 삭제 가능해짐
 
참고 정보

https://stackoverflow.com/a/41399166

 

How do I delete a versioned bucket in AWS S3 using the CLI?

I have tried both s3cmd: $ s3cmd -r -f -v del s3://my-versioned-bucket/ And the AWS CLI: $ aws s3 rm s3://my-versioned-bucket/ --recursive But both of these commands simply add DELETE markers t...

stackoverflow.com

 

시도해본 정보

awscli로 삭제해보려 했느나 (실패)

$ aws s3 rb s3://photo-album --force
remove_bucket failed: s3://photo-album 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.

위와같은 결과를 받음