我正在尝试使用以下代码删除全新的S3存储桶:
public void DeleteBucket(string bucketName)
{
s3Client.DeleteBucket(new DeleteBucketRequest() {BucketName = bucketName, UseClientRegion = true});
}
存储桶没有启用版本控制,并且没有文件。我可以从网络界面删除它,但是,我无法使用上面的代码将其删除。
我收到错误消息&#34的AmazonS3Exception错误;不允许对此资源使用指定的方法。"
ErrorCode是" MethodNotAllowed"
StackTrace如下:
at Amazon.Runtime.AmazonWebServiceClient.d__1a.MoveNext() 在 d:\詹金斯\工作空间\积聚sdkandtools \ SDK \ SRC \ AWSSDK_DotNet45 \ Amazon.Runtime \ AmazonWebServiceClient.cs:线 453 ---来自先前位置的堆栈跟踪结束异常 被扔了 - 在 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务 任务) System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务 任务) System.Runtime.CompilerServices.ConfiguredTaskAwaitable
1.ConfiguredTaskAwaiter.GetResult() at Amazon.Runtime.AmazonWebServiceClient.<InvokeConfiguredRequest>d__3
1.MoveNext() 在 d:\詹金斯\工作空间\积聚sdkandtools \ SDK \ SRC \ AWSSDK_DotNet45 \ Amazon.Runtime \ AmazonWebServiceClient.cs:线 274 ---来自先前位置的堆栈跟踪结束异常 被扔了 - 在 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()at Amazon.S3.AmazonS3Client.DeleteBucket(DeleteBucketRequest请求)中 d:\詹金斯\工作空间\积聚sdkandtools \ SDK \ SRC \ AWSSDK_DotNet45 \ Amazon.S3 \ AmazonS3Client.cs:线 375 at WPFBucketManager.Service.AwsService.DeleteBucket(String bucketName)在c:\ Users \ Matt \ Documents \ Visual Studio中 2012 \项目\ BucketManager \ WPFBucketManager \服务\ AwsService.cs:行 28点 WPFBucketManager.ViewModel.ApplicationViewModel.DeleteSelectedBucket() 在c:\ Users \ Matt \ Documents \ Visual Studio中 2012 \项目\ BucketManager \ WPFBucketManager \视图模型\ ApplicationViewModel.cs:行 32点 WPFBucketManager.ViewModel.ApplicationViewModel.b__0(对象 param)在c:\ Users \ Matt \ Documents \ Visual Studio中 2012 \项目\ BucketManager \ WPFBucketManager \视图模型\ ApplicationViewModel.cs:行 43在WPFBucketManager.Infrastructure.RelayCommand.Execute(Object 参数)在c:\ Users \ Matt \ Documents \ Visual Studio中 2012 \项目\ BucketManager \ WPFBucketManager \基础设施\ RelayCommand.cs:行 55点 MS.Internal.Commands.CommandHelpers.CriticalExecuteCommandSource(ICommandSource commandSource,Boolean userInitiated)at System.Windows.Controls.Primitives.ButtonBase.OnClick()at System.Windows.Controls.Button.OnClick()at System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs e)在System.Windows.UIElement.OnMouseLeftButtonUpThunk(Object sender,MouseButtonEventArgs e)at System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(代表 genericHandler,Object genericTarget)at System.Windows.RoutedEventArgs.InvokeHandler(委托处理程序,对象 目标) System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args,Boolean reRaised)at System.Windows.UIElement.ReRaiseEventAs(DependencyObject sender, RoutedEventArgs args,RoutedEvent newEvent)at System.Windows.UIElement.OnMouseUpThunk(Object sender, MouseButtonEventArgs e)at System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(代表 genericHandler,Object genericTarget)at System.Windows.RoutedEventArgs.InvokeHandler(委托处理程序,对象 目标) System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args,Boolean reRaised)at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)at System.Windows.UIElement.RaiseTrustedEvent(RoutedEventArgs args)at at System.Windows.UIElement.RaiseEvent(RoutedEventArgs args,Boolean 可信的)在System.Windows.Input.InputManager.ProcessStagingArea() 在System.Windows.Input.InputManager.ProcessInput(InputEventArgs 输入) System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport)at System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr hwnd, InputMode模式,Int32时间戳,RawMouseActions操作,Int32 x, Int32 y,Int32 wheel)at System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr的 hwnd,WindowMessage msg,IntPtr wParam,IntPtr lParam,Boolean&amp; 处理) System.Windows.Interop.HwndSource.InputFilterMessage(IntPtr hwnd, Int32 msg,IntPtr wParam,IntPtr lParam,Boolean&amp;处理) MS.Win32.HwndWrapper.WndProc(IntPtr hwnd,Int32 msg,IntPtr wParam, IntPtr lParam,Boolean&amp;处理) MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)at System.Windows.Threading.ExceptionWrapper.InternalRealCall(代表 回调,对象args,Int32 numArgs)at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(对象 source,Delegate方法,Object args,Int32 numArgs,Delegate catchHandler)at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(的DispatcherPriority 优先级,TimeSpan超时,委托方法,对象args,Int32 numArgs)在MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg,IntPtr wParam,IntPtr lParam)at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG&amp; msg)at at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame 框架) System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame框架)
在System.Windows.Threading.Dispatcher.Run()处 System.Windows.Application.RunDispatcher(Object ignore)at System.Windows.Application.RunInternal(窗口窗口)at System.Windows.Application.Run(窗口窗口)at WPFBucketManager.App.Main()中的System.Windows.Application.Run() c:\ Users \ Matt \ Documents \ Visual Studio 2012 \项目\ BucketManager \ WPFBucketManager \ OBJ \调试\ App.g.cs:行 50在System.AppDomain._nExecuteAssembly(RuntimeAssembly程序集, System.AppDomain.ExecuteAssembly上的String [] args)(String assemblyFile,Evidence assemblySecurity,String [] args)at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
在System.Threading.ThreadHelper.ThreadStart_Context(对象状态)
在System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext,ContextCallback回调,对象状态,布尔值 preserveSyncCtx)at System.Threading.ExecutionContext.Run(执行上下文 executionContext,ContextCallback回调,对象状态,布尔值 preserveSyncCtx)at System.Threading.ExecutionContext.Run(执行上下文 executionContext,ContextCallback回调,对象状态)at System.Threading.ThreadHelper.ThreadStart()
根据要求,完整代码:
public class AwsService
{
private readonly IAmazonS3 s3Client;
private const string AccessKey = "ACCESSKEYREMOVED";
private const string SecretKey = "SECRETKEYREMOVED";
public AwsService()
{
s3Client = AWSClientFactory.CreateAmazonS3Client(AccessKey, SecretKey, RegionEndpoint.APNortheast1);
}
public List<S3Bucket> GetAllBuckets()
{
return s3Client.ListBuckets().Buckets.ToList();
}
public void DeleteBucket(string bucketName)
{
s3Client.DeleteBucket(new DeleteBucketRequest() {BucketName = bucketName, UseClientRegion = true});
}
}
DeleteBucket以字符串形式传递,其中包含现有存储桶名称的确切文本(从GetAllBuckets()中检索。
另一个编辑:
使用以下方法通过.NET创建存储桶成功创建存储桶(刷新Web控制台显示存在存储桶):
public void CreateBucket(string bucketName)
{
s3Client.PutBucket(new PutBucketRequest() {BucketName = bucketName, UseClientRegion = true});
}
现在,在确认这可以创建存储桶之后,我将完全相同的存储桶名称传递给上面的DeleteBucket方法,并按预期删除存储桶。
确认:我正在尝试创建和删除位于同一区域(RegionEndpoint.USWest2 == Oregon)的存储桶。能够通过库创建和删除,无法从Web创建和通过库删除。
答案 0 :(得分:0)
AWS库完全没有问题,整个问题都在我的最后。我试图从列表中选择一个桶来删除它,当我最后一次踩到代码时,我注意到“选择”一个桶时,它实际上从未被选中。多么愚蠢的错误。
如果其他人正在进行上述错误检查以确保您没有将空值作为存储桶名称传递,那就是我的问题。