1

Using CLI (not s3cmd) to manage Amazon S3, how can I select all objects with extension .pdf and apply the content type application/pdf?

This is what I came up with so far:

aws s3 sync s3://${BUCKET_NAME} s3://${BUCKET_NAME}
--dryrun
--exclude '*'
--include '*.pdf'
--no-guess-mime-type
--content-type application/pdf

Using the --debug parameter I found out about this error:

An error occurred (InvalidRequest) when calling the CopyObject operation:
This copy request is illegal because it is trying to copy an object to itself
without changing the object's metadata, storage class,
website redirect location or encryption attributes.
Anthony Neace
  • 25,013
  • 7
  • 114
  • 129
bart
  • 14,958
  • 21
  • 75
  • 105

1 Answers1

2

Try changing metadata directly:

aws s3 sync s3://${BUCKET_NAME} s3://${BUCKET_NAME}
--dryrun
--exclude '*'
--include '*.pdf'
--no-guess-mime-type
--metadata Content-Type=application/pdf
Sergey Kovalev
  • 9,110
  • 2
  • 28
  • 32