You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Logger.GetLogger(GetType()).InfoFormat("Invalid value {0} for {1} in profile {2}. A boolean true/false is expected.",ec2MetadataV1DisabledString,EC2MetadataV1DisabledField,profileName);
Logger.GetLogger(typeof(EC2InstanceMetadata)).Error(e,"Unable to contact EC2 Metadata service to obtain a metadata token. Attempting to access IMDS without a token.");
693
-
694
-
//If there isn't a status code, it was a failure to contact the server which would be
695
-
//a request failure, a network issue, or a timeout. Cache this response and fallback
696
-
//to IMDS flow without a token unless EC2MetadataV1Disabled is set to true. If the non
697
-
//token IMDS flow returns unauthorized, the useNullToken flag will be cleared and the IMDS
698
-
//flow will attempt to obtain another token.
699
-
700
-
if(EC2MetadataV1Disabled)
701
-
{
702
-
thrownewInvalidOperationException("Unable to retrieve token for use in IMDSv2 call and IMDSv1 has been disabled.");
703
-
}
704
-
705
-
if(httpStatusCode==null)
706
-
{
707
-
useNullToken=true;
708
-
}
709
-
710
-
//Return null to fallback to the IMDS flow without using a token.
@@ -735,16 +686,20 @@ private static List<string> GetItems(string relativeOrAbsolutePath, int tries, b
735
686
//token cannot be obtained we will fallback to not using a token.
736
687
if(token==null)
737
688
{
738
-
token=FetchApiToken(DEFAULT_RETRIES);
689
+
try
690
+
{
691
+
token=FetchApiToken(DEFAULT_RETRIES);
692
+
}
693
+
catch(InvalidOperationExceptione)
694
+
{
695
+
Logger.GetLogger(typeof(EC2InstanceMetadata)).InfoFormat("Failed to retrieve IMDS data \"{0}\" because IMDS API token could not be retrieved: {1}",relativeOrAbsolutePath,e.Message);
696
+
returnnull;// If we could not get a token then assume we are not running in an EC2 instance and return null.
0 commit comments