Search code examples
bashubuntuamazon-s3file-permissions

Download zip file from s3 using s3cmd issue


I have two issues I need help with on bash, linux and s3cmd.

First, I'm running into linux permission issue. I am trying to download zip files from a s3 bucket using s3cmd with following command in a bash script.sh:

/usr/bin/s3cmd get s3://<bucketname>/<folder>/zipfilename.tar.gz

I am seeing following error: permission denied.

If I try to run this command manually from command line on a linux machine, it works and downloads the file:

sudo /usr/bin/s3cmd get s3://<bucketname>/<folder>/zipfilename.tar.gz

I really don't want to use sudo in front of the command in the script. How do I get this command to work? Do I need to give chown permission to the script.sh which is actually sitting in a path i.e /foldername/script.sh or how do I get this get command to work?

Two: Once I get this command to work, How do I get it to download from s3 to the linux home dir: ~/ ? Do I have to specifically issue a command in the bash script: cd ~/ before the above download command?

I really appreciate any help and guidance.


Solution

  • First, determine what's failing and the reason, otherwise you won't find the answer.

    You can specify the destination in order to avoid permission problems when the script is invoked using a directory that's not writeable by that process

    /usr/bin/s3cmd get s3:////zipfilename.tar.gz /path/to/writeable/destination/zipfilename.tar.gz