I guess the main concern I was having was to having to keep uploading my software package with the library each time I was making changes to my application knowing that the library itself which was responsible for nearly 80-90% of the total size of the upload package was never changing. That is why I wanted to know if there was a way to load this library into my final application in the cloud without having to actually upload it.
So at first, I pondered on whether I could store the library in S3 and load it from there. But as @Dan Farrell pointed out, that will mean the application would have to load the library with every request which is certainly not the right way to go.
Eventually after doing some research and hands on with Composer I was able to achieve what I wanted to do. AWS will automatically load dependencies using composer if that configuration is presented in the root folder of the application package being uploaded. Since I could add the library as a dependency to the application along with other dependencies, and AWS would run the dependency downloads on deployment it meant that my application packages were light and only contained my domain specific code. So my final composer.json file was like -
{
"require": {
"cakephp/cakephp": "2.10.*",
"aws/aws-sdk-php": "2.*",
"stripe/stripe-php": "^5.8",
"facebook/graph-sdk": "^5.6"
},
"config": {
"vendor-dir": "./app/Vendor/"
}
}
In terms of my application code, the only thing I needed to change was the location of the Cake Library. Since I had configured the composer to load dependencies into the app/Vendor folder, I had to change the path to the library in the index.php file in app/webroot.
But surprisingly enough, the CakePHP authors have already provisioned this. There is the initial declaration of the path which is used by default when the library is inline with the app folder. That just needs to be commented out - See below -
/**
* The absolute path to the "cake" directory, WITHOUT a trailing DS.
*
* Un-comment this line to specify a fixed path to CakePHP.
* This should point at the directory containing `Cake`.
*
* For ease of development CakePHP uses PHP's include_path. If you
* cannot modify your include_path set this value.
*
* Leaving this constant undefined will result in it being defined in Cake/bootstrap.php
*
* The following line differs from its sibling
* /lib/Cake/Console/Templates/skel/webroot/index.php
*/
//define('CAKE_CORE_INCLUDE_PATH', ROOT .DS. 'lib'); <-- Comment this line out
The next couple of lines will set the library path to the path where composer would have downloaded the same -
/**
* This auto-detects CakePHP as a composer installed library.
* You may remove this if you are not planning to use composer (not recommended, though).
*/
$vendorPath = ROOT . DS . APP_DIR . DS . 'Vendor' . DS . 'cakephp' . DS . 'cakephp' . DS . 'lib';
$dispatcher = 'Cake' . DS . 'Console' . DS . 'ShellDispatcher.php';
if (!defined('CAKE_CORE_INCLUDE_PATH') && file_exists($vendorPath . DS . $dispatcher)) {
define('CAKE_CORE_INCLUDE_PATH', $vendorPath);
}
And that's how I saved having to upload 7.2MB every time down to 2.6MB which for an internet connection with low upload speeds has meant an improvement in the time required to upload a new application version with the same output.
Hope this helps.