asp.net - 从 S3 中删除存储桶时的随机行为
问题描述
我正在编写与Aws s3交互的代码,以执行各种操作,如创建存储桶、删除存储桶、上传和下载文件等。尝试删除存储桶时出现问题;拒绝访问
目前,我正在使用Root 用户凭据来创建和删除存储桶。未启用版本控制,并且无法在 AWS 控制台中看到附加到此存储桶的任何存储桶策略。
它表现出奇怪的行为;有时在尝试删除空存储桶时会出现访问被拒绝错误,有时它会毫不费力地被删除。
我可以毫无问题地通过 AWs s3 控制台删除存储桶。它只是通过它随机行为的代码。
请有人解释一下;可能是什么原因?
这是我的代码
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!\"}";
}
}
解决方案
您应该检查 HTTP 响应正文以查看来自 AWS 的错误消息。例如:
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.");
}
推荐阅读
- spring - 使用 api 创建引用另一个资源的资源时,期望的正确格式是什么
- r - 如何用前一行的2列中的值递归替换元素
- sql - 如何检查多个表中是否存在列值?
- laravel - 在 Docker 中从 AWS 设置 SSL
- javascript - 如何使每个视频元素以相同的大小出现?
- autodesk-forge - 以 RVT/CAD 格式导出标记数据
- javascript - 将 Javascript 函数作为参数传递 - 这个逻辑是如何工作的?
- c# - EWS 邮箱组流订阅
- php - 计算发出了多少 curl_multi 请求
- python-3.x - pathlib.Path 模块中的exist_ok 参数有什么作用?