amazon-archives / aws-sdk-core-ruby

This repository has moved to the master branch of aws/aws-sdk-ruby
https://github.com/aws/aws-sdk-ruby
243 stars 57 forks source link

InstanceProfileCredentials require that refresh! be called before they can be used #193

Closed patrickbcullen closed 9 years ago

patrickbcullen commented 9 years ago

I was trying to use the Aws::InstanceProfileCredentials and kept getting an error that the credentials were not set. I finally figure out the solution, call the refresh! method before trying to use the credentials.

credentials = Aws::InstanceProfileCredentials.new(retries: 3)
credentials.refresh!
ec2 = Aws::EC2::Client.new(region: opts[:region], credentials: credentials)

It would be more intuitive if the InstanceProfileCredentials called the refresh method in its constructor.

trevorrowe commented 9 years ago

Credentials should be loaded during construction. You should not need to forcibly call #refresh! on newly created instance profile credentials. That said, while digging into the issue, I found a possible related issue that could cause your problems.

The bug caused instance profile credentials to not refresh if the expiration date was nil. This could happen under a few scenarios where the initial load of credentials fails because the instance metadata service is not responding yet, for example. The related fix treats a nil expiration as stale and accessing any of its attributes will force a refresh.

trevorrowe commented 9 years ago

The fix is available in the released SDK and this should be resolved. Please re-open if the issue persists.