title: Symfony2 Amazon SDK Setting Credentials Dynamically
body: <p>I've gotten <code>Amazon SDK</code> to work well with <strong>Symfony2</strong>. It involves loading the <code>sdk.class.php</code> right into the <code>autoload.php</code>. I'm not sure if this is best, but it seems be. </p>
  
  <p>But my main problem is loading the Credentials. <strong>Amazon wants you too..</strong> edit the <code>config.inc.php</code> and put it either in the <code>vendor directory</code> OR in the <code>HOME</code>. Option 1 isnt good because it involves modifying a Repo which would get overwritten on updates and <code>HOME</code> doesn't work because it's outside my project directory. </p>
  
  <p><strong>What I'm doing now,</strong> <em>inside <code>autoload.php</code></em> is loading the <code>sdk.class.php</code> and then running <code>CFCredentionals:set(array());</code> .. my code is below. Normally I'd want to do a Dependency Injection or use Parameters.. but I can't figure out any other way to get the Credentials loaded. Also, I don't want to load them when I instantiate the Services. like <code>$e3 = new AmazonE3(array($a,$s));</code>. It's so much cleaner and stream lined to have the credentials pre-loaded so you can just use <code>$e3 = new AmazonE3();</code></p>
  
  <p><strong>So this is what works -- but there's got to be a better way</strong></p>
  
  <pre><code> require_once __DIR__. '../../vendor/AmazonPHPSDK/sdk.class.php';
      CFCredentials::set(array(
         '@default' =&gt; array(
              'key' =&gt; '1dfXXXXXXXXXXXXXXXXXXXXXZ82',
              'secret' =&gt; '8tCXXXXXXXXXXXXXXXXXXXXXXfjB+Q',
              'default_cache_config' =&gt; 'apc',
               'certificate_authority' =&gt; false
          )));
  </code></pre>
  
  <p>There's nothing wrong with how Amazon wants us to load the credentials. It just just doesn't seem to go well with the Symfony2 framework. Having an Array with Access Credentials in the autoload.php just doesn't seem right.</p>