I am trying to delete a brand new S3 bucket using the following code:
public void DeleteBucket(string bucketName)
{
s3Client.DeleteBucket(new DeleteBucketRequest() {BucketName = bucketName, UseClientRegion = true});
}
The bucket does not have versioning enabled and has no files in it. I am able to delete it from the web interface, however, I am unable to delete it using the above code.
I get an AmazonS3Exception error with the error message "The specified method is not allowed against this resource."
ErrorCode is "MethodNotAllowed"
StackTrace follows:
at Amazon.Runtime.AmazonWebServiceClient.d__1a.MoveNext() in d:\Jenkins\workspace\build-sdkandtools\sdk\src\AWSSDK_DotNet45\Amazon.Runtime\AmazonWebServiceClient.cs:line 453 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.ConfiguredTaskAwaitable
1.ConfiguredTaskAwaiter.GetResult() at Amazon.Runtime.AmazonWebServiceClient.<InvokeConfiguredRequest>d__3
1.MoveNext() in d:\Jenkins\workspace\build-sdkandtools\sdk\src\AWSSDK_DotNet45\Amazon.Runtime\AmazonWebServiceClient.cs:line 274 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at Amazon.S3.AmazonS3Client.DeleteBucket(DeleteBucketRequest request) in d:\Jenkins\workspace\build-sdkandtools\sdk\src\AWSSDK_DotNet45\Amazon.S3\AmazonS3Client.cs:line 375 at WPFBucketManager.Service.AwsService.DeleteBucket(String bucketName) in c:\Users\Matt\Documents\Visual Studio 2012\Projects\BucketManager\WPFBucketManager\Service\AwsService.cs:line 28 at WPFBucketManager.ViewModel.ApplicationViewModel.DeleteSelectedBucket() in c:\Users\Matt\Documents\Visual Studio 2012\Projects\BucketManager\WPFBucketManager\ViewModel\ApplicationViewModel.cs:line 32 at WPFBucketManager.ViewModel.ApplicationViewModel.b__0(Object param) in c:\Users\Matt\Documents\Visual Studio 2012\Projects\BucketManager\WPFBucketManager\ViewModel\ApplicationViewModel.cs:line 43 at WPFBucketManager.Infrastructure.RelayCommand.Execute(Object parameter) in c:\Users\Matt\Documents\Visual Studio 2012\Projects\BucketManager\WPFBucketManager\Infrastructure\RelayCommand.cs:line 55 at 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) at System.Windows.UIElement.OnMouseLeftButtonUpThunk(Object sender, MouseButtonEventArgs e) at System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget) at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target) at 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(Delegate genericHandler, Object genericTarget) at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target) at 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 System.Windows.UIElement.RaiseEvent(RoutedEventArgs args, Boolean trusted) at System.Windows.Input.InputManager.ProcessStagingArea() at System.Windows.Input.InputManager.ProcessInput(InputEventArgs input) at System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport) at System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawMouseActions actions, Int32 x, Int32 y, Int32 wheel) at System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr hwnd, WindowMessage msg, IntPtr wParam, IntPtr lParam, Boolean& handled) at System.Windows.Interop.HwndSource.InputFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled) at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled) at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o) at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs) at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler) at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs) at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam) at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg) at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame) at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
at System.Windows.Threading.Dispatcher.Run() at System.Windows.Application.RunDispatcher(Object ignore) at System.Windows.Application.RunInternal(Window window) at System.Windows.Application.Run(Window window) at System.Windows.Application.Run() at WPFBucketManager.App.Main() in c:\Users\Matt\Documents\Visual Studio 2012\Projects\BucketManager\WPFBucketManager\obj\Debug\App.g.cs:line 50 at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args) at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart()
as requested, full code:
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 is passed in a string with the exact text of an existing bucket name (which is retrieved from GetAllBuckets().
Another Edit:
Using the following method to create a bucket through .NET successfully creates the bucket (refreshing the web console shows the bucket existing):
public void CreateBucket(string bucketName)
{
s3Client.PutBucket(new PutBucketRequest() {BucketName = bucketName, UseClientRegion = true});
}
Now, after confirming this can create the bucket, I pass the exact same bucket name into the above DeleteBucket method, and it deletes the bucket as expected.
To confirm: I am trying to create and delete buckets that are in the same region (RegionEndpoint.USWest2 == Oregon). Am able to create and delete via the library, unable to create from web and delete via library.