Reputation: 1902
i.e. will this code cause it to appear as 2 GET requests in my bill, or only 1?
key = bucket.get_key('some_invalid_key')
key = bucket.get_key('some_valid_key')
string = key.get_contents_to_string()
Upvotes: 0
Views: 357
Reputation: 44092
By default, get_key
validate existence of the key on the bucket by HEAD request (which is rather small one, but the request counts to number of requests you do).
If you do not want to make this validation, set validate=False
and boto will not make the request.
Docstring for get_key
:
Type: instancemethod
String form: <bound method Bucket.get_key of <Bucket: tmpdistributionplatform>>
File: /home/javl/Envs/so/local/lib/python2.7/site-packages/boto/s3/bucket.py
Definition: bucket.get_key(self, key_name, headers=None, version_id=None, response_headers=None, validate=True)
Docstring:
Check to see if a particular key exists within the bucket. This
method uses a HEAD request to check for the existance of the key.
Returns: An instance of a Key object or None
:param key_name: The name of the key to retrieve
:type key_name: string
:param headers: The headers to send when retrieving the key
:type headers: dict
:param version_id:
:type version_id: string
:param response_headers: A dictionary containing HTTP
headers/values that will override any headers associated
with the stored object in the response. See
http://goo.gl/EWOPb for details.
:type response_headers: dict
:param validate: Verifies whether the key exists. If ``False``, this
will not hit the service, constructing an in-memory object.
Default is ``True``.
:type validate: bool
:rtype: :class:`boto.s3.key.Key`
:returns: A Key object from this bucket.
get_key
generates one HEAD requests and you are charged for it.validate=False
Upvotes: 2