Discussion:
delete S3 bucket with AWS PHP SDK
Tim Dunphy
2013-09-29 16:30:17 UTC
Permalink
Hi All,

I am attempting to delete an empty S3 bucket using the AWS PHP SDK.

Here's how they describe the process in the docs:

$result = $client->deleteBucket(array(
// Bucket is required
'Bucket' => 'string',
));

You can find the full entry here:

AWS PHP SDK Delete Bucket
Docs<http://docs.aws.amazon.com/aws-sdk-php-2/latest/class-Aws.S3.S3Client.html#_deleteBucket>

Here's how I approached it in my code:

$s3 = new AmazonS3();

$result = $s3->deleteObject(array(
'Bucket' => $bucket_name ));

But when I run it, this is the error I get:

'Notice: Undefined index: $bucket_name in /var/www/awssdk/delete_bucket.php
on line 5 Warning: Missing argument 2 for AmazonS3::delete_object() in
/var/www/awssdk/services/s3.class.php on line 1576 Notice: Undefined
variable: filename in /var/www/awssdk/services/s3.class.php on line 1581
Warning: preg_match() expects parameter 2 to be string, array given in
/var/www/awssdk/services/s3.class.php on line 1042 Warning: preg_match()
expects parameter 2 to be string, array given in
/var/www/awssdk/services/s3.class.php on line 1043 Fatal error: Uncaught
exception 'S3_Exception' with message 'S3 does not support "Array" as a
valid bucket name. Review "Bucket Restrictions and Limitations" in the S3
Developer Guide for more information.' in
/var/www/awssdk/services/s3.class.php:548 Stack trace: #0
/var/www/awssdk/services/s3.class.php(1594): AmazonS3->authenticate(Array,
Array) #1 [internal function]: AmazonS3->delete_object(Array) #2
/var/www/awssdk/sdk.class.php(436): call_user_func_array(Array, Array) #3
/var/www/awssdk/delete_bucket.php(10): CFRuntime->__call('deleteObject',
Array) #4 /var/www/awssdk/delete_bucket.php(10):
AmazonS3->deleteObject(Array) #5 {main} thrown in
/var/www/awssdk/services/s3.class.php on line 548'


This is line 548 in the above referenced file:

