Reputation: 25
My s3 account has different buckets and some of them belongs to EU region and some to US region. How can I specify the region when I connect to s3 via Coldfusion. Because now I can only access the buckets in US region only (I connected to s3 only using secret and access keys). My s3 component init function is as below;
<cffunction name="init" access="public" returnType="s3" output="false">
<cfargument name="accessKeyId" type="string" required="true">
<cfargument name="secretAccessKey" type="string" required="true">
<cfset variables.accessKeyId = arguments.accessKeyId>
<cfset variables.secretAccessKey = arguments.secretAccessKey>
<cfreturn this>
</cffunction>
Upvotes: 0
Views: 638
Reputation: 46
S3 bucket names are unique across the all AWS buckets. Only while creating bucket you need to provide region and all objects will created and accessed from the same region (while creating or accessing object you only need to provide bucket not region).
In ColdFusion you can define default location at application level using property "s3.defaultLocation" or while creating bucket using attribute storeLocation. e.g.
this.se.defaultLocation = "eu-west-1"
<cfdirectory action="create" directory="s3://bucketName" storeLocation="eu-west-1" storeacl="#perms#">
Creating a file in bucket created (No need to specify region):
<cffile action="write" file="s3://bucketName/somefile.txt" output="sdgkjfcskbkcjsa" />
Listing files in bucket (No need to specify region):
<cfdirectory action="list" directory="s3://bucketName" name="tmp">
<cfdump var="#tmp#"/>
Even new regions of AWS works well with ColdFusion older versions. I have tried with ColdFusion 2016 and 2018 and new regions of AWS.
Upvotes: 1
Reputation: 565
S3 bucket names are unique across all of AWS. When you make a call to S3 using built-in CFML support, you do not specify a region. AWS automagically routes the request from your CFML app to the correct region.
Prior to ColdFusion 2018, Update 2, ColdFusion S3 integration only worked with regions that supported the older, v2 signature style for making requests to AWS. ColdFusion 2018, Update 2 introduced support for v4 signatures, which are supported in all regions. If you are using an older version of ColdFusion, you can only make S3 requests to regions which support v2 signatures — that means regions which went online prior to 2016. Most US regions went online prior to 2016, while most EU regions did not.
If you are using a version of ColdFusion prior to CF 2018, Update 2, you will need to use the AWS Java SDK to make S3 requests to regions which require the v4 signature, or sign the S3 requests manually using the v4 method. I do not recommend that route. Using the AWS Java SDK is straightforward. I have numerous examples of how to use it on my blog.
Upvotes: 2