I want to use the AWS Command Line Interface (AWS CLI) to create an automated snapshot in Amazon Lightsail.
Resolution
Note: If you receive errors when you run AWS CLI commands, then see Troubleshoot AWS CLI errors. Also, make sure that you're using the most recent AWS CLI version.
To use the AWS CLI to create an automated snapshot in Lightsail, complete the following steps:
-
Create a snapshot script:
#!/bin/bash
# Create a snapshot
aws lightsail create-instance-snapshot \
—instance-name example-instance-name \
—createsnapshot.sh "$INSTANCE_NAME$(date +%Y%m%d%H%M%S)" —example-default-region
Note: In the preceding command, replace the example- values with your instance name and AWS Region.
-
Add permissions to run the script:
$ chmod +x createsnapshot.sh
-
Schedule the script:
$ crontab -e
0 * * * * /path/to/createsnapshot.sh
-
Make sure that the script is active:
./createsnapshot.sh
Note: To verify that snapshots are active, open the Lightsail dashboard, and then choose the Snapshots tab.