This is a short post to explain how to run AWS CLI commands from a crontab.
First you’ll need to install and set up the AWS CLI. More information here: http://docs.aws.amazon.com/cli/
Once you’ve set up AWS CLI, you’ll notice that there is a “.aws” folder created in the HOME folder for the user you’re logged in as. If it’s root, it would be “/root/.aws”.
The problem with running AWS CLI commands from crontab is that crontab sets HOME to “/”, so the “aws” command will not find “~/.aws”.
In order to get around this, you simply need to set HOME=”/root/” (or whatever the HOME is for the user AWS CLI was set up under). This can be done in the shell script that is being called by crontab, or if the aws command is directly in crontab, the crontab command could be something like the following:
HOME=”/root” && aws cli
And that’s it!
One thought on “Running AWS CLI commands from crontab”