3

I can set Cache-Control metadata on every item in an S3 bucket using the following command (from this answer):

aws s3 cp s3://mybucket s3://mybucket --recursive --metadata-directive REPLACE \
--cache-control max-age=86400

Is there a way to read the Cache-Control metadata for every item in a bucket?

Community
  • 1
  • 1
user200783
  • 13,722
  • 12
  • 69
  • 135

1 Answers1

2

This bash one-liner should work (but it is very slow since it sends separate request for each object):

IFS=$'\n'; for object in `aws s3 ls s3://my-bucket-name --recursive | tr -s ' ' | cut -d' ' -f4-`; do echo $object `aws s3api head-object --bucket my-bucket-name --key $object --query CacheControl` ; done
Dusan Bajic
  • 10,249
  • 3
  • 33
  • 43
  • Thanks for this - as you say, it works but is quite slow. Also, for use with Cygwin, I had to set `IFS=$'\r\n'`. – user200783 May 16 '16 at 23:22
  • 2
    I also swapped the "columns" of the output to improve alignment. The command I ended up using was `IFS=$'\r\n'; for object in \`aws s3 ls s3://my-bucket-name --recursive | tr -s ' ' | cut -d' ' -f4-\`; do echo \`aws s3api head-object --bucket my-bucket-name --key $object --query CacheControl\` $object ; done`. – user200783 May 17 '16 at 12:51