Python botocore.awsrequest() Examples
The following are 19
code examples of botocore.awsrequest().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
botocore
, or try the search function
.
Example #1
Source File: utils.py From aws-builders-fair-projects with Apache License 2.0 | 6 votes |
def _get_response(self, full_url, headers, timeout): try: AWSRequest = botocore.awsrequest.AWSRequest request = AWSRequest(method='GET', url=full_url, headers=headers) response = self._session.send(request.prepare()) response_text = response.content.decode('utf-8') if response.status_code != 200: raise MetadataRetrievalError( error_msg=( "Received non 200 response (%s) from ECS metadata: %s" ) % (response.status_code, response_text)) try: return json.loads(response_text) except ValueError: error_msg = ( "Unable to parse JSON returned from ECS metadata services" ) logger.debug('%s:%s', error_msg, response_text) raise MetadataRetrievalError(error_msg=error_msg) except RETRYABLE_HTTP_ERRORS as e: error_msg = ("Received error when attempting to retrieve " "ECS metadata: %s" % e) raise MetadataRetrievalError(error_msg=error_msg)
Example #2
Source File: utils.py From deepWordBug with Apache License 2.0 | 6 votes |
def _get_response(self, full_url, headers, timeout): try: AWSRequest = botocore.awsrequest.AWSRequest request = AWSRequest(method='GET', url=full_url, headers=headers) response = self._session.send(request.prepare()) response_text = response.content.decode('utf-8') if response.status_code != 200: raise MetadataRetrievalError( error_msg=( "Received non 200 response (%s) from ECS metadata: %s" ) % (response.status_code, response_text)) try: return json.loads(response_text) except ValueError: raise MetadataRetrievalError( error_msg=("Unable to parse JSON returned from " "ECS metadata: %s" % response_text)) except RETRYABLE_HTTP_ERRORS as e: error_msg = ("Received error when attempting to retrieve " "ECS metadata: %s" % e) raise MetadataRetrievalError(error_msg=error_msg)
Example #3
Source File: utils.py From AWS-Transit-Gateway-Demo-MultiAccount with MIT License | 6 votes |
def _get_response(self, full_url, headers, timeout): try: AWSRequest = botocore.awsrequest.AWSRequest request = AWSRequest(method='GET', url=full_url, headers=headers) response = self._session.send(request.prepare()) response_text = response.content.decode('utf-8') if response.status_code != 200: raise MetadataRetrievalError( error_msg=( "Received non 200 response (%s) from ECS metadata: %s" ) % (response.status_code, response_text)) try: return json.loads(response_text) except ValueError: raise MetadataRetrievalError( error_msg=("Unable to parse JSON returned from " "ECS metadata: %s" % response_text)) except RETRYABLE_HTTP_ERRORS as e: error_msg = ("Received error when attempting to retrieve " "ECS metadata: %s" % e) raise MetadataRetrievalError(error_msg=error_msg)
Example #4
Source File: utils.py From bash-lambda-layer with MIT License | 6 votes |
def _get_response(self, full_url, headers, timeout): try: AWSRequest = botocore.awsrequest.AWSRequest request = AWSRequest(method='GET', url=full_url, headers=headers) response = self._session.send(request.prepare()) response_text = response.content.decode('utf-8') if response.status_code != 200: raise MetadataRetrievalError( error_msg=( "Received non 200 response (%s) from ECS metadata: %s" ) % (response.status_code, response_text)) try: return json.loads(response_text) except ValueError: error_msg = ( "Unable to parse JSON returned from ECS metadata services" ) logger.debug('%s:%s', error_msg, response_text) raise MetadataRetrievalError(error_msg=error_msg) except RETRYABLE_HTTP_ERRORS as e: error_msg = ("Received error when attempting to retrieve " "ECS metadata: %s" % e) raise MetadataRetrievalError(error_msg=error_msg)
Example #5
Source File: utils.py From AWS-Transit-Gateway-Demo-MultiAccount with MIT License | 6 votes |
def _get_response(self, full_url, headers, timeout): try: AWSRequest = botocore.awsrequest.AWSRequest request = AWSRequest(method='GET', url=full_url, headers=headers) response = self._session.send(request.prepare()) response_text = response.content.decode('utf-8') if response.status_code != 200: raise MetadataRetrievalError( error_msg=( "Received non 200 response (%s) from ECS metadata: %s" ) % (response.status_code, response_text)) try: return json.loads(response_text) except ValueError: raise MetadataRetrievalError( error_msg=("Unable to parse JSON returned from " "ECS metadata: %s" % response_text)) except RETRYABLE_HTTP_ERRORS as e: error_msg = ("Received error when attempting to retrieve " "ECS metadata: %s" % e) raise MetadataRetrievalError(error_msg=error_msg)
Example #6
Source File: signers.py From bash-lambda-layer with MIT License | 5 votes |
def generate_presigned_url(self, request_dict, operation_name, expires_in=3600, region_name=None, signing_name=None): """Generates a presigned url :type request_dict: dict :param request_dict: The prepared request dictionary returned by ``botocore.awsrequest.prepare_request_dict()`` :type operation_name: str :param operation_name: The operation being signed. :type expires_in: int :param expires_in: The number of seconds the presigned url is valid for. By default it expires in an hour (3600 seconds) :type region_name: string :param region_name: The region name to sign the presigned url. :type signing_name: str :param signing_name: The name to use for the service when signing. :returns: The presigned url """ request = create_request_object(request_dict) self.sign(operation_name, request, region_name, 'presign-url', expires_in, signing_name) request.prepare() return request.url
Example #7
Source File: signers.py From aws-builders-fair-projects with Apache License 2.0 | 5 votes |
def generate_presigned_url(self, request_dict, operation_name, expires_in=3600, region_name=None, signing_name=None): """Generates a presigned url :type request_dict: dict :param request_dict: The prepared request dictionary returned by ``botocore.awsrequest.prepare_request_dict()`` :type operation_name: str :param operation_name: The operation being signed. :type expires_in: int :param expires_in: The number of seconds the presigned url is valid for. By default it expires in an hour (3600 seconds) :type region_name: string :param region_name: The region name to sign the presigned url. :type signing_name: str :param signing_name: The name to use for the service when signing. :returns: The presigned url """ request = create_request_object(request_dict) self.sign(operation_name, request, region_name, 'presign-url', expires_in, signing_name) request.prepare() return request.url
Example #8
Source File: utils.py From aws-builders-fair-projects with Apache License 2.0 | 5 votes |
def _get_request(self, url_path, retry_func): """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 taht was provided in the initializer. :type retry_func: callable :param retry_func: A function that takes the response as an argument and determines if it needs to retry. By default empty and non 200 OK responses are retried. """ if self._disabled: logger.debug("Access to EC2 metadata has been disabled.") raise self._RETRIES_EXCEEDED_ERROR_CLS() if retry_func is None: retry_func = self._default_retry url = self._base_url + url_path headers = {} if self._user_agent is not None: headers['User-Agent'] = self._user_agent for i in range(self._num_attempts): try: request = botocore.awsrequest.AWSRequest( method='GET', url=url, headers=headers) response = self._session.send(request.prepare()) if not retry_func(response): return response except RETRYABLE_HTTP_ERRORS as e: logger.debug( "Caught retryable HTTP exception while making metadata " "service request to %s: %s", url, e, exc_info=True) raise self._RETRIES_EXCEEDED_ERROR_CLS()
Example #9
Source File: signers.py From aws-extender with MIT License | 5 votes |
def generate_presigned_url(self, request_dict, operation_name, expires_in=3600, region_name=None, signing_name=None): """Generates a presigned url :type request_dict: dict :param request_dict: The prepared request dictionary returned by ``botocore.awsrequest.prepare_request_dict()`` :type operation_name: str :param operation_name: The operation being signed. :type expires_in: int :param expires_in: The number of seconds the presigned url is valid for. By default it expires in an hour (3600 seconds) :type region_name: string :param region_name: The region name to sign the presigned url. :type signing_name: str :param signing_name: The name to use for the service when signing. :returns: The presigned url """ request = create_request_object(request_dict) self.sign(operation_name, request, region_name, 'presign-url', expires_in, signing_name) request.prepare() return request.url
Example #10
Source File: utils.py From AWS-Transit-Gateway-Demo-MultiAccount with MIT License | 5 votes |
def _get_request(self, url_path, retry_func): """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 taht was provided in the initializer. :type retry_func: callable :param retry_func: A function that takes the response as an argument and determines if it needs to retry. By default empty and non 200 OK responses are retried. """ if self._disabled: logger.debug("Access to EC2 metadata has been disabled.") raise self._RETRIES_EXCEEDED_ERROR_CLS() if retry_func is None: retry_func = self._default_retry url = self._base_url + url_path headers = {} if self._user_agent is not None: headers['User-Agent'] = self._user_agent for i in range(self._num_attempts): try: request = botocore.awsrequest.AWSRequest( method='GET', url=url, headers=headers) response = self._session.send(request.prepare()) if not retry_func(response): return response except RETRYABLE_HTTP_ERRORS as e: logger.debug( "Caught retryable HTTP exception while making metadata " "service request to %s: %s", url, e, exc_info=True) raise self._RETRIES_EXCEEDED_ERROR_CLS()
Example #11
Source File: signers.py From AWS-Transit-Gateway-Demo-MultiAccount with MIT License | 5 votes |
def generate_presigned_url(self, request_dict, operation_name, expires_in=3600, region_name=None, signing_name=None): """Generates a presigned url :type request_dict: dict :param request_dict: The prepared request dictionary returned by ``botocore.awsrequest.prepare_request_dict()`` :type operation_name: str :param operation_name: The operation being signed. :type expires_in: int :param expires_in: The number of seconds the presigned url is valid for. By default it expires in an hour (3600 seconds) :type region_name: string :param region_name: The region name to sign the presigned url. :type signing_name: str :param signing_name: The name to use for the service when signing. :returns: The presigned url """ request = create_request_object(request_dict) self.sign(operation_name, request, region_name, 'presign-url', expires_in, signing_name) request.prepare() return request.url
Example #12
Source File: utils.py From AWS-Transit-Gateway-Demo-MultiAccount with MIT License | 5 votes |
def _get_request(self, url_path, retry_func): """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 taht was provided in the initializer. :type retry_func: callable :param retry_func: A function that takes the response as an argument and determines if it needs to retry. By default empty and non 200 OK responses are retried. """ if self._disabled: logger.debug("Access to EC2 metadata has been disabled.") raise self._RETRIES_EXCEEDED_ERROR_CLS() if retry_func is None: retry_func = self._default_retry url = self._base_url + url_path headers = {} if self._user_agent is not None: headers['User-Agent'] = self._user_agent for i in range(self._num_attempts): try: request = botocore.awsrequest.AWSRequest( method='GET', url=url, headers=headers) response = self._session.send(request.prepare()) if not retry_func(response): return response except RETRYABLE_HTTP_ERRORS as e: logger.debug( "Caught retryable HTTP exception while making metadata " "service request to %s: %s", url, e, exc_info=True) raise self._RETRIES_EXCEEDED_ERROR_CLS()
Example #13
Source File: signers.py From faces with GNU General Public License v2.0 | 5 votes |
def generate_presigned_url(self, request_dict, operation_name, expires_in=3600, region_name=None): """Generates a presigned url :type request_dict: dict :param request_dict: The prepared request dictionary returned by ``botocore.awsrequest.prepare_request_dict()`` :type operation_name: str :param operation_name: The operation being signed. :type expires_in: int :param expires_in: The number of seconds the presigned url is valid for. By default it expires in an hour (3600 seconds) :type region_name: string :param region_name: The region name to sign the presigned url. :returns: The presigned url """ request = create_request_object(request_dict) self.sign(operation_name, request, region_name, 'presign-url', expires_in) request.prepare() return request.url
Example #14
Source File: utils.py From bash-lambda-layer with MIT License | 5 votes |
def _get_request(self, url_path, retry_func): """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 taht was provided in the initializer. :type retry_func: callable :param retry_func: A function that takes the response as an argument and determines if it needs to retry. By default empty and non 200 OK responses are retried. """ if self._disabled: logger.debug("Access to EC2 metadata has been disabled.") raise self._RETRIES_EXCEEDED_ERROR_CLS() if retry_func is None: retry_func = self._default_retry url = self._base_url + url_path headers = {} if self._user_agent is not None: headers['User-Agent'] = self._user_agent for i in range(self._num_attempts): try: request = botocore.awsrequest.AWSRequest( method='GET', url=url, headers=headers) response = self._session.send(request.prepare()) if not retry_func(response): return response except RETRYABLE_HTTP_ERRORS as e: logger.debug( "Caught retryable HTTP exception while making metadata " "service request to %s: %s", url, e, exc_info=True) raise self._RETRIES_EXCEEDED_ERROR_CLS()
Example #15
Source File: s3.py From learn_python3_spider with MIT License | 5 votes |
def download_request(self, request, spider): p = urlparse_cached(request) scheme = 'https' if request.meta.get('is_secure') else 'http' bucket = p.hostname path = p.path + '?' + p.query if p.query else p.path url = '%s://%s.s3.amazonaws.com%s' % (scheme, bucket, path) if self.anon: request = request.replace(url=url) elif self._signer is not None: import botocore.awsrequest awsrequest = botocore.awsrequest.AWSRequest( method=request.method, url='%s://s3.amazonaws.com/%s%s' % (scheme, bucket, path), headers=request.headers.to_unicode_dict(), data=request.body) self._signer.add_auth(awsrequest) request = request.replace( url=url, headers=awsrequest.headers.items()) else: signed_headers = self.conn.make_request( method=request.method, bucket=bucket, key=unquote(p.path), query_args=unquote(p.query), headers=request.headers, data=request.body) request = request.replace(url=url, headers=signed_headers) return self._download_http(request, spider)
Example #16
Source File: s3.py From learn_python3_spider with MIT License | 5 votes |
def download_request(self, request, spider): p = urlparse_cached(request) scheme = 'https' if request.meta.get('is_secure') else 'http' bucket = p.hostname path = p.path + '?' + p.query if p.query else p.path url = '%s://%s.s3.amazonaws.com%s' % (scheme, bucket, path) if self.anon: request = request.replace(url=url) elif self._signer is not None: import botocore.awsrequest awsrequest = botocore.awsrequest.AWSRequest( method=request.method, url='%s://s3.amazonaws.com/%s%s' % (scheme, bucket, path), headers=request.headers.to_unicode_dict(), data=request.body) self._signer.add_auth(awsrequest) request = request.replace( url=url, headers=awsrequest.headers.items()) else: signed_headers = self.conn.make_request( method=request.method, bucket=bucket, key=unquote(p.path), query_args=unquote(p.query), headers=request.headers, data=request.body) request = request.replace(url=url, headers=signed_headers) return self._download_http(request, spider)
Example #17
Source File: signers.py From deepWordBug with Apache License 2.0 | 5 votes |
def generate_presigned_url(self, request_dict, operation_name, expires_in=3600, region_name=None, signing_name=None): """Generates a presigned url :type request_dict: dict :param request_dict: The prepared request dictionary returned by ``botocore.awsrequest.prepare_request_dict()`` :type operation_name: str :param operation_name: The operation being signed. :type expires_in: int :param expires_in: The number of seconds the presigned url is valid for. By default it expires in an hour (3600 seconds) :type region_name: string :param region_name: The region name to sign the presigned url. :type signing_name: str :param signing_name: The name to use for the service when signing. :returns: The presigned url """ request = create_request_object(request_dict) self.sign(operation_name, request, region_name, 'presign-url', expires_in, signing_name) request.prepare() return request.url
Example #18
Source File: utils.py From deepWordBug with Apache License 2.0 | 5 votes |
def _get_request(self, url_path, retry_func): """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 taht was provided in the initializer. :type retry_func: callable :param retry_func: A function that takes the response as an argument and determines if it needs to retry. By default empty and non 200 OK responses are retried. """ if self._disabled: logger.debug("Access to EC2 metadata has been disabled.") raise self._RETRIES_EXCEEDED_ERROR_CLS() if retry_func is None: retry_func = self._default_retry url = self._base_url + url_path headers = {} if self._user_agent is not None: headers['User-Agent'] = self._user_agent for i in range(self._num_attempts): try: request = botocore.awsrequest.AWSRequest( method='GET', url=url, headers=headers) response = self._session.send(request.prepare()) if not retry_func(response): return response except RETRYABLE_HTTP_ERRORS as e: logger.debug( "Caught retryable HTTP exception while making metadata " "service request to %s: %s", url, e, exc_info=True) raise self._RETRIES_EXCEEDED_ERROR_CLS()
Example #19
Source File: signers.py From faces with GNU General Public License v2.0 | 5 votes |
def generate_presigned_url(self, request_dict, operation_name, expires_in=3600, region_name=None): """Generates a presigned url :type request_dict: dict :param request_dict: The prepared request dictionary returned by ``botocore.awsrequest.prepare_request_dict()`` :type operation_name: str :param operation_name: The operation being signed. :type expires_in: int :param expires_in: The number of seconds the presigned url is valid for. By default it expires in an hour (3600 seconds) :type region_name: string :param region_name: The region name to sign the presigned url. :returns: The presigned url """ request = create_request_object(request_dict) self.sign(operation_name, request, region_name, 'presign-url', expires_in) request.prepare() return request.url