Random behaviour while deleting bucket from S3

66 views Asked by At

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!\"}";
    }
}
1

There are 1 answers

0
Chilkat Software On

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.");
}