create_website_config ( $bucket, $opt )

Enables and configures an Amazon S3 website using the corresponding bucket as the content source. The website will have one default domain name associated with it, which is the bucket name. If you attempt to configure an Amazon S3 website for a bucket whose name is not compatible with DNS, Amazon S3 returns an InvalidBucketName error. For more information on bucket names and DNS, refer to Bucket Restrictions and Limitations.

To visit the bucket as a website a new endpoint is created in the following pattern: http://<bucketName>.s3-website-<region>.amazonaws.com. This is a sample URL for a bucket called example-bucket in the us-east-1 region. (e.g., http://example-bucket.s3-website-us-east-1.amazonaws.com)

Access

public

Parameters

Parameter

Type

Required

Description

$bucket

string

Required

The name of the bucket to use.

$opt

array

Optional

An associative array of parameters that can have the following keys:

  • indexDocument - string - Optional - The file path to use as the root document. The default value is index.html.
  • errorDocument - string - Optional - The file path to use as the error document. The default value is error.html.
  • curlopts - array - Optional - A set of values to pass directly into curl_setopt(), where the key is a pre-defined CURLOPT_* constant.
  • returnCurlHandle - boolean - Optional - A private toggle specifying that the cURL handle be returned rather than actually completing the request. This toggle is useful for manually managed batch requests.

Returns

Type

Description

CFResponse

A CFResponse object containing a parsed HTTP response.

Examples

Create a new website configuration.

// Instantiate the class
$s3 = new AmazonS3();
$bucket = 'my-bucket' . strtolower($s3->key);

// Create a website, using index.html as the root document and error.html as the error document.
$response = $s3->create_website_config($bucket);

// Success?
var_dump($response->isOK());
Result:
bool(true)

Create a new website configuration.

// Instantiate the class
$s3 = new AmazonS3();
$bucket = 'my-bucket' . strtolower($s3->key);

// Create a website, using home.html as the root document and 404.html as the error document.
$response = $s3->create_website_config($bucket, array(
	'indexDocument' => 'home.html',
	'errorDocument' => '404.html'
));

// Success?
var_dump($response->isOK());
Result:
bool(true)

Related Methods

Source

Method defined in services/s3.class.php | Toggle source view (21 lines) | View on GitHub

public function create_website_config($bucket, $opt = null)
{
    if (!$opt) $opt = array();
    $opt['verb'] = 'PUT';
    $opt['sub_resource'] = 'website';

    $xml = simplexml_load_string($this->website_config_xml);
    if (isset($opt['indexDocument']))
    {
        $xml->IndexDocument->Suffix = $opt['indexDocument'];
    }
    if (isset($opt['errorDocument']))
    {
        $xml->ErrorDocument->Key = $opt['errorDocument'];
    }

    $opt['body'] = $xml->asXML();

    // Authenticate to S3
    return $this->authenticate($bucket, $opt);
}

Copyright © 2010–2013 Amazon Web Services, LLC


Feedback