Make a get request to the Instance Metadata Service. :type url_path: str :param url_path: The path component of the URL to make a get request. This arg is appended to the base_url that was provided in the initializer. :type retry_func: callable
(self, url_path, retry_func, token=None)
| 441 | return None |
| 442 | |
| 443 | def _get_request(self, url_path, retry_func, token=None): |
| 444 | """Make a get request to the Instance Metadata Service. |
| 445 | |
| 446 | :type url_path: str |
| 447 | :param url_path: The path component of the URL to make a get request. |
| 448 | This arg is appended to the base_url that was provided in the |
| 449 | initializer. |
| 450 | |
| 451 | :type retry_func: callable |
| 452 | :param retry_func: A function that takes the response as an argument |
| 453 | and determines if it needs to retry. By default empty and non |
| 454 | 200 OK responses are retried. |
| 455 | |
| 456 | :type token: str |
| 457 | :param token: Metadata token to send along with GET requests to IMDS. |
| 458 | """ |
| 459 | self._assert_enabled() |
| 460 | if not token: |
| 461 | self._assert_v1_enabled() |
| 462 | if retry_func is None: |
| 463 | retry_func = self._default_retry |
| 464 | url = self._construct_url(url_path) |
| 465 | headers = {} |
| 466 | if token is not None: |
| 467 | headers['x-aws-ec2-metadata-token'] = token |
| 468 | self._add_user_agent(headers) |
| 469 | for i in range(self._num_attempts): |
| 470 | try: |
| 471 | request = botocore.awsrequest.AWSRequest( |
| 472 | method='GET', url=url, headers=headers |
| 473 | ) |
| 474 | response = self._session.send(request.prepare()) |
| 475 | if not retry_func(response): |
| 476 | return response |
| 477 | except RETRYABLE_HTTP_ERRORS as e: |
| 478 | logger.debug( |
| 479 | "Caught retryable HTTP exception while making metadata " |
| 480 | "service request to %s: %s", |
| 481 | url, |
| 482 | e, |
| 483 | exc_info=True, |
| 484 | ) |
| 485 | raise self._RETRIES_EXCEEDED_ERROR_CLS() |
| 486 | |
| 487 | def _add_user_agent(self, headers): |
| 488 | if self._user_agent is not None: |
no test coverage detected