0

Im writing a Bash script to download some objects from S3. The user account that runs this script does not have a home directory available. meaning - the folder refered to by $HOME does not exist.

I have used environment variables to redirect the credentials and config files. This is working, the files are created in the new location

export AWS_CONFIG_FILE=/newfolder/.aws/config
export AWS_SHARED_CREDENTIALS_FILE=/newfolder/.aws/credentials

I get a Permission denied error when running this command.

/usr/local/bin/aws --profile thisprofile s3 ls $BUCKET$FOLDER --recursive

It is trying to write to a cache file in the users home directory, but cannot because the $HOME directory doesn't exist.

$HOME/.aws/cli/cache/a5e04d49e9fc210124ee0431e237dccc5ed84794.json

I have tried to export HOME to a valid folder. This works but I don't think this is the nicest way to solve this. This script works properly with a user account that has a home directory.

Assuming I cannot just fix the missing home directory, Is there a way to redirect this cache file, or everything in .aws, to a new location similar to what I did with the credentials?

Edit: In addition to Anon Cowards answer showing where it explicitly calls the HOME variable, there is an open feature-request to disable caching

0

The workaround you've found is the only real solution. Basically, if there's any scenario where boto3 needs to use assume role, the following code is eventually called:

    CACHE_DIR = os.path.expanduser(os.path.join('~', '.aws', 'boto', 'cache'))

As you can see, there's no hope of customization, since the tilde expansion that's done by Python's os.path.expanduser() explicitly uses $HOME. Technically, the code that uses CACHE_DIR in JSONFileCache has an escape hatch to allow a different directory to be specified, but that option isn't used by any of the calling functions.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.