Currently all the boto3 documentation show date element as datetime() object.e.g.
{
'Contents': [
{
'Key': 'string',
'LastModified': datetime(2015, 1, 1),
'ETag': 'string',
.....
}
There is little documentation mentioned how to deal with the datetime object when using jmespath query.
What specifically are you trying to use with jmespath and timestamps? Could you provide a sample JMESPath expression you are trying to apply?
Some mistake can be solved by common-sense or good documentation.
As shown here.
This user use a formatted datetime string
get specific date using jmes
This user wrongly use single quote , which the datetime() object should be encase in backquote.
search can't compare datetime
@commutecat , i ma using the backquotes . still not working .
filtered_iterator = page_iterator.search("Contents[?LastModified>=`datetime.datetime(2017, 7, 5, 13, 41, 27, tzinfo=tzutc())`].Key")
What will be the solution for it .please let me know . thanks
any news?
I'm trying to get this example to work:
https://stackoverflow.com/questions/41584793/aws-boto3-page-iterator-search-cant-compare-datetime-datetime-to-str/41589013#41589013
but I'm not getting any results.
import boto3
s3 = boto3.client("s3")
s3_paginator = s3.get_paginator('list_objects')
s3_iterator = s3_paginator.paginate(Bucket='mytestbucket')
filtered_iterator = s3_iterator.search(
"Contents[?LastModified >= `datetime.datetime(2016, 12, 27, 8, 5, 37, tzinfo=tzutc())`].Key"
)
for key_data in filtered_iterator:
print(key_data)
I'm trying to get this example to work:
https://stackoverflow.com/questions/41584793/aws-boto3-page-iterator-search-cant-compare-datetime-datetime-to-str/41589013#41589013
but I'm not getting any results.import boto3 s3 = boto3.client("s3") s3_paginator = s3.get_paginator('list_objects') s3_iterator = s3_paginator.paginate(Bucket='mytestbucket') filtered_iterator = s3_iterator.search( "Contents[?LastModified >= `datetime.datetime(2016, 12, 27, 8, 5, 37, tzinfo=tzutc())`].Key" ) for key_data in filtered_iterator: print(key_data)
@tomisaacson I have also tried to replicate this example using my own data and am also unable to return any results (nor any errors).
I contacted AWS support about this and after some wrong starts they gave me this which works:
import boto3
s3 = boto3.client("s3")
s3_paginator = s3.get_paginator('list_objects_v2')
s3_iterator = s3_paginator.paginate(Bucket='mytestbucket')
filtered_iterator = s3_iterator.search(
"Contents[?to_string(LastModified)>='\"2016-12-27 08:05:37+00:00\"'].Key"
)
for key_data in filtered_iterator:
print(key_data)
However because you're providing a string you have to be careful with the format. I haven't tested this exhaustively so there may be combinations that don't work.
I contacted AWS support about this and after some wrong starts they gave me this which works:
import boto3 s3 = boto3.client("s3") s3_paginator = s3.get_paginator('list_objects_v2') s3_iterator = s3_paginator.paginate(Bucket='mytestbucket') filtered_iterator = s3_iterator.search( "Contents[?to_string(LastModified)>='\"2016-12-27 08:05:37+00:00\"'].Key" ) for key_data in filtered_iterator: print(key_data)However because you're providing a string you have to be careful with the format. I haven't tested this exhaustively so there may be combinations that don't work.
@tomisaacson Awesome, thank you! 馃憦 I just tested this out and can confirm that it works! I should note that I compared the results I got using this approach to a more brute-force approach using some CLI arguments and they were the same.
Marking this as documentation. We can add this example here
Most helpful comment
I contacted AWS support about this and after some wrong starts they gave me this which works:
However because you're providing a string you have to be careful with the format. I haven't tested this exhaustively so there may be combinations that don't work.