'do aws s3api query output varies to shell variable & value?
case:
I need to fetch AWS s3 objects which matches with prefix and lastModified value is greater than the object which I accessed lastly.
Therefore I am using lastModified attribute of the object in the script.
AWS CLI version :
aws-cli/1.19.38 Python/3.6.8 Linux/4.18.0-240.22.1.el8_3.x86_64 botocore/1.20.38.
Hurdle :
I can't able to update the AWS CLI hence I don't have the chance to use start's_with option in AWS s3api which is in aws CLI version - 2.x.x.
Problem :
The result is not the same while using the exact value & shell variable.
aws s3api list-objects --bucket "bucket" --query 'Contents[?Key!=`null`]|[?starts_with (Key,`a/b/c/file_`)==`true`]|[?LastModified > `2021-08-11T15:25:50.000Z`].[Key,LastModified]' --output text | sort -k2 | head -1
output : (should print new line)
because in s3 path s3://bucket/a/b/c/ there is only one file which is last modified exactly at 2021-08-11T15:25:50.000Z.As there are no objects modified recently than 2021-08-11T15:25:50.000Z. Hence output should be new line.
the one object with matching prefix is
key : s3://bucket/a/b/c/file_1.txt
Last modified : 2021-08-11T15:25:50.000Z
but when I am storing the LastModified value of the object the result is different but should be same.
#!/bin/bash
alias grep='grep --color=never'
lastFileTime=2021-08-11T15:25:50.000Z
aws s3api list-objects --bucket "bucket" --query 'Contents[?Key!=`null`]|[?starts_with (Key,`a/b/c/file_`)==`true`]|[?LastModified > `$lastFileTime`].[Key,LastModified]' --output text | sort -k2 | head -1
echo $lastFile
output : a/b/c/file_1.txt 2021-08-11T15:25:50.000Z
My expectation:
It should output nothing ( just a new line ) as a/b/c/file_1.txt is last modified value is same as 2021-08-11T15:25:50.000Z.
Note: with & without alias grep='grep --color=never' the output is same.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
