-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Temporary credentials from EC2 Metadata Service are not reflected in the AWS.config.credentials attribute, breaks S3.getSignedUrl(). #246
Comments
This is expected behavior of the SDK. Credentials can be loaded asynchronously, something we support in the SDK. Since loading anything from HTTP is an asynchronous call in Node, the only way to load credentials would be to wait until the loading completes. The SDK already waits for this in its internal request lifecycle, so you don't have to do anything yourself. Note that getSignedUrl() has both a synchronous and asynchronous mode. The synchronous mode is a convenience for certain configurations (static or environment provided credentials), but we explicitly document the caveat for asynchronous credential providers in the documentation for getSignedUrl(). If you do want to ensure that credentials are loaded before you do anything with the SDK to inspect the credentials, you can call: AWS.config.getCredentials(function(err) {
// no err means AWS.config.credentials is loaded
}); This is what we transparently do for you before signing each request. Keep in mind that you should still not try to use getSignedUrl synchronously with async credentials even if you've preloaded them with the above code. If your credentials expire, the SDK will attempt to (asynchronously) refresh credentials from your metadata service, something that getSignedUrl's synchronous mode cannot support. Hope that clarifies. |
Thanks very much for your prompt response and clarification.
|
@maitreya1975 thanks, it looks like getCredentials is marked private for now, though it's likely something we can expose as the public API. I will keep this issue open to track if we can update the docs for that. |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread. |
This is a bug I noticed with the following versions of the AWS SDK for JavaScript:
2.0.0-rc11, 2.0.0-rc9, 1.18.0.
I am testing against node v0.10.26.
The SDK does not automatically configure the AWS.config singleton with credentials from the EC2 Metadata service.
This is related to a documentation bug raised recently: #153
Actual invocation of the services (making REST calls to S3, DynamoDB, SNS, SQS) does work but the AWS.config.credentials attribute is not setup correctly.
This impacts ability to query the AWS.config object to get the credentials that are currently in use. Also, this breaks the S3.getSignedUrl() method.
See an example code here that exhibits this behavior:
I am running an EC2 instance that has an IAM Role and associated temporary credentials from the EC2 Metadata Service. See output below:
The SDK picks up credentials set in the Environment variables correctly and S3.getSignedUrl returns a URL signed with the credentials. For example:
However, it does not pick up credentials from the EC2 metadata service. Also, note that the S3 getSignedUrl method now just returns the S3 hostname and no other parameters:
The text was updated successfully, but these errors were encountered: