Kank Moiz
Kank Moiz

Reputation: 11

How to download s3 bucket images from folder to local system

How can I use regular expressions to selectively download images from an S3 bucket to my local machine? Specifically, I want to target files that start with 20231201. Currently, I am using the S3 CLI and my commands are downloading all historical images from previous months and years. My goal is to download only the images that have filenames following this pattern:

https://optimus-ai.s3.ca-central-1.amazonaws.com/clients/chatbot/prod/20231203-6de2d5dd-7303-4841-b35c-c69e1b35d9f0.jpg
https://optimus-ai.s3.ca-central-1.amazonaws.com/clients/chatbot/prod/20231201-030e87e7-3a61-4748-bfa4-fbd10a2a2ecf.jpg
https://optimus-ai.s3.ca-central-1.amazonaws.com/clients/chatbot/prod/20231208-2220bc6b-fa21-4df9-b4d4-a47e988cab0d.jpg
https://optimus-ai.s3.ca-central-1.amazonaws.com/clients/chatbot/prod/20231203-a4939bde-4a14-414e-9d1a-0a89912a4f63.jpg
https://optimus-ai.s3.ca-central-1.amazonaws.com/clients/chatbot/prod/20231205-c2ca109d-8f7f-43ba-bd47-d6782bae0d5e.jpg
https://optimus-ai.s3.ca-central-1.amazonaws.com/clients/chatbot/prod/20231205-cf76fe0a-733c-4317-a0a6-a0ecd0860794.jpg

The command I'm currently using downloads all files from previous years:

aws s3 sync s3://optimus-ai.s3.ca-central-1.amazonaws.com/clients/chatbot/prod/ ./local-directory

When I attempt to download only files from 202312 using the regex pattern in the include parameter, it doesn't download anything:

aws s3 sync s3://optimus-ai.s3.ca-central-1.amazonaws.com/clients/chatbot/prod/ ./local-directory --exclude "*" --include "20231201*"

What should be the correct command to download all files starting with 202312?

Upvotes: 0

Views: 60

Answers (1)

Gunesh Shanbhag
Gunesh Shanbhag

Reputation: 640

You can use below command, Update the month and year based on your preference.

aws s3 sync s3://optimus-ai.s3.ca-central-1.amazonaws.com/clients/chatbot/prod/ ./local-directory --exclude "*" --include "202312*"

Upvotes: 1

Related Questions