@@ -37,23 +37,23 @@ def get_fleet_instance_id(self):
3737 return self .host_name
3838
3939 @classmethod
40- def __look_up_host_name (cls ):
40+ def __look_up_host_name (cls , token ):
4141 """
4242 The id of the fleet element. Eg. host name in ec2.
4343 """
44- return cls .__look_up_with_IMDSv2 (EC2_HOST_NAME_URI )
44+ return cls .__look_up_with_IMDSv2 (EC2_HOST_NAME_URI , token )
4545
4646 @classmethod
47- def __look_up_instance_type (cls ):
47+ def __look_up_instance_type (cls , token ):
4848 """
4949 The type of the instance. Eg. m5.2xlarge
5050 """
51- return cls .__look_up_with_IMDSv2 (EC2_HOST_INSTANCE_TYPE_URI )
51+ return cls .__look_up_with_IMDSv2 (EC2_HOST_INSTANCE_TYPE_URI , token )
5252
5353 @classmethod
54- def __look_up_with_IMDSv2 (cls , url ):
54+ def __look_up_with_IMDSv2 (cls , url , token ):
5555 return http_get (url = url ,
56- headers = {EC2_METADATA_TOKEN_HEADER_KEY : cls . __look_up_ec2_api_token () }) \
56+ headers = {EC2_METADATA_TOKEN_HEADER_KEY : token }) \
5757 .read ().decode ()
5858
5959 @classmethod
@@ -65,9 +65,10 @@ def __look_up_ec2_api_token(cls):
6565 @classmethod
6666 def look_up_metadata (cls ):
6767 try :
68+ token = cls .__look_up_ec2_api_token ()
6869 return cls (
69- host_name = cls .__look_up_host_name (),
70- host_type = cls .__look_up_instance_type ()
70+ host_name = cls .__look_up_host_name (token ),
71+ host_type = cls .__look_up_instance_type (token )
7172 )
7273 except Exception :
7374 log_exception (logger , "Unable to get Ec2 instance metadata, this is normal when running in a different "
0 commit comments