title: How to use temporary AWS keys instead of env variables with the Java AWS SDK?
body: <p>I'm using <code>saml2aws</code> to generate temporary AWS keys for my clients. Previously I was using environmental variables:</p>
  
  <pre><code>aws_access_key_id=MY KEY
  aws_secret_access_key=MY SECRET
  </code></pre>
  
  <p>After authenticating with <code>saml2aws</code> my <code>~/.aws/config</code> file looks like this <em>(unchanged)</em>:</p>
  
  <pre><code>[default]
  output=json
  </code></pre>
  
  <p>And my <code>~/.aws/credentials</code> looks like this:</p>
  
  <pre><code>[default]
  aws_access_key_id        = MY KEY ID
  aws_secret_access_key    = MY KEY
  aws_session_token        = MY SESSION TOKEN
  aws_security_token       = MY TOKEN
  x_principal_arn          = MY ARN
  x_security_token_expires = TIME
  </code></pre>
  
  <p>When I try this from the cli with <code>aws s3 ls</code> it works but when I try to access S3 from the Java SDK:</p>
  
  <pre><code>AmazonS3Client(ProfileCredentialsProvider())
                  .listObjects(ListObjectsRequest()
                          .withBucketName("some-bucket")
                          .withPrefix("some-prefix")
                          .withDelimiter("/")
                          .withMaxKeys(10000))
  </code></pre>
  
  <p>I get:</p>
  
  <blockquote>
    <p>com.amazonaws.AmazonClientException: Unable to load credentials into profile. Profile Name or AWS Access Key ID or AWS Secret Access Key missing for a profile.</p>
  </blockquote>
  
  <p>And it doesn't work even if I explicitly try to use the <code>default</code> profile: <code>ProfileCredentialsProvider("default")</code> or even if I don't set a provider at all!</p>
  
  <p>What am I doing wrong?</p>