// Validate the S3 bucket name
if (!$this->validate_bucketname_support($bucket))
{
// @codeCoverageIgnoreStart
throw new S3_Exception('S3 does not support "' .
$bucket . '" as a valid bucket name. Review "Bucket Restrictions and
Limitations" in the S3 Developer Guide for more information.');
// @codeCoverageIgnoreEnd
}




Has anyone played around enough with the AWS SDK to know what I'm doing
wrong here? Would anyone else be able to hazard a guess?

Thanks
Tim
--
GPG me!!

gpg --keyserver pool.sks-keyservers.net --recv-keys F186197B
Ashley Sheridan
2013-09-29 16:56:55 UTC
Permalink
Post by Tim Dunphy
Hi All,
I am attempting to delete an empty S3 bucket using the AWS PHP SDK.
$result = $client->deleteBucket(array(
// Bucket is required
'Bucket' => 'string',
));
AWS PHP SDK Delete Bucket
Docs<http://docs.aws.amazon.com/aws-sdk-php-2/latest/class-Aws.S3.S3Client.html#_deleteBucket>
$s3 = new AmazonS3();
$result = $s3->deleteObject(array(
'Bucket' => $bucket_name ));
'Notice: Undefined index: $bucket_name in /var/www/awssdk/delete_bucket.php
on line 5 Warning: Missing argument 2 for AmazonS3::delete_object() in
/var/www/awssdk/services/s3.class.php on line 1576 Notice: Undefined
variable: filename in /var/www/awssdk/services/s3.class.php on line 1581
Warning: preg_match() expects parameter 2 to be string, array given in
/var/www/awssdk/services/s3.class.php on line 1042 Warning: preg_match()
expects parameter 2 to be string, array given in
/var/www/awssdk/services/s3.class.php on line 1043 Fatal error: Uncaught
exception 'S3_Exception' with message 'S3 does not support "Array" as a
valid bucket name. Review "Bucket Restrictions and Limitations" in the S3
Developer Guide for more information.' in
/var/www/awssdk/services/s3.class.php:548 Stack trace: #0
/var/www/awssdk/services/s3.class.php(1594): AmazonS3->authenticate(Array,
Array) #1 [internal function]: AmazonS3->delete_object(Array) #2
/var/www/awssdk/sdk.class.php(436): call_user_func_array(Array, Array) #3
/var/www/awssdk/delete_bucket.php(10): CFRuntime->__call('deleteObject',
AmazonS3->deleteObject(Array) #5 {main} thrown in
/var/www/awssdk/services/s3.class.php on line 548'
// Validate the S3 bucket name
if (!$this->validate_bucketname_support($bucket))
{
throw new S3_Exception('S3 does not support "' .
$bucket . '" as a valid bucket name. Review "Bucket Restrictions and
Limitations" in the S3 Developer Guide for more information.');
}
Has anyone played around enough with the AWS SDK to know what I'm doing
wrong here? Would anyone else be able to hazard a guess?
Thanks
Tim
Your code is failing because $bucket_name, I suspect, is null. Where do
you define this variable before you use it in this bit of code:

$result = $s3->deleteObject(array(
'Bucket' => $bucket_name ));

Thanks,
Ash
http://www.ashleysheridan.co.uk
Aziz Saleh
2013-09-29 17:09:45 UTC
Permalink
Hi Tim,

Is the call working? Does it actually get deleted?

This could just be an issue (which I see alot) where developers do not
check for variables or preset them before usage, causing those notices to
come up (pretty harmless most of the times).

Aziz
Post by Tim Dunphy
Hi All,
I am attempting to delete an empty S3 bucket using the AWS PHP SDK.
$result = $client->deleteBucket(array(
// Bucket is required
'Bucket' => 'string',
));
AWS PHP SDK Delete Bucket
Docs<
http://docs.aws.amazon.com/aws-sdk-php-2/latest/class-Aws.S3.S3Client.html#_deleteBucket
$s3 = new AmazonS3();
$result = $s3->deleteObject(array(
'Bucket' => $bucket_name ));
'Notice: Undefined index: $bucket_name in /var/www/awssdk/delete_bucket.php
on line 5 Warning: Missing argument 2 for AmazonS3::delete_object() in
/var/www/awssdk/services/s3.class.php on line 1576 Notice: Undefined
variable: filename in /var/www/awssdk/services/s3.class.php on line 1581
Warning: preg_match() expects parameter 2 to be string, array given in
/var/www/awssdk/services/s3.class.php on line 1042 Warning: preg_match()
expects parameter 2 to be string, array given in
/var/www/awssdk/services/s3.class.php on line 1043 Fatal error: Uncaught
exception 'S3_Exception' with message 'S3 does not support "Array" as a
valid bucket name. Review "Bucket Restrictions and Limitations" in the S3
Developer Guide for more information.' in
/var/www/awssdk/services/s3.class.php:548 Stack trace: #0
/var/www/awssdk/services/s3.class.php(1594): AmazonS3->authenticate(Array,
Array) #1 [internal function]: AmazonS3->delete_object(Array) #2
/var/www/awssdk/sdk.class.php(436): call_user_func_array(Array, Array) #3
/var/www/awssdk/delete_bucket.php(10): CFRuntime->__call('deleteObject',
AmazonS3->deleteObject(Array) #5 {main} thrown in
/var/www/awssdk/services/s3.class.php on line 548'
// Validate the S3 bucket name
if (!$this->validate_bucketname_support($bucket))
{
throw new S3_Exception('S3 does not support "' .
$bucket . '" as a valid bucket name. Review "Bucket Restrictions and
Limitations" in the S3 Developer Guide for more information.');
}
Has anyone played around enough with the AWS SDK to know what I'm doing
wrong here? Would anyone else be able to hazard a guess?
Thanks
Tim
--
GPG me!!
gpg --keyserver pool.sks-keyservers.net --recv-keys F186197B
Tim Dunphy
2013-09-29 19:28:29 UTC
Permalink
Hey guys,

Sorry about that i should have posted the full code to give you some idea
of context. Anyway, here it is:

<?php
require_once 'sdk.class.php';
if (isset($_POST['submit'])) {

* $bucket_name = $_POST['$bucket_name'];*
// Create the S3 Object from the SDK
*$s3 = new AmazonS3();*

* $result = $s3->deleteObject(array(*
* 'Bucket' => $bucket_name ));*


// The response comes back as a Simple XML Object
// In this case we just want to know if everything was okay.
// If not, report the message from the XML response.
if ((int) $response->isOK()) {
echo '<center>Deleted Bucket';
echo '<br /><br />';
echo '<a href=listbuckets.php>List Buckets</a></center>';
} else {
echo (string) $response->body->Message;
}
//echo '<br /><br />';
}
?>
<body>
<center><h3>Delete S3 Bucket</h3>
<form name="delete_bucket" method="post" action="delete_bucket.php">
<label for="bucket_name">Bucket Name:</label><br />
* <input type="text" id="bucket_name" name="bucket_name" /><br /><br />*
<input type="submit" name="submit" value="Delete Bucket" />
</form></center>

So, as you can see I am taking the 'bucket_value' from $_POST and passing
it into the call to S3.

When the form comes up on the web I give it the name of one of my S3
buckets. The result is the following error:

Notice: Undefined index: $bucket_name in /var/www/awssdk/delete_bucket.php
on line 67 Warning: Missing argument 2 for AmazonS3::delete_object() in
/var/www/awssdk/services/s3.class.php on line 1576 Notice: Undefined
variable: filename in /var/www/awssdk/services/s3.class.php on line 1581
Warning: preg_match() expects parameter 2 to be string, array given in
/var/www/awssdk/services/s3.class.php on line 1042 Warning: preg_match()
expects parameter 2 to be string, array given in
/var/www/awssdk/services/s3.class.php on line 1043 Fatal error: Uncaught
exception 'S3_Exception' with message 'S3 does not support "Array" as a
valid bucket name. Review "Bucket Restrictions and Limitations" in the S3
Developer Guide for more information.' in
/var/www/awssdk/services/s3.class.php:548 Stack trace: #0
/var/www/awssdk/services/s3.class.php(1594): AmazonS3->authenticate(Array,
Array) #1 [internal function]: AmazonS3->delete_object(Array) #2
/var/www/awssdk/sdk.class.php(436): call_user_func_array(Array, Array) #3
/var/www/awssdk/delete_bucket.php(72): CFRuntime->__call('deleteObject',
Array) #4 /var/www/awssdk/delete_bucket.php(72):
AmazonS3->deleteObject(Array) #5 {main} thrown in
/var/www/awssdk/services/s3.class.php on line 548



I hope that clarifies my situation a bit. Sorry for not providing that
sooner!

Thanks
Tim
Post by Aziz Saleh
Hi Tim,
Is the call working? Does it actually get deleted?
This could just be an issue (which I see alot) where developers do not
check for variables or preset them before usage, causing those notices to
come up (pretty harmless most of the times).
Aziz
Post by Tim Dunphy
Hi All,
I am attempting to delete an empty S3 bucket using the AWS PHP SDK.
$result = $client->deleteBucket(array(
// Bucket is required
'Bucket' => 'string',
));
AWS PHP SDK Delete Bucket
Docs<
http://docs.aws.amazon.com/aws-sdk-php-2/latest/class-Aws.S3.S3Client.html#_deleteBucket
$s3 = new AmazonS3();
$result = $s3->deleteObject(array(
'Bucket' => $bucket_name ));
'Notice: Undefined index: $bucket_name in
/var/www/awssdk/delete_bucket.php
on line 5 Warning: Missing argument 2 for AmazonS3::delete_object() in
/var/www/awssdk/services/s3.class.php on line 1576 Notice: Undefined
variable: filename in /var/www/awssdk/services/s3.class.php on line 1581
Warning: preg_match() expects parameter 2 to be string, array given in
/var/www/awssdk/services/s3.class.php on line 1042 Warning: preg_match()
expects parameter 2 to be string, array given in
/var/www/awssdk/services/s3.class.php on line 1043 Fatal error: Uncaught
exception 'S3_Exception' with message 'S3 does not support "Array" as a
valid bucket name. Review "Bucket Restrictions and Limitations" in the S3
Developer Guide for more information.' in
/var/www/awssdk/services/s3.class.php:548 Stack trace: #0
/var/www/awssdk/services/s3.class.php(1594): AmazonS3->authenticate(Array,
Array) #1 [internal function]: AmazonS3->delete_object(Array) #2
/var/www/awssdk/sdk.class.php(436): call_user_func_array(Array, Array) #3
/var/www/awssdk/delete_bucket.php(10): CFRuntime->__call('deleteObject',
AmazonS3->deleteObject(Array) #5 {main} thrown in
/var/www/awssdk/services/s3.class.php on line 548'
// Validate the S3 bucket name
if (!$this->validate_bucketname_support($bucket))
{
throw new S3_Exception('S3 does not support "' .
$bucket . '" as a valid bucket name. Review "Bucket Restrictions and
Limitations" in the S3 Developer Guide for more information.');
}
Has anyone played around enough with the AWS SDK to know what I'm doing
wrong here? Would anyone else be able to hazard a guess?
Thanks
Tim
--
GPG me!!
gpg --keyserver pool.sks-keyservers.net --recv-keys F186197B
--
GPG me!!

gpg --keyserver pool.sks-keyservers.net --recv-keys F186197B
Aziz Saleh
2013-09-29 21:04:52 UTC
Permalink
No Problem, the issue is that you referring to the invalid post element
$bucket_name as opposed to the correct on bucket_name.

*$bucket_name = $_POST['$bucket_name'];*

Should be

*$bucket_name = $_POST['bucket_name'];*

Aziz
Post by Tim Dunphy
Hey guys,
Sorry about that i should have posted the full code to give you some idea
<?php
require_once 'sdk.class.php';
if (isset($_POST['submit'])) {
* $bucket_name = $_POST['$bucket_name'];*
// Create the S3 Object from the SDK
*$s3 = new AmazonS3();*
* $result = $s3->deleteObject(array(*
* 'Bucket' => $bucket_name ));*
// The response comes back as a Simple XML Object
// In this case we just want to know if everything was okay.
// If not, report the message from the XML response.
if ((int) $response->isOK()) {
echo '<center>Deleted Bucket';
echo '<br /><br />';
echo '<a href=listbuckets.php>List Buckets</a></center>';
} else {
echo (string) $response->body->Message;
}
//echo '<br /><br />';
}
?>
<body>
<center><h3>Delete S3 Bucket</h3>
<form name="delete_bucket" method="post" action="delete_bucket.php">
<label for="bucket_name">Bucket Name:</label><br />
* <input type="text" id="bucket_name" name="bucket_name" /><br /><br />
*
<input type="submit" name="submit" value="Delete Bucket" />
</form></center>
So, as you can see I am taking the 'bucket_value' from $_POST and passing
it into the call to S3.
When the form comes up on the web I give it the name of one of my S3
Notice: Undefined index: $bucket_name in /var/www/awssdk/delete_bucket.php
on line 67 Warning: Missing argument 2 for AmazonS3::delete_object() in
/var/www/awssdk/services/s3.class.php on line 1576 Notice: Undefined
variable: filename in /var/www/awssdk/services/s3.class.php on line 1581
Warning: preg_match() expects parameter 2 to be string, array given in
/var/www/awssdk/services/s3.class.php on line 1042 Warning: preg_match()
expects parameter 2 to be string, array given in
/var/www/awssdk/services/s3.class.php on line 1043 Fatal error: Uncaught
exception 'S3_Exception' with message 'S3 does not support "Array" as a
valid bucket name. Review "Bucket Restrictions and Limitations" in the S3
Developer Guide for more information.' in
/var/www/awssdk/services/s3.class.php:548 Stack trace: #0
/var/www/awssdk/services/s3.class.php(1594): AmazonS3->authenticate(Array,
Array) #1 [internal function]: AmazonS3->delete_object(Array) #2
/var/www/awssdk/sdk.class.php(436): call_user_func_array(Array, Array) #3
/var/www/awssdk/delete_bucket.php(72): CFRuntime->__call('deleteObject',
AmazonS3->deleteObject(Array) #5 {main} thrown in
/var/www/awssdk/services/s3.class.php on line 548
I hope that clarifies my situation a bit. Sorry for not providing that
sooner!
Thanks
Tim
Post by Aziz Saleh
Hi Tim,
Is the call working? Does it actually get deleted?
This could just be an issue (which I see alot) where developers do not
check for variables or preset them before usage, causing those notices to
come up (pretty harmless most of the times).
Aziz
Post by Tim Dunphy
Hi All,
I am attempting to delete an empty S3 bucket using the AWS PHP SDK.
$result = $client->deleteBucket(array(
// Bucket is required
'Bucket' => 'string',
));
AWS PHP SDK Delete Bucket
Docs<
http://docs.aws.amazon.com/aws-sdk-php-2/latest/class-Aws.S3.S3Client.html#_deleteBucket
$s3 = new AmazonS3();
$result = $s3->deleteObject(array(
'Bucket' => $bucket_name ));
'Notice: Undefined index: $bucket_name in
/var/www/awssdk/delete_bucket.php
on line 5 Warning: Missing argument 2 for AmazonS3::delete_object() in
/var/www/awssdk/services/s3.class.php on line 1576 Notice: Undefined
variable: filename in /var/www/awssdk/services/s3.class.php on line 1581
Warning: preg_match() expects parameter 2 to be string, array given in
/var/www/awssdk/services/s3.class.php on line 1042 Warning: preg_match()
expects parameter 2 to be string, array given in
/var/www/awssdk/services/s3.class.php on line 1043 Fatal error: Uncaught
exception 'S3_Exception' with message 'S3 does not support "Array" as a
valid bucket name. Review "Bucket Restrictions and Limitations" in the S3
Developer Guide for more information.' in
/var/www/awssdk/services/s3.class.php:548 Stack trace: #0
AmazonS3->authenticate(Array,
Array) #1 [internal function]: AmazonS3->delete_object(Array) #2
/var/www/awssdk/sdk.class.php(436): call_user_func_array(Array, Array) #3
/var/www/awssdk/delete_bucket.php(10): CFRuntime->__call('deleteObject',
AmazonS3->deleteObject(Array) #5 {main} thrown in
/var/www/awssdk/services/s3.class.php on line 548'
// Validate the S3 bucket name
if (!$this->validate_bucketname_support($bucket))
{
throw new S3_Exception('S3 does not support "' .
$bucket . '" as a valid bucket name. Review "Bucket Restrictions and
Limitations" in the S3 Developer Guide for more information.');
}
Has anyone played around enough with the AWS SDK to know what I'm doing
wrong here? Would anyone else be able to hazard a guess?
Thanks
Tim
--
GPG me!!
gpg --keyserver pool.sks-keyservers.net --recv-keys F186197B
--
GPG me!!
gpg --keyserver pool.sks-keyservers.net --recv-keys F186197B
Tim Dunphy
2013-09-30 02:29:26 UTC
Permalink
Hi Aziz,

Thank you for getting back to me!

I appreciate you spotting that error.

So I corrected that

<?php
require_once 'sdk.class.php';
if (isset($_POST['submit'])) {

* $bucket_name = $_POST['bucket_name'];*
// Create the S3 Object from the SDK
$s3 = new AmazonS3();
*
$result = $s3->deleteObject(array(
'Bucket' => $bucket_name ));*


// The response comes back as a Simple XML Object
// In this case we just want to know if everything was okay.
// If not, report the message from the XML response.
if ((int) $response->isOK()) {
echo '<center>Deleted Bucket';
echo '<br /><br />';
echo '<a href=listbuckets.php>List Buckets</a></center>';
} else {
echo (string) $response->body->Message;
}
//echo '<br /><br />';
}
?>
<body>
<center><h3>Delete S3 Bucket</h3>
<form name="delete_bucket" method="post" action="delete_bucket.php">
<label for="bucket_name">Bucket Name:</label><br />
* <input type="text" id="bucket_name" name="bucket_name" /><br /><br />*
<input type="submit" name="submit" value="Delete Bucket" />
</form></center>
<script>
</body>
</html>


And this is the error I am currently getting:

Warning: Missing argument 2 for AmazonS3::delete_object() in
/var/www/awssdk/services/s3.class.php on line 1576 Notice: Undefined
variable: filename in /var/www/awssdk/services/s3.class.php on line 1581
Warning: preg_match() expects parameter 2 to be string, array given in
/var/www/awssdk/services/s3.class.php on line 1042 Warning: preg_match()
expects parameter 2 to be string, array given in
/var/www/awssdk/services/s3.class.php on line 1043 Fatal error: Uncaught
exception 'S3_Exception' with message 'S3 does not support "Array" as a
valid bucket name. Review "Bucket Restrictions and Limitations" in the S3
Developer Guide for more information.' in
/var/www/awssdk/services/s3.class.php:548 Stack trace: #0
/var/www/awssdk/services/s3.class.php(1594): AmazonS3->authenticate(Array,
Array) #1 [internal function]: AmazonS3->delete_object(Array) #2
/var/www/awssdk/sdk.class.php(436): call_user_func_array(Array, Array) #3
/var/www/awssdk/delete_bucket.php(72): CFRuntime->__call('deleteObject',
Array) #4 /var/www/awssdk/delete_bucket.php(72):
AmazonS3->deleteObject(Array) #5 {main} thrown in
/var/www/awssdk/services/s3.class.php on line 548

Not sure if I'm getting closer here... but definitely appreciate any advice
anyone may have.

Thanks!
Tim
Post by Aziz Saleh
No Problem, the issue is that you referring to the invalid post element
$bucket_name as opposed to the correct on bucket_name.
*$bucket_name = $_POST['$bucket_name'];*
Should be
*$bucket_name = $_POST['bucket_name'];*
Aziz
Post by Tim Dunphy
Hey guys,
Sorry about that i should have posted the full code to give you some
<?php
require_once 'sdk.class.php';
if (isset($_POST['submit'])) {
* $bucket_name = $_POST['$bucket_name'];*
// Create the S3 Object from the SDK
*$s3 = new AmazonS3();*
* $result = $s3->deleteObject(array(*
* 'Bucket' => $bucket_name ));*
// The response comes back as a Simple XML Object
// In this case we just want to know if everything was okay.
// If not, report the message from the XML response.
if ((int) $response->isOK()) {
echo '<center>Deleted Bucket';
echo '<br /><br />';
echo '<a href=listbuckets.php>List Buckets</a></center>';
} else {
echo (string) $response->body->Message;
}
//echo '<br /><br />';
}
?>
<body>
<center><h3>Delete S3 Bucket</h3>
<form name="delete_bucket" method="post" action="delete_bucket.php">
<label for="bucket_name">Bucket Name:</label><br />
* <input type="text" id="bucket_name" name="bucket_name" /><br /><br />*
<input type="submit" name="submit" value="Delete Bucket" />
</form></center>
So, as you can see I am taking the 'bucket_value' from $_POST and passing
it into the call to S3.
When the form comes up on the web I give it the name of one of my S3
Notice: Undefined index: $bucket_name in
/var/www/awssdk/delete_bucket.php on line 67 Warning: Missing argument 2
for AmazonS3::delete_object() in /var/www/awssdk/services/s3.class.php on
line 1576 Notice: Undefined variable: filename in
/var/www/awssdk/services/s3.class.php on line 1581 Warning: preg_match()
expects parameter 2 to be string, array given in
/var/www/awssdk/services/s3.class.php on line 1042 Warning: preg_match()
expects parameter 2 to be string, array given in
/var/www/awssdk/services/s3.class.php on line 1043 Fatal error: Uncaught
exception 'S3_Exception' with message 'S3 does not support "Array" as a
valid bucket name. Review "Bucket Restrictions and Limitations" in the S3
Developer Guide for more information.' in
/var/www/awssdk/services/s3.class.php:548 Stack trace: #0
/var/www/awssdk/services/s3.class.php(1594): AmazonS3->authenticate(Array,
Array) #1 [internal function]: AmazonS3->delete_object(Array) #2
/var/www/awssdk/sdk.class.php(436): call_user_func_array(Array, Array) #3
/var/www/awssdk/delete_bucket.php(72): CFRuntime->__call('deleteObject',
AmazonS3->deleteObject(Array) #5 {main} thrown in
/var/www/awssdk/services/s3.class.php on line 548
I hope that clarifies my situation a bit. Sorry for not providing that
sooner!
Thanks
Tim
Post by Aziz Saleh
Hi Tim,
Is the call working? Does it actually get deleted?
This could just be an issue (which I see alot) where developers do not
check for variables or preset them before usage, causing those notices to
come up (pretty harmless most of the times).
Aziz
Post by Tim Dunphy
Hi All,
I am attempting to delete an empty S3 bucket using the AWS PHP SDK.
$result = $client->deleteBucket(array(
// Bucket is required
'Bucket' => 'string',
));
AWS PHP SDK Delete Bucket
Docs<
http://docs.aws.amazon.com/aws-sdk-php-2/latest/class-Aws.S3.S3Client.html#_deleteBucket
$s3 = new AmazonS3();
$result = $s3->deleteObject(array(
'Bucket' => $bucket_name ));
'Notice: Undefined index: $bucket_name in
/var/www/awssdk/delete_bucket.php
on line 5 Warning: Missing argument 2 for AmazonS3::delete_object() in
/var/www/awssdk/services/s3.class.php on line 1576 Notice: Undefined
variable: filename in /var/www/awssdk/services/s3.class.php on line 1581
Warning: preg_match() expects parameter 2 to be string, array given in
/var/www/awssdk/services/s3.class.php on line 1042 Warning: preg_match()
expects parameter 2 to be string, array given in
/var/www/awssdk/services/s3.class.php on line 1043 Fatal error: Uncaught
exception 'S3_Exception' with message 'S3 does not support "Array" as a
valid bucket name. Review "Bucket Restrictions and Limitations" in the S3
Developer Guide for more information.' in
/var/www/awssdk/services/s3.class.php:548 Stack trace: #0
AmazonS3->authenticate(Array,
Array) #1 [internal function]: AmazonS3->delete_object(Array) #2
/var/www/awssdk/sdk.class.php(436): call_user_func_array(Array, Array) #3
/var/www/awssdk/delete_bucket.php(10): CFRuntime->__call('deleteObject',
AmazonS3->deleteObject(Array) #5 {main} thrown in
/var/www/awssdk/services/s3.class.php on line 548'
// Validate the S3 bucket name
if (!$this->validate_bucketname_support($bucket))
{
throw new S3_Exception('S3 does not support "' .
$bucket . '" as a valid bucket name. Review "Bucket Restrictions and
Limitations" in the S3 Developer Guide for more information.');
}
Has anyone played around enough with the AWS SDK to know what I'm doing
wrong here? Would anyone else be able to hazard a guess?
Thanks
Tim
--
GPG me!!
gpg --keyserver pool.sks-keyservers.net --recv-keys F186197B
--
GPG me!!
gpg --keyserver pool.sks-keyservers.net --recv-keys F186197B
--
GPG me!!

gpg --keyserver pool.sks-keyservers.net --recv-keys F186197B
Aziz Saleh
2013-10-01 18:56:41 UTC
Permalink
Hey Tim,

It seems that deleteObject takes in 2 params, and you are sending it 1
param. I would recommend you look at the documentation and make sure you
are sending the right params.

Aziz
Post by Tim Dunphy
Hi Aziz,
Thank you for getting back to me!
I appreciate you spotting that error.
So I corrected that
<?php
require_once 'sdk.class.php';
if (isset($_POST['submit'])) {
* $bucket_name = $_POST['bucket_name'];*
// Create the S3 Object from the SDK
$s3 = new AmazonS3();
*
$result = $s3->deleteObject(array(
'Bucket' => $bucket_name ));*
// The response comes back as a Simple XML Object
// In this case we just want to know if everything was okay.
// If not, report the message from the XML response.
if ((int) $response->isOK()) {
echo '<center>Deleted Bucket';
echo '<br /><br />';
echo '<a href=listbuckets.php>List Buckets</a></center>';
} else {
echo (string) $response->body->Message;
}
//echo '<br /><br />';
}
?>
<body>
<center><h3>Delete S3 Bucket</h3>
<form name="delete_bucket" method="post" action="delete_bucket.php">
<label for="bucket_name">Bucket Name:</label><br />
* <input type="text" id="bucket_name" name="bucket_name" /><br /><br />
*
<input type="submit" name="submit" value="Delete Bucket" />
</form></center>
<script>
</body>
</html>
Warning: Missing argument 2 for AmazonS3::delete_object() in
/var/www/awssdk/services/s3.class.php on line 1576 Notice: Undefined
variable: filename in /var/www/awssdk/services/s3.class.php on line 1581
Warning: preg_match() expects parameter 2 to be string, array given in
/var/www/awssdk/services/s3.class.php on line 1042 Warning: preg_match()
expects parameter 2 to be string, array given in
/var/www/awssdk/services/s3.class.php on line 1043 Fatal error: Uncaught
exception 'S3_Exception' with message 'S3 does not support "Array" as a
valid bucket name. Review "Bucket Restrictions and Limitations" in the S3
Developer Guide for more information.' in
/var/www/awssdk/services/s3.class.php:548 Stack trace: #0
/var/www/awssdk/services/s3.class.php(1594): AmazonS3->authenticate(Array,
Array) #1 [internal function]: AmazonS3->delete_object(Array) #2
/var/www/awssdk/sdk.class.php(436): call_user_func_array(Array, Array) #3
/var/www/awssdk/delete_bucket.php(72): CFRuntime->__call('deleteObject',
AmazonS3->deleteObject(Array) #5 {main} thrown in
/var/www/awssdk/services/s3.class.php on line 548
Not sure if I'm getting closer here... but definitely appreciate any
advice anyone may have.
Thanks!
Tim
Post by Aziz Saleh
No Problem, the issue is that you referring to the invalid post element
$bucket_name as opposed to the correct on bucket_name.
*$bucket_name = $_POST['$bucket_name'];*
Should be
*$bucket_name = $_POST['bucket_name'];*
Aziz
Post by Tim Dunphy
Hey guys,
Sorry about that i should have posted the full code to give you some
<?php
require_once 'sdk.class.php';
if (isset($_POST['submit'])) {
* $bucket_name = $_POST['$bucket_name'];*
// Create the S3 Object from the SDK
*$s3 = new AmazonS3();*
* $result = $s3->deleteObject(array(*
* 'Bucket' => $bucket_name ));*
// The response comes back as a Simple XML Object
// In this case we just want to know if everything was okay.
// If not, report the message from the XML response.
if ((int) $response->isOK()) {
echo '<center>Deleted Bucket';
echo '<br /><br />';
echo '<a href=listbuckets.php>List Buckets</a></center>';
} else {
echo (string) $response->body->Message;
}
//echo '<br /><br />';
}
?>
<body>
<center><h3>Delete S3 Bucket</h3>
<form name="delete_bucket" method="post" action="delete_bucket.php">
<label for="bucket_name">Bucket Name:</label><br />
* <input type="text" id="bucket_name" name="bucket_name" /><br /><br />*
<input type="submit" name="submit" value="Delete Bucket" />
</form></center>
So, as you can see I am taking the 'bucket_value' from $_POST and
passing it into the call to S3.
When the form comes up on the web I give it the name of one of my S3
Notice: Undefined index: $bucket_name in
/var/www/awssdk/delete_bucket.php on line 67 Warning: Missing argument 2
for AmazonS3::delete_object() in /var/www/awssdk/services/s3.class.php on
line 1576 Notice: Undefined variable: filename in
/var/www/awssdk/services/s3.class.php on line 1581 Warning: preg_match()
expects parameter 2 to be string, array given in
/var/www/awssdk/services/s3.class.php on line 1042 Warning: preg_match()
expects parameter 2 to be string, array given in
/var/www/awssdk/services/s3.class.php on line 1043 Fatal error: Uncaught
exception 'S3_Exception' with message 'S3 does not support "Array" as a
valid bucket name. Review "Bucket Restrictions and Limitations" in the S3
Developer Guide for more information.' in
/var/www/awssdk/services/s3.class.php:548 Stack trace: #0
/var/www/awssdk/services/s3.class.php(1594): AmazonS3->authenticate(Array,
Array) #1 [internal function]: AmazonS3->delete_object(Array) #2
/var/www/awssdk/sdk.class.php(436): call_user_func_array(Array, Array) #3
/var/www/awssdk/delete_bucket.php(72): CFRuntime->__call('deleteObject',
AmazonS3->deleteObject(Array) #5 {main} thrown in
/var/www/awssdk/services/s3.class.php on line 548
I hope that clarifies my situation a bit. Sorry for not providing that
sooner!
Thanks
Tim
Post by Aziz Saleh
Hi Tim,
Is the call working? Does it actually get deleted?
This could just be an issue (which I see alot) where developers do not
check for variables or preset them before usage, causing those notices to
come up (pretty harmless most of the times).
Aziz
Post by Tim Dunphy
Hi All,
I am attempting to delete an empty S3 bucket using the AWS PHP SDK.
$result = $client->deleteBucket(array(
// Bucket is required
'Bucket' => 'string',
));
AWS PHP SDK Delete Bucket
Docs<
http://docs.aws.amazon.com/aws-sdk-php-2/latest/class-Aws.S3.S3Client.html#_deleteBucket
$s3 = new AmazonS3();
$result = $s3->deleteObject(array(
'Bucket' => $bucket_name ));
'Notice: Undefined index: $bucket_name in
/var/www/awssdk/delete_bucket.php
on line 5 Warning: Missing argument 2 for AmazonS3::delete_object() in
/var/www/awssdk/services/s3.class.php on line 1576 Notice: Undefined
variable: filename in /var/www/awssdk/services/s3.class.php on line 1581
Warning: preg_match() expects parameter 2 to be string, array given in
/var/www/awssdk/services/s3.class.php on line 1042 Warning: preg_match()
expects parameter 2 to be string, array given in
/var/www/awssdk/services/s3.class.php on line 1043 Fatal error: Uncaught
exception 'S3_Exception' with message 'S3 does not support "Array" as a
valid bucket name. Review "Bucket Restrictions and Limitations" in the S3
Developer Guide for more information.' in
/var/www/awssdk/services/s3.class.php:548 Stack trace: #0
AmazonS3->authenticate(Array,
Array) #1 [internal function]: AmazonS3->delete_object(Array) #2
/var/www/awssdk/sdk.class.php(436): call_user_func_array(Array, Array) #3
CFRuntime->__call('deleteObject',
AmazonS3->deleteObject(Array) #5 {main} thrown in
/var/www/awssdk/services/s3.class.php on line 548'
// Validate the S3 bucket name
if (!$this->validate_bucketname_support($bucket))
{
throw new S3_Exception('S3 does not support "' .
$bucket . '" as a valid bucket name. Review "Bucket Restrictions and
Limitations" in the S3 Developer Guide for more information.');
}
Has anyone played around enough with the AWS SDK to know what I'm doing
wrong here? Would anyone else be able to hazard a guess?
Thanks
Tim
--
GPG me!!
gpg --keyserver pool.sks-keyservers.net --recv-keys F186197B
--
GPG me!!
gpg --keyserver pool.sks-keyservers.net --recv-keys F186197B
--
GPG me!!
gpg --keyserver pool.sks-keyservers.net --recv-keys F186197B
Loading...