How to use the EC2MetadataCredentials function from aws-sdk

Find comprehensive JavaScript aws-sdk.EC2MetadataCredentials code examples handpicked from public code repositorys.

13
14
15
16
17
18
19
20
21
22

// if iamRole is set attempt to fetch credentials from the Metadata Service
if (this.config.iamRole) {
  if (this.config.iamRole == 'any') {
    // If the iamRole is set to any, then attempt to fetch any available credentials
    ms = new AWS.EC2MetadataCredentials();
    ms.refresh(function(err) {
      if (err) { console.log('Failed to fetch IAM role credentials: ' + err); }
      self.config.credentials = ms;
      setEmitter();
fork icon53
star icon80
watch icon5

80
81
82
83
84
85
86
87
88
options.daemon = flags.get('daemon')
options.stdout = flags.get('stdout')

// Fallback to IAM based credentials.
if (!options.accessKeyId) {
  options.credentials = new AWS.EC2MetadataCredentials({
    host: options.metadataServiceHost || '169.254.169.254'
  })
}
fork icon2
star icon10
watch icon162

0
1
2
3
4
5
6
7
8
9
10
var AWS = require("aws-sdk");


module.exports = async function({ aws_profile }) {
  AWS.CredentialProviderChain.defaultProviders = [
    function () {
      return new AWS.EC2MetadataCredentials();
    },
    function () {
      return new AWS.SharedIniFileCredentials({
        profile: aws_profile ? aws_profile : "interactives",
fork icon1
star icon0
watch icon0

115
116
117
118
119
120
121
122
123
124
// Load AWS credentials from environment
AWS.CredentialProviderChain.defaultProviders = [
	() => new AWS.EnvironmentCredentials("AWS"),
	() => new AWS.EnvironmentCredentials("AMAZON"),
	() => new AWS.SharedIniFileCredentials({ profile: config.profile || "default" }),
	() => new AWS.EC2MetadataCredentials(),
];

(new AWS.CredentialProviderChain()).resolve((err, cred) => {
	if (err) {
fork icon0
star icon0
watch icon0

5
6
7
8
9
10
11
12
13
const region = process.env[`${prefix}_REGION`] ? process.env[`${prefix}_REGION`] : config.region;

AWS.CredentialProviderChain.defaultProviders = [
  () => new AWS.EnvironmentCredentials(prefix),
  () => new AWS.SharedIniFileCredentials({ profile: config.profile || 'default' }),
  () => new AWS.EC2MetadataCredentials()
];

const chain = new AWS.CredentialProviderChain();
fork icon0
star icon0
watch icon1

+ 13 other calls in file

76
77
78
79
80
81
82
83
84
85
const region = sourceOptions['region'];
const useRoleArn = sourceOptions['instance_metadata_credentials'] === 'aws_arn_role';

let credentials = null;
if (useAWSInstanceProfile) {
  credentials = new AWS.EC2MetadataCredentials({ httpOptions: { timeout: 5000 } });
} else if (useRoleArn) {
  const assumeRoleCredentials = await this.getAssumeRoleCredentials(sourceOptions['role_arn']);
  credentials = new AWS.Credentials(
    assumeRoleCredentials.accessKeyId,
fork icon0
star icon0
watch icon147