简体   繁体   中英

Random behaviour while deleting bucket from S3

I am working on the code that interacts with Aws s3 to perform various operations like create bucket, Delete bucket, upload and download files and so on. An issue is occurring while trying to delete the bucket; Access Denied

At present, I am using Root user credentials to create and delete the bucket. No versioning is enabled and could not see any bucket Policy in AWS Console attached to this bucket.

It is showing strange behaviour; sometimes gives access denied error while trying to delete the empty bucket , sometime it just gets delete effortlessly.

I am able to delete the bucket via AWs s3 console without any trouble. It is just through the code it is behaving random.

Can please somebody explain; what could be the reason?

here is my code

public string DeleteBucket(string bucketName, string S3Region)
{
    string sts = "";
   
    Chilkat.Http http = new Chilkat.Http();

    // Insert your access key here:
    http.AwsAccessKey = "AccessKey";
    http.AwsSecretKey = "SecretKey";  //root user
    http.AwsRegion = S3Region;
    

    bool success = http.S3_DeleteBucket(bucketName);
    
    if (success != true)
    {
        
        return sts = "{\"Status\":\"Failed\",\"Message\":\""http.lastErrorText"\"}";
    }
    else
    {
        return sts = "{\"Status\":\"Success\",\"Message\":\"Bucket deleted!\"}";
    }
}

You should examine the HTTP response body to see the error message from AWS. For example:

http.KeepResponseBody = true;

bool success = http.S3_DeleteBucket(bucketName);

if (success != true) {
    Debug.WriteLine(http.LastErrorText);
    // Also examine the error response body from AWS:
    Debug.WriteLine(http.LastResponseBody);
}
else {
    Debug.WriteLine("Bucket created.");
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM