Question

I'm running Coldfusion8 and am using the Amazon S3 Rest Wrapper CFC trying to set it up with a EU bucket.

I can use the cfc to set up buckets in the US, but whenever I'm changing to the EU setting, it does not work.

Here is the function being used:

<cffunction name="putBucket" access="public" output="false" returntype="boolean" description="Creates a bucket.">
    <cfargument name="bucketName" type="string" required="true">
    <cfargument name="acl" type="string" required="false" default="public-read">
    <cfargument name="storageLocation" type="string" required="false" default="">

    <cfset var strXML = "">
    <cfset var dateTimeString = GetHTTPTimeString(Now())>
    <cfset var destination = "http://s3.amazonaws.com/">

    <!--- Create a canonical string to send based on operation requested ---> 
    <cfset var cs = "PUT\n\ntext/html\n#dateTimeString#\nx-amz-acl:#arguments.acl#\n/#arguments.bucketName#">

    <cfset var signature = createSignature(cs)>
    <!--- added switch to EU --->
    <cfif arguments.storageLocation EQ "EU">
        <cfset destination = "http://s3-eu-west-1.amazonaws.com/">
    </cfif>

    <!--- Create a proper signature --->
    <cfif compare(arguments.storageLocation,'')>
        <cfsavecontent variable="strXML">
            <CreateBucketConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/"><LocationConstraint>#arguments.storageLocation#</LocationConstraint></CreateBucketConfiguration>
        </cfsavecontent>
    <cfelse>
        <cfset strXML = "">
    </cfif>

    <!--- put the bucket via REST --->
    <cfhttp method="PUT" url="#destination##arguments.bucketName#" charset="utf-8">
        <cfhttpparam type="header" name="Content-Type" value="text/html">
        <cfhttpparam type="header" name="Date" value="#dateTimeString#">
        <cfhttpparam type="header" name="x-amz-acl" value="#arguments.acl#">
        <cfhttpparam type="header" name="Authorization" value="AWS #variables.accessKeyId#:#signature#">
        <cfhttpparam type="body" value="#trim(strXML)#">
    </cfhttp>

    <cfreturn true>
</cffunction>

I have added the switch to the EU region URL, but this doesn't work either.

Any idea what I need to do in order to create a bucket in the EU?

EDIT:
I have fixed the regional values. It still doesn't work tough, because if I pass a regional value other than "", this line:

 <cfif compare(arguments.storageLocation,'')>
    <cfsavecontent variable="strXML">
       <CreateBucketConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/"><LocationConstraint>#arguments.storageLocation#</LocationConstraint></CreateBucketConfiguration>
     </cfsavecontent>
 <cfelse>
     <cfset strXML = "">
 </cfif>

will produce a strXML like so:

 <CreateBucketConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/"><LocationConstraint>#arguments.storageLocation#</LocationConstraint></CreateBucketConfiguration> 

which creates the bad request error again

Was it helpful?

Solution

You need to use the proper values for the storage location. From the API documents, I believe those values are:

The preferred geographical location for the bucket. [Allowed values: AmazonS3::REGION_US_E1, AmazonS3::REGION_US_W1, AmazonS3::REGION_EU_W1, AmazonS3::REGION_APAC_SE1, AmazonS3::REGION_APAC_NE1]

OTHER TIPS

If you are running this on Linux, you could alternatively use the S3CMD tools

sudo apt-get install s3cmd

You will then need to run the configuration procedure or even better, build and maintain configuration in your source control and deploy to the server making the S3 commands

s3cmd --configure

Generally, the configuration includes information (in particular keys) about your S3 account. Make sure if you use a file you set permissions on the file correctly so you don't have to execute the s3cmd's as root

and then in you application

<cfexecute name="s3cmd" arguments="mb s3://my-new-bucket-name">
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top