Amazon S3 Error Handling

Amazon S3 PHP Class A standalone Amazon S3 (REST) client for PHP 5.2.x using CURL that does not require PEAR.

AWS Management Console Home
AWS Management Console Home

AMAZON S3 (Scalable Storage in the Cloud) PHP CLASS

AWS access info
AWS access info

// AWS access info
if (!defined(‘awsAccessKey’)) define(‘awsAccessKey’, ‘CHANGE-KEY’);
if (!defined(‘awsSecretKey’)) define(‘awsSecretKey’, ‘CHANGE-KEY’);

OO method (e,g; $s3->getObject(…)):
$s3 = new S3(awsAccessKey, awsSecretKey);

Statically (e,g; S3::getObject(…)):
S3::setAuth(awsAccessKey, awsSecretKey);

Warning: S3::getBucket(): [PermanentRedirect] The bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint.

We need to End Point for our S3 Buckets by default it’s

$s3 = new S3(awsAccessKey, awsSecretKey);

S3 Management Console
S3 Management Console

Else we need to specify here…

S3 Management Console
S3 Management Console

$s3 = new S3(awsAccessKey, awsSecretKey, true, ‘‘);

Warning: S3::getBucket(): [60] SSL certificate problem, verify that the CA cert is OK. Details: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed

We need SSL enabled with CURL πŸ˜‰

OpenSSL phpinfo()
OpenSSL phpinfo()
CURL With OpenSSL phpinfo()
CURL With OpenSSL phpinfo()

For class documentation see:

AWS CloudFront with PHP

Amazon CloudFront is a web service for content delivery (CDN). It integrates with other Amazon Web Services EC2 / S3 to give developers and businesses an easy way to distribute content to end users with low latency and high data transfer speeds.

Digital Inspiration – Thanks to… it always provides help for all latest technologies πŸ™‚

You can follow basic steps here to setup CloudFront with Amazon S3 with your domain…
How to Setup Amazon S3 with CloudFront as a Content Delivery Network

You can download Cloudfront keys from AWS account


$file="svnlabs.flv"; // file on Amazon S3

function rsa_sha1_sign($policy, $private_key_filename) {
    $signature = "";

    // load the private key
    $fp = fopen($private_key_filename, "r");
    $priv_key = fread($fp, 8192);
    $pkeyid = openssl_get_privatekey($priv_key);

    // compute signature
    openssl_sign($policy, $signature, $pkeyid);

    // free the key from memory

    return $signature;

function url_safe_base64_encode($value) {
    $encoded = base64_encode($value);
    // replace unsafe characters +, = and / with the safe characters -, _ and ~
    return str_replace(
        array('+', '=', '/'),
        array('-', '_', '~'),

function encode_query_params($stream_name) {

    return str_replace(
        array('?', '=', '&'),
        array('%3F', '%3D', '%26'),

/// Download from here...

$private_key_filename = 'pk-XXXXXXXXXXXXXXXXXXXX.pem';
$cloudfront= '';

$file_location = "$cloudfront$file";

$expires = time() + 3;  // 3 min from now
$remote_ip = $_SERVER['REMOTE_ADDR'];

$policy = 
            '"Resource":"'. $file_location . '",'.
                '"IpAddress":{"AWS:SourceIp":"' . $remote_ip . '/32"},'.
                '"DateLessThan":{"AWS:EpochTime":' . $expires . '}'.
    ']' .

$encoded_policy = url_safe_base64_encode($policy);
$signature = rsa_sha1_sign($policy, $private_key_filename);
$encoded_signature = url_safe_base64_encode($signature);

<title>CloudFront Implementation in PHP</title> 
<a href='<?php echo "$file_location$streamer"; ?>'><?php echo "$file_location$streamer"; ?></a> 

A Master inspires you by his being & learning happens. πŸ˜‰

SaaS built using a PaaS (Google App Engine) and using IaaS (Amazon EC2)

SaaS = PaaS + IaaS

Historical Method - VaR Cloud App.png

Tools for Development, Testing and Implementation:
* Amazon Web Services (AWS)
* Google App Engine (GAE)
* Google Chart Libraries
* Eclipse IDE

VaR Cloud Presentation SVNLabs

Google AppEngine:
Amazon EC2:
Google Chart:

“A lamp does not speak. It introduces itself through it’s light. Achievers never expose themselves. But their achievements expose them..!!!”

FB Social Marketing is a Social Media Marketing company specializing in the development of Facebook Fan Pages for your business.

Be sure to check out complete line of training videos.

I have partnered with Shelle Kind of and we have released the Amazon S3 / EC2 Solution for Facebook fanpage apps.

How to Setup Elastic Load Balancing on AWS

Amazon S3 & Facebook Fanpage app

I want to link Amazon S3 https object like “” to facebook iframed fan page…
But it returned error….

405 Method Not Allowed
Code: MethodNotAllowed
Message: The specified method is not allowed against this resource.
ResourceType: OBJECT
Method: POST


PreconditionFailedAt least one of the pre-conditions you specified did not holdBucket POST must be of the enclosure-type multipart/form-data….. πŸ™


<Message>At least one of the pre-conditions you specified did not hold</Message>
<Condition>Bucket POST must be of the enclosure-type multipart/form-data</Condition>

After few searches I got link…. but not helpful πŸ™

Finally, I got good article on AWS Forum..

I came to know that facebook loads the requested HTTPS S3 URL “” by sending a form POST and injected some content into the iframe, but S3 have POST for file uploading only… so it returned “MethodNotAllowed”

Bucket Policies won’t work in this condition… πŸ™

Now, I have few options to use S3 HTTPS Object “” in facebook iframed fan page…

1. Run a HTTPS Apache server that can load S3 HTTPS Object with POST method and supply to fan page πŸ™‚
2. Load S3 HTTPS Object using another iframe on any server… see code below

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Facebook Fan Page - Amazon S3</title>

<iframe frameborder="0" style="width: 520px; height: 800px;" src="" scrolling="no"></iframe>

You can check videos released on blog 9th May 2011 for more detailed installation…

I have partnered with Shelle Kind of facebook social marketing and we have released the Amazon S3 / EC2 Solution for Facebook fanpage apps.

Partner: Shelle-K | Custom graphic and web developer

When MIND is weak situation is a PROBLEM, when MIND is balanced situation is CHALLENGE, when MIND is strong situation is an OPPORTUNITY πŸ˜‰

Backup mysql database to amazon S3

Below is the simple code to create sql script of database on Amazon EC2 server using “mysqldump”…

then upload this sql script to Amazon S3 bucket using command line S3 tool “s3cmd”…


$sqlbackup="/usr/bin/mysqldump -v -u root -h localhost -r /var/www/html/backup/".date("Y-m-d-H-i-s")."_db.sql -pdbusername  databasename 2>&1";


implode("<br /> "$o);

$file "/var/www/html/backup/".date("Y-m-d-H-i-s")."_db.sql";

$bucket "s3bucketname";

exec("/usr/bin/s3cmd  put β€“acl-public β€“guess-mime-type  β€“config=/var/www/html/.s3cfg   ".$file."  s3://".$bucket."  2>&1"$o);

echo implode("<br /> "$o);


0 */12 * * * env php -q /var/www/html/s3bkup/s3bkup.php > /dev/null 2>&1 (per 12 hours)

You can set above php file as scheduled task (cronjob) for automated backup on Amazon S3 Bucket, I mostly use CloudBerry Explorer for Amazon S3 PRO for managing Amazon S3 files πŸ˜‰