如何使用Coldfusion在Amazon S3上创建EU存储桶?

时间:2012-08-10 11:53:22

标签: coldfusion upload amazon-s3 amazon-web-services bucket

我正在运行Coldfusion8并正在使用Amazon S3 Rest Wrapper CFC尝试使用欧盟存储桶进行设置。

我可以使用cfc在美国设置存储桶,但每当我更改为EU设置时,它都不起作用。

以下是使用的功能:

<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>

我已将切换添加到欧盟区域网址,但这也不起作用。

知道我需要做些什么才能在欧盟创建一个桶?

修改
我已经修复了区域价值。它仍然不起作用,因为如果我传递""以外的区域值,则该行:

 <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>

会产生类似的strXML:

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

再次创建bad request错误

2 个答案:

答案 0 :(得分:1)

您需要使用proper values for the storage location。从API文档中,我相信这些值是:

  

水桶的首选地理位置。 [允许的值:AmazonS3 :: REGION_US_E1,AmazonS3 :: REGION_US_W1,AmazonS3 :: REGION_EU_W1,AmazonS3 :: REGION_APAC_SE1,AmazonS3 :: REGION_APAC_NE1]

答案 1 :(得分:0)

如果您在Linux上运行它,您也可以使用S3CMD工具

sudo apt-get install s3cmd

然后,您需要运行配置过程,甚至更好,在源代码管理中构建和维护配置,并部署到发出S3命令的服务器

s3cmd --configure

通常,配置包含有关S3帐户的信息(特别是密钥)。确保您使用的文件是否正确设置了文件的权限,因此您不必以root身份执行s3cmd

然后在你的应用程序中

<cfexecute name="s3cmd" arguments="mb s3://my-new-bucket-name">