title: How to use IAM role to access resources using temporary credentials?
body: <p>I'm using AWS IAM roles that allows an instance to have access to certain resources using temporary API credentials (access key, secret key and security token).</p>
  
  <p>When I test the temporary credentials using this ruby script, it runs without any problems :</p>
  
  <pre><code>require 'rubygems'
  require 'aws-sdk'
  AWS.config(
      :access_key_id     =&gt; "MY ACCESS KEY GOES HERE",
      :secret_access_key =&gt; "MY SECRET KEY GOES HERE",
      :session_token     =&gt; "MY TOKEN GOES HERE")
  s3 = AWS::S3.new()
  myfile = s3.buckets['My-Config'].objects["file.sh"]
  File.open("/tmp/file.sh", "w") do |f|
      f.write(myfile.read)
  end
  </code></pre>
  
  <p>But when using command line to run cfn-describe-stacks I get an error:</p>
  
  <pre><code>export AWS_CREDENTIAL_FILE=aws_credentials.cfg
  cfn-describe-stacks
  cfn-describe-stacks:  Refused: The security token included in the request is invalid
  </code></pre>
  
  <p>and here is my aws_credentials.cfg :</p>
  
  <pre><code>AWSAccessKeyId=MY ACCESS KEY
  AWSSecretKey=My SECRET KEY
  AWSToken="MY TOKEN=="
  </code></pre>
  
  <p>So what am i missing here ? Thank you!</p>