Back Up EC2 Instances And Send Status To Zabbix Via AWS Powershell Tools

According to Amazon EC2 best practices you need regularly back up your volumes using snapshots. That’s most probably a must and at the same time the easiest way to do. One reason more is that it costs not many funds because technically only the blocks on the device that have changed after your last snapshot are saved in the new snapshot.

I will do it on Windows via PowerShell and perform monitoring through Zabbix 3.4.

Let’s start with creating of AWS user for it.

First, go to AWS Console → IAM → Users using Administrator account and create the name for a new user according to convention in your organization. Check in only Programmatic access as on the screnshot below because we don’t need web access for this account.

Step 1

On the next step, go to Attach existing policies directly and grant AmazonEC2FullAccess for the new user.

Step 2

On the last step, copy just created Access key ID and Secret access key to a password manager tool that you have used.

Step 4

Of course, implies that we are going to keep script on one of the servers of our organization. So, after AWS Tools for Windows PowerShell has been installed on it, go to Powershell console and put just created credentials to the store.

To check that keys were added, execute the following.

And you’ll see just created NetSDKCredentialsFile profile in the output.

Let’s create PowerShell script file.

Simply speaking, we are going through each volume that has ‘in-use’ status and back up it by doing snapshots. If something went wrong (or good), we send appropriate status code to Zabbix server.

Zabbix → All templates → AWS EC2 Snapshots → Triggers

Script and Zabbix template you can download here. I scheduled task through Task Scheduler on Windows and execute it every week. You can do it more often, but I don’t recommend it because primarily snapshots are not designed for such a frequent use.

Like what you read? Give Max Muravyev a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.