Seeking clear documentation/example code for simple Lucee/S3 file handling

Good afternoon, I am wondering if there are any simple “Getting Started” examples available for Lucee/S3 integration. I am primarily looking for basic information on file handling.

I have a Lucee Server and an S3 bucket, and I’d like the Lucee Server to upload files to the S3 bucket and delete them as needed.

I have attempted to use the Youtube videos here and here, but neither have been particularly helpful. I have duplicated the code from those videos into my system and I do not have any success at all.

I am of the understanding that there is a method for using the access id/key in the application.cfc, sort of hinted at here, but these code snippets result in errors in every configuration I could think of.

I’m mostly just looking for an extremely straightforward, uncomplicated example of the very basics of a read/write operation from a Lucee server to an S3 bucket, and how to set up the code to handle that. If anybody has any suggestions on where I can find this information, if it’s already been written somewhere, I’d be quite grateful. If it’s not written somewhere, then perhaps this thread can assist somebody in the future.

OS: Linux (4.4.0-1128-aws) 64bit
Java Version: 1.8.0_292 (Private Build) 64bit
Tomcat Version: Apache Tomcat/8.0.32 (Ubuntu)
Lucee Version: Lucee 5.3.8.201

It’s possible I’ve found a solution AND another question, though I am unsure if this would be the most secure method.

In the Application.cfc I have the following:

component {	
   this.s3.accesskeyid= "xx_myaccesskeyid_xx";
   this.s3.awssecretkey= "xx_myawssecretkey_xx";
   this.s3.defaultlocation = "xx_mys3bucketname_xx";
   boolean function onRequestStart(string targetPage) {
      url["s3url"] = "https://xx_mys3bucketname_xx";
      url["s3p"] = "s3://xx_mys3bucketname";
      return true;
   }
}

And in my .cfm page, I can use things like:

<cffile action="copy" source="a.png" destination = "#s3p#">
<cffile action="delete" file="#s3p#/a.png">

This seems to work. I have no idea whether this is good practice or not, but it’s what works, at least for now.

So now I have another question. I saw lots of things getting tossed around in the variety of “tutorials” available out there regarding mapping. Is there anything that is considered “best practices” for mapping for S3 interactions?

Also, I’m wondering if there is a way to avoid having my <img> urls pointing to the xx_mys3bucketname_xx.s3.us-west-2.amazonaws.com domain. Can that be reconfigured through mapping or some other method to display images as though they’re coming from my own domain?

I appreciate any help that is out there.

1 Like

I remember experimenting a little with S3 in the past, and I also had some issues trying to replicate and figure out the S3 source examples of the documentation. At that time, as far as I can remember, the issues were mostly because of some Amazons S3 permission settings or issues involved with the zone/region location of the bucket.

To my understanding there is no big difference doing file handling with S3 then with other file handling see file handling, with the connection protocol “S3://” in the mapping setting, but I remember that I’ve not done or experimented a lot.

What I’m missing is which errors exactly you’ve encountered and if they are related somehow to some of the issues with S3. Would be nice to know, so others would have more details to help.

UPDATE: didn’t see your last post resolving your first issue. Glad you are making progress. Thanks for sharing your efforts.

An alternative could be loading the image through a cfm file by using cfcontent

Update: another way would be to use cloudfront… please see this link on SO