Jump to content

Getting Amazon AWS SDK to work with PW

Recommended Posts

Hi all,

I am trying to use Amazon S3 to store video files for a client. I am having trouble getting the SDK to work. I am sure it is a stupid error on my part but my head is sore from banging it against my desk and I thought I would finally ask for some help. 

I am running PW 3.0.11 on NGINX.

1. Amazon recommends using Composer to install the SDK. I was not sure where in the path to install the SDK so I put composer in the /site folder and installed the SDK there (putting vendor at the same level as modules), then I put the require and uses statements in _init.php. I always got an error saying it could not load the aws or s3 classes from the library.

2. So, then I tried to use aws.phar. I put that in the /site directory but once again, no matter what I do, it will not load with the following error:

require(): Failed opening required '/site/aws.phar'

The file is there with proper permissions and the code for loading is:

// --- amazon S3 stuff
require $config->urls->site . 'aws.phar';

$s3 = new Aws\S3\S3Client([
    'version' => 'latest',
    'region'  => 'us-standard',

So, here are my questions:

1. In general, where is the correct place to put a php library? It is not a PW module so I assume it should not go in the modules folder.

2. Should I use Composer to install the SDK? If so, where do I put the files? Should I add the AWS SDK to the main composer.json file or put it somewhere else?

3. If I don't use Composer, where do I put the aws.phar file so that PW can load it?

4. Should I not put the 'require' in the _init.php file and move it to another file (_func.php)?

I am sure there is a massive face-palm in my future when this gets sorted out.


Share this post

Link to post
Share on other sites

1. There's not final answer, but your choice makes sense.

2. Use composer

4. use 'require __DIR__ . "/vendor/autoload.php";' in your config.php

  • Like 1

Share this post

Link to post
Share on other sites

@LostKobrakai: Thanks. I will take your suggestions and I will report back on my success or failure.

Share this post

Link to post
Share on other sites

Newest update after trying @LostKobrakai's suggestions:

1. Used Composer in root of site. AWS is in the vendor folder.

2. 3.0.11 index.php file calls the composer autoloader so I did not add the require 'vendor/autoloader.php' to the config.php file.

3. Tried to create an S3 object in _init.php using the following:

$s3 = new Aws\S3\S3Client([
    'version' => 'latest',
    'region'  => 'us-standard',

but get the following error:

Class 'ProcessWire\Aws\S3\S3Client' not found

The code not sure why it is trying to reference Processwire\Aws...


Share this post

Link to post
Share on other sites

The code example probably expects you to be in a non namespaced environment, where it would work. You need to either use a "use" statement in the beginning of your file or call the class with a leading backslash \Aws\S3….

  • Like 2

Share this post

Link to post
Share on other sites

@LostKobrakai: That was it. I am a junior PHP developer at best and have not learned the whole namespaces features yet.

Thanks for the help!

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Lex Sanchez
      Hi everyone:
      I do not know if someone before using ProcessWire with AWS CloudFront, currently I have problems with the login, it does not work for any reason, when I check in the logs generated by ProcessWire, it only indicates This request was aborted because it appears to be forged. (in /wire/core/SessionCSRF.php line 190).
      I have allowed CloudFront to forward all headers, cookies and allow all methods (GET, POST, PUT).
      When I perform the same process from the ip server if it works or from the balancer.
    • By FrancisChung
      Has anyone come across this issue where Amazon Cloudfront seems to refuse to cache a certain small number of static objects?
      I've tried invaliding the cache (root path) several times to no avail.
      I had a look at the file permissions of the objects in question, and they seemed all ok.
      I've also gone into the Amazon Console and there are no errors logged.
      You can see more details of this here :
      I recently upgraded this test site to PW 3.062 from PW 2.8.x and noticed this was happening. I'm also running the latest version of Procache on this site.
    • By Karl_T
      Short question: is it possible that Processwire uses AWS S3 with s3fs as a remote file system(mount to asset folder)? Please advise anything that have to be take care of.
      I am currently trying to make Processwire running inside AWS Beanstalk as I want to take advantages of the auto scaling function that my client wanted.
      I have found a discussion here: 
      By reading this and the link inside, I realize that to use the auto scaling I need to configure my web server to be stateless. So, I was looking for a method that can serve the purpose and then I found s3fs.  s3fs is a FUSE filesystem that allows you to mount an Amazon S3 bucket as a local filesystem, quoted from their github. I guess that mounting s3 bucket using s3fs to the asset folder should be the right thing to do.
      My site needs many image upload as it is an e-commerce site using padloper while the admin always using the local file system for images. I have thought of using modules like AmazonS3Cloudfront or FieldtypeFileS3. It seems like those modules are not support my use case. s3fs suits better and more simple. One of my concerns is that I am not sure can the URL of the images can be generated by the default API like $image->url correctly. 
      Before implementing this, I would like to ask the advise from anyone having implemented this with processwire as I am new to AWS. Is it possible? Any better alternatives?
      I think if not implementing auto scaling, it is also good to separate asset away in some cases, like reducing requests. Thank you for your reading. 
    • By modifiedcontent
      Has anyone successfully installed Processwire on an Amazon EC2 instance/virtual server?
      Which configuration works; Amazon Linux or one of the other flavors?
      How do you get file permissions and the database working?
      Which lines in .htaccess cause problems on Amazon AWS? 
      What are the pitfalls to watch out for?
      Why can't I get it working...?
      The first problem I run into is an error message that the installer doesn't have write access and that I should manually rename the 'site-myprofile' folder to 'site'. Attempt to chmod all the files and folders to 777 don't seem to have any effect on that and some files do get written fine.
      But I keep ending up with inaccessable pages and fatal server errors. I am not asking you to solve my problem. I am curious what other people's experiences are with this. Can it be done or am I wasting my time?
  • Create New...