简体   繁体   中英

Getting credentials for AWS V4 Signing when running on a EC2 instance with IAM role

I have the following AWS Javascript SDK code, to sign requests for AWS Elasticsearch:

var signer = new AWS.Signers.V4(req, 'es');
signer.addAuthorization(creds, new Date());

I need credentials (creds) for the addAuthorization() call. When running locally I do this:

var creds = AWS.config.credentials;

But this does not work on an EC2 instance running with an IAM role.

My question is how to get the credentials object to do the manual signing?

Or, if there is another way to V4 sign with running under IAM, what is it?

你有尝试过吗?

var creds = new AWS.EnvironmentCredentials('AWS');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM