Getty Images

How to create and manage Amazon EBS snapshots via AWS CLI

EBS snapshots are an essential part of any data backup and recovery strategy in EC2-based deployments. Become familiar with how to create and manage them with the AWS CLI.

While Amazon EC2 provides the ability to launch a variety of virtual servers, there is also the need to deploy data storage for each virtual server.

Amazon Elastic Block Storage (EBS) volumes are virtual storage devices in the cloud that get attached to EC2 instances and provide internal storage for essential areas in any application, such as OS files, source code, libraries and configuration files. Given the critical nature of this data, enterprises need a reliable way to create and manage backups of EBS volumes.

Learn how EBS snapshots can help with disaster recovery, as well as how to create and manage them through the AWS Command Line Interface.

EBS snapshot features and pricing

EBS snapshots are a point-in-time backup of an EBS volume. With EBS snapshots, users can control how data in an EBS volume is backed up, stored, managed and recovered. Developers can trigger the creation of an EBS snapshot using the AWS CLI or SDK, or through the EC2 console. Some core features of EBS snapshots include the following:

  • Direct read access. Users can read snapshots' data and pinpoint differences between two EBS snapshots without needing to create EBS volumes and EC2 instances via the EBS direct API. This feature enables users to better track incremental changes on EBS volumes, which provides increased granularity and faster backup times.
  • Create snapshots from any block storage. In addition, with the direct API, users can create snapshots directly from any block storage data, no matter where it is stored, and then recover into EBS volumes.
  • Copy snapshots across AWS Regions. With EBS, users can automatically copy snapshots across other Regions. This helps migration and disaster recovery efforts.
  • Share snapshots. Users have the choice to share data within their organization as well as publicly to all AWS users.

EBS snapshots are a better fit for the creation of regular backups of EBS volumes. For a solid disaster recovery strategy, users should create snapshots routinely and copy them to other AWS Regions and AWS accounts. EBS snapshots can also be transitioned to cold storage, which is an option to consider to significantly reduce storage costs.

EBS snapshot pricing

EBS snapshots cost $0.05 per GB, per month, for the standard tier. The cost to create and keep an Amazon Machine Image depends solely on the EBS snapshots that are essential to that AMI. A 100 GB EBS snapshot or AMI would cost $5 per month. Subsequent snapshots of a particular EBS volume are charged based only on the blocks that have changed since the previous snapshot.

To reduce costs, users can transition snapshots to the Archive tier, which costs $0.0125 per GB, per month. In the Archive tier, the same 100 GB snapshot would then cost $1.25 per month. Data retrieval from the Archive tier is billed at $0.03 per GB. Be aware that there's a minimum 90-day retention period.

EBS snapshots vs. Amazon Machine Images

When users create an EBS snapshot, they can use it to configure an EC2 AMI. An AMI supplies a storage image, which a new EC2 instance requires at launch.

An active EC2 instance can also create an AMI. The EC2 service first creates one or more EBS snapshots, which are then automatically used for the new AMI. The number of snapshots produced depends on how many EBS volumes are attached to the source EC2 instance. The EC2 service creates one EBS snapshot per attached EBS volume.

EC2 instances can be launched only from an existing AMI and not directly from an EBS snapshot. If an EBS snapshot is used as the source data to launch new EC2 instances, it must first be used to create an AMI. Then, the AMI will be the input when launching new EC2 instances.

Since AMIs are a way to manage the starting point of new EC2 instances, there is no need to create AMIs as frequently as EBS snapshots. Also, AWS recommends maintaining cross-region and cross-account copies of AMIs for disaster recovery purposes, as well as enabling encryption when creating EBS volumes and snapshots.

Create and manage EBS snapshots

It's convenient to launch and manage EBS snapshots through the AWS CLI. The create-snapshot command provides a way to quickly start snapshot creation. A basic example of this CLI command looks like the following example.

aws ec2 create-snapshot --volume-id <ebs-volume-id> –description <ebs-snapshot-description>

This command returns, among other data, the SnapshotId value of the recently created snapshot, as well as its creation state, the value of which will be Pending right after calling this command.

The describe-snapshots command in the following example offers a way to list and filter snapshots in your account.

aws ec2 describe-snapshots --snapshot-ids <space-separated-list-of-snapshot-ids>

This command also offers a useful filters parameter to narrow the list of returned EBS snapshots.

As with any AWS CLI command, it's important to define region and profile parameters, or set them through the AWS_DEFAULT_REGION and AWS_PROFILE environment variables, respectively. The examples provided show basic scenarios. Keep in mind that the CLI offers additional parameters that deliver more options.

Dig Deeper on Cloud app development and management

Data Center
ITOperations
SearchAWS
SearchVMware
Close