39

How to download simple storage service(s3) bucket files directly on user's local machine?

Axxy
  • 431
  • 1
  • 4
  • 3
  • Are you looking for a solution implemented in your own program code or an off the shelf application to do this? I assume the later because you have not tagged your question with a programming language tag. – camelCase Aug 16 '17 at 10:42
  • I am going to use that command in bash script. Which i will configured as cron job so it will automatically download logs on my machine – Axxy Aug 16 '17 at 10:49
  • Welcome to StackOverflow! Please note that asking general questions like this is discouraged. You are expected to have full researched your issue and attempted to solve your issue yourself. If you still have specific issues, you can post a specific question including details of what you have tried so far. Please read [How much research effort is expected of Stack Overflow users?](https://meta.stackoverflow.com/questions/261592/how-much-research-effort-is-expected-of-stack-overflow-users) and [How do I ask a good question](https://stackoverflow.com/help/how-to-ask) – FluffyKitten Aug 17 '17 at 00:55
  • Possible duplicate of [Getting 403 forbidden from s3 when attempting to download a file](https://stackoverflow.com/questions/37192084/getting-403-forbidden-from-s3-when-attempting-to-download-a-file) – Dawny33 Aug 17 '17 at 01:28

1 Answers1

75

you can check the aws s3 cli so to copy a file from s3.

The following cp command copies a single object to a specified file locally:

aws s3 cp s3://mybucket/test.txt test2.txt

Make sure to use quotes " in case you have spaces in your key

aws s3 cp "s3://mybucket/test with space.txt" "./test with space.txt"
Frederic Henri
  • 51,761
  • 10
  • 113
  • 139
  • thanks Frédéric Henri but this will copy file on virtualmachine on aws, I wants to download that file from s3 on my machine from where i am accesssing aws – Axxy Aug 17 '17 at 11:11
  • 1
    The command will copy a file to an s3 bucket. The question asked is to do the reverse. – GhostCode Jul 18 '18 at 09:14
  • 2
    @GhostCode check on a bucket, this copies a S3 object to a file locally, you can even check doc I refer from the link and search for "Copying an S3 object to a local file" – Frederic Henri Jul 18 '18 at 09:17
  • Yes, I saw the command carefully now. I thought your answer was : aws s3 cp test.txt s3://mybucket/test2.txt Sorry for being hasty – GhostCode Jul 18 '18 at 12:54
  • you can do the `cp` command as long as your user and bucket have `PutItem` permissions – thedanotto Jul 11 '19 at 15:55
  • I used this command for downloading a file from localstack and it worked fine. – mehdi mohammadi Oct 31 '19 at 12:33