MCPcopy Create free account
hub / github.com/aws/aws-cli / InstanceMetadataProvider

Class InstanceMetadataProvider

awscli/botocore/credentials.py:1150–1177  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1148
1149
1150class InstanceMetadataProvider(CredentialProvider):
1151 METHOD = 'iam-role'
1152 CANONICAL_NAME = 'Ec2InstanceMetadata'
1153
1154 def __init__(self, iam_role_fetcher):
1155 self._role_fetcher = iam_role_fetcher
1156
1157 def load(self):
1158 fetcher = self._role_fetcher
1159 # We do the first request, to see if we get useful data back.
1160 # If not, we'll pass & move on to whatever's next in the credential
1161 # chain.
1162 metadata = fetcher.retrieve_iam_role_credentials()
1163 if not metadata:
1164 return None
1165 register_feature_id('CREDENTIALS_IMDS')
1166 logger.debug(
1167 'Found credentials from IAM Role: %s', metadata['role_name']
1168 )
1169 # We manually set the data here, since we already made the request &
1170 # have it. When the expiry is hit, the credentials will auto-refresh
1171 # themselves.
1172 creds = RefreshableCredentials.create_from_metadata(
1173 metadata,
1174 method=self.METHOD,
1175 refresh_using=fetcher.retrieve_iam_role_credentials,
1176 )
1177 return creds
1178
1179
1180class EnvProvider(CredentialProvider):

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected