2 Antworten
- Neueste
- Die meisten Stimmen
- Die meisten Kommentare
0
If you want to test if object doesn't have any tags you can test if TagSet[0] is null.
% aws s3api get-object-tagging --bucket BUCKET --key OBJECT
{
"TagSet": []
}
% aws s3api get-object-tagging --bucket BUCKET --key OBJECT --query 'TagSet[0]==`null`'
true
As your original script was listing all the tag, but now you'd only want to list object name when there is no tags, you can replace inner for -loop with simple if -cmd than will print object name (%%a) when above cmd return true. Not being Windows professional I will leave the syntax of script for you as an exercise ;-)
0
Please see the more clear syntax
for /f "tokens=*" %%a in ('aws s3api list-objects-v2 --bucket <bucket> --prefix <prefix> --no-cli-auto-prompt --query Contents[*].[Key] --output text') do (
for /f "tokens=*" %%b in ('aws s3api get-object-tagging --bucket <bucket> --key %%a --no-cli-auto-prompt --query "TagSet[0]==null" --output text') do (
if %%b==True @echo %%a >> <file>
)
)
beantwortet vor 10 Monaten
Relevanter Inhalt
- AWS OFFICIALAktualisiert vor 3 Jahren
- AWS OFFICIALAktualisiert vor 2 Jahren
- AWS OFFICIALAktualisiert vor einem Jahr
Hello,
Thank you for your useful hint.
But, in Windows, the only way I know to run AWS CLI command inside other CMD command (including if -cmd) is that FOR /F (there is no other way to make command substitution, to use the output of AWS CLI environment inside WIN CMD environment). So, the solution that I found is presented below.
for /f "tokens=" %%a in ('aws s3api list-objects-v2 --bucket <bucket> --prefix <prefix> --no-cli-auto-prompt --query Contents[].[Key] --output text') do ( for /f "tokens=*" %%b in ('aws s3api get-object-tagging --bucket <bucket> --key %%a --no-cli-auto-prompt --query "TagSet[0]==null" --output text') do ( if %%b==True @echo %%a >> <file> ) ) Now that I have the command, I could see that the execution time is very long, as it includes one call for each in hundreds keys. Does it exist any way to shorten the execution time ?
Thank you, Mihai ADAM