I have a shell script which is supposed to download some files from S3 and mount an ebs drive. However, I always end up with "Unable to locate credentials".
I have specified my credentials with the aws configure
command and the commands work outside the shell script. Could somebody, please, tell me (preferably in detail) how to make it work?
This is my script
#!/bin/bash AWS_CONFIG_FILE="~/.aws/config" echo $1 sudo mkfs -t ext4 $1 sudo mkdir /s3-backup-test sudo chmod -R ugo+rw /s3-backup-test sudo mount $1 /s3-backup-test sudo aws s3 sync s3://backup-test-s3 /s3-backup/test du -h /s3-backup-test ipt (short version):
Thanks for any help!
While you might have your credentials and config file properly located in ~/. aws, it might not be getting picked up by your user account. To set the credentials, run this command: aws configure and then enter the credentials that are specified in your ~/. aws/credentials file.
The shared AWS config and credentials files are plaintext files that reside by default in a folder named . aws that is placed in the " home " folder on your computer. On Linux and macOS, this is typically shown as ~/. aws .
To resolve this issue, make sure that your AWS credentials are correctly configured in the AWS CLI. Note: If you still receive an error when running an AWS CLI command, make sure that you're using the most recent AWS CLI version.
sudo
will change the $HOME
directory (and therefore ~
) to /root, and remove most bash variables like AWS_CONFIG_FILE from the environment. Make sure you do everything with aws as root or as your user, dont mix.
Make sure you did sudo aws configure
for example. And try
sudo bash -c 'AWS_CONFIG_FILE=/root/.aws/config aws s3 sync s3://backup-test-s3 /s3-backup/test'
You might prefer to remove all the sudo from inside the script, and just sudo the script itself.
While you might have your credentials and config file properly located in ~/.aws, it might not be getting picked up by your user account.
Run this command to see if your credentials have been set:aws configure list
To set the credentials, run this command: aws configure
and then enter the credentials that are specified in your ~/.aws/credentials file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With