Search code examples
amazon-s3aws-cli

How to upload files matching a pattern with aws cli to s3


Team, I need to upload all files matching this pattern console.X.log to s3, where X=0...any

I tried below and getting error.

aws s3 cp /var/log/console.* s3://test/dom0/

Unknown options: /var/log/console.70.log,s3://0722-maglev-avdc-provisions/dom0/

Solution

  • AWS s3 cli doesn't support regex, but there is an exclude and include for s3. So you should be able to use:

    aws s3 cp /var/log/ s3://test/dom0/ --recursive --exclude "*" --include "console.*"
    

    Note the order of the exclude and include, if you switch them around then nothing will be uploaded. You can include more patterns by adding more includes.