{"id":1053,"date":"2021-06-15T02:10:00","date_gmt":"2021-06-15T02:10:00","guid":{"rendered":"https:\/\/blog.ngocha.biz\/?p=1053"},"modified":"2021-06-15T02:10:00","modified_gmt":"2021-06-15T02:10:00","slug":"automate-ebs-snapshot-creation-deletion","status":"publish","type":"post","link":"https:\/\/blog.ngocha.biz\/?p=1053","title":{"rendered":"How to Automate EBS Snapshot Creation  [ AWS Ec2 Backup ]"},"content":{"rendered":"<p>It is essential to have AWS ec2 backup using EBS volumes for data recovery and protection. AWS EBS snapshots play an important role in the backup of your ec2 instance data (root volumes &amp; additional volumes).<\/p>\n<p>Even though AWS EBS snapshots are considered &#8220;poor man&#8217;s backup,&#8221; it gives you a point in time backup and faster restore options to meet your <a href=\"https:\/\/www.enterprisestorageforum.com\/storage-management\/rpo-and-rto-understanding-the-differences.html?ref=devopscube.com\" rel=\"noreferrer noopener\">RPO<\/a> objective.<\/p>\n<p>Towards the end of the article, I have added some key EBS snapshot features and some best practices to manage snapshots.<\/p>\n<h2 id=\"automation-aws-ebs-snapshot-for-ec2-instances\">Automation AWS EBS Snapshot For EC2 Instances<\/h2>\n<p>AWS EBS Snapshots are the cheapest and easiest way to enable backups for your EC2 instances or EBS volumes.<\/p>\n<p>There are three ways to take automated snapshots.<\/p>\n<ol>\n<li>AWS EBS Life Cycle manager<\/li>\n<li>AWS Cloudwatch Events<\/li>\n<li>AWS Lambda Functions.<\/li>\n<\/ol>\n<p>This tutorial will guide you through EBS snapshot automation and its life cycle management using all three approaches.<\/p>\n<h2 id=\"automation-ebs-snapshot-with-life-cycle-manager\">Automation EBS Snapshot \u00a0with Life Cycle manager<\/h2>\n<p>AWS EC2 lifecycle manage is a native AWS functionality to manage the lifecycle of EBS volumes and snapshots.<\/p>\n<p>It is the quickest and easiest way to automate EBS snapshots. It works on the concept of AWS tags. Based on the instance or volume tags, you can group EBS volumes and perform snapshot operations in bulk or for a single instance.<\/p>\n<p>Follow the steps given below to setup a EBS snapshot lifecycle policy.<\/p>\n<h3 id=\"step-1-tag-your-ec2-instance-and-volumes\"><strong>Step 1: Tag your ec2 instance and \u00a0volumes<\/strong><\/h3>\n<p>EC2 EBS snapshots with the life cycle manager work with the instance &amp; volume tags. It requires instances and volumes to be tagged to identify the snapshot candidate.<\/p>\n<p>You can use the following tag in the instances and volumes that needs automated snapshots.<\/p>\n<pre><code>Key = Backup \nValue = True<\/code><\/pre>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/ec2-ebs-tagging-min-1.png\" class=\"kg-image\" alt=\"AWS tags for ebs snapshot automation\" loading=\"lazy\" width=\"598\" height=\"218\"><\/figure>\n<h3 id=\"step-2-go-to-the-ebs-life-cycle-manager-to-create-a-snapshot-lifecycle-policy-\">Step 2: Go to the EBS life cycle manager to create a snapshot lifecycle policy.<\/h3>\n<p>Head over to the EC2 dashboard and select &#8220;<code>Lifecycle Manager<\/code>&#8221; option under <code>ELASTIC BLOCK STORE<\/code> category as shown below.<\/p>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/life-cycle-manager-dashboard-min-1.png\" class=\"kg-image\" alt=\"EBS life cycle manager to create ebs snapshot policy.\" loading=\"lazy\" width=\"619\" height=\"413\" srcset=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w600\/2025\/03\/life-cycle-manager-dashboard-min-1.png 600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/life-cycle-manager-dashboard-min-1.png 619w\"><\/figure>\n<p>You will be taken to the life cycle manager dashboard. Click \u00a0&#8220;<code>Create Snapshot Lifecycle Policy<\/code>&#8221; button.<\/p>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/create-lifecyle-policy-min-1.png\" class=\"kg-image\" alt=\"life cycle policy creation for ebs snapshot automation.\" loading=\"lazy\"><\/figure>\n<h3 id=\"step-3-add-ebs-snapshot-life-cycle-policy-rules\">Step 3: Add EBS snapshot life cycle policy rules<\/h3>\n<p>Enter the EBS snapshot policy details as shown below. Ensure that you select the right tags for the volumes you need the snapshot.<\/p>\n<blockquote><p><strong>Note: <\/strong>You can add multiple tags to target specific Volumes<\/p><\/blockquote>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/snapshot-policy-min-1.png\" class=\"kg-image\" alt=\"Life cycle policy rules for EBS snapshot automation.\" loading=\"lazy\" width=\"588\" height=\"275\"><\/figure>\n<p>Enter EBS snapshot schedule details based on your requirements. You can choose retention type for both count &amp; age.<\/p>\n<p>For regular ec2 ebs backups, count is the ideal way.<\/p>\n<p>Also apply proper tags to identify the snapshots.<\/p>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/ebs-snapshot-policy-rules-min-1.png\" class=\"kg-image\" alt=\"ec2 policy tags for EBS snapshot automation.\" loading=\"lazy\" width=\"613\" height=\"653\" srcset=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w600\/2025\/03\/ebs-snapshot-policy-rules-min-1.png 600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/ebs-snapshot-policy-rules-min-1.png 613w\"><\/figure>\n<p>There are two optional parameters for the EBS snapshot high availability and fast restore. You can choose these options for production volumes.<\/p>\n<p>Keep in mind that these two options will incur extra charges.<\/p>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/ebs-snapshot-ppolicy-optional-parameters-min-1-1.png\" class=\"kg-image\" alt=\"High availability &amp; faster restore for EBS snapshot.\" loading=\"lazy\" width=\"572\" height=\"278\"><\/figure>\n<p>Select an IAM role that has permission to create and delete snapshots. If you don&#8217;t have an IAM role, you can use the default role option. AWS will automatically create a role for snapshots.<\/p>\n<p>I recommend you to create a custom role and use it with the policy to keep track of IAM roles.<\/p>\n<p>Also select &#8220;enable policy&#8221; for the policy to be active immediately after creation.<\/p>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/ebs-create-snapshot-policy-min-1.png\" class=\"kg-image\" alt loading=\"lazy\"><\/figure>\n<p>Click create policy.<\/p>\n<p>Now the policy manager will automatically create snapshots based on the schedules you have added.<\/p>\n<h2 id=\"create-ebs-volume-snapshots-with-cloudwatch-events\">Create EBS Volume Snapshots With Cloudwatch Events<\/h2>\n<p>Cloudwatch custom events &amp; \u00a0schedules can be used to create EBS snapshots.<\/p>\n<p>You can choose AWS services events for cloudwatch to trigger custom actions.<\/p>\n<p>To demonstrate this, I will use the cloudwatch schedule to create EBS snapshots. Follow the steps given below.<\/p>\n<p>[powerkit_posts title=&#8221;Also Read&#8221; \u00a0ids=&#8221;6350&#8243; \u00a0image_size=&#8221;pk-thumbnail&#8221; template=&#8221;list&#8221;]<\/p>\n<p>First we need to create a <a href=\"https:\/\/devopscube.com\/how-to-setup-and-push-serverapplication-logs-to-aws-cloudwatch\/\" rel=\"noreferrer noopener\">Cloudwatch<\/a> Schedule.<\/p>\n<p>Head over to cloudwatch service and click create a rule under the rule options as shown below.<\/p>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/cloudwatch-rules-min-1.png\" class=\"kg-image\" alt=\"cloudwatch events for EBS snapshot automation.\" loading=\"lazy\" width=\"604\" height=\"367\" srcset=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w600\/2025\/03\/cloudwatch-rules-min-1.png 600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/cloudwatch-rules-min-1.png 604w\"><\/figure>\n<p>You can choose either a fixed schedule or a cron expression. Under targets, search for ec2 and select the &#8220;EC2 CreateSnapshot API Call&#8221; option.<\/p>\n<p>Get the Volume ID from the EBS volume information, apply it to the Volume ID field and click &#8220;Configure details&#8221;.<\/p>\n<p>Create more targets if you want to take snapshot of more volumes.<\/p>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/cloudwatch-ebs-volume-target-min-1.png\" class=\"kg-image\" alt=\"cloudwatch rule for EBS snapshot automation.\" loading=\"lazy\" width=\"585\" height=\"603\"><\/figure>\n<p>Enter the rule name, description and click create rule.<\/p>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/create-ebs-cloudwatch-rule-min-1.png\" class=\"kg-image\" alt=\"cloudwatch rule details for EBS snapshot automation.\" loading=\"lazy\"><\/figure>\n<p>Thats it. Based on the cloudwatch schedules, the snapshots will be created.<\/p>\n<h2 id=\"automate-ebs-snapshot-creation-and-deletion-with-lambda-function\">Automate EBS snapshot Creation and Deletion With Lambda Function<\/h2>\n<p>If you have any use case where the lifecycle manager does not suffice the requirements, you can opt for lambda-based snapshot creation. Most use cases come under unscheduled activities.<\/p>\n<p>One use case I can think of is, taking snapshots just before updating\/upgrading stateful systems. You can have an automation that will trigger a lambda function that performs the snapshot action.<\/p>\n<h3 id=\"getting-started-with-lambda-based-ebs-snapshot\">Getting Started With Lambda Based EBS snapshot<\/h3>\n<p>We will use Python 2.7 scripts, lambda, IAM role, and cloud watch event schedule for this setup.<\/p>\n<p>For this lambda function to work, you need to create a tag named &#8220;backup&#8221; with the value true for all the instances for which you need a backup.<\/p>\n<p>For setting up a lambda function for creating automated snapshots, you need to do the following.<\/p>\n<ol>\n<li>A snapshot creation python script with the necessary parameters.<\/li>\n<li>An IAM role with snapshot create, modify, and delete access.<\/li>\n<li>A lambda function.<\/li>\n<\/ol>\n<h3 id=\"configure-python-script-for-ebs-snapshot\">Configure Python Script for EBS Snapshot<\/h3>\n<p>Following python code will create snapshots on all the instance which have a tag named &#8220;backup.&#8221;<\/p>\n<blockquote><p><em><strong>Note: <\/strong>You can get all the code <a href=\"https:\/\/github.com\/devopscube\/Automate-EBS-Snapshot-Lambda?ref=devopscube.com\" rel=\"noopener noreferrer\">from here<\/a><\/em><\/p><\/blockquote>\n<pre><code>import boto3\nimport collections\nimport datetime\n\nec = boto3.client('ec2')\n\ndef lambda_handler(event, context):\n    reservations = ec.describe_instances(\n        Filters=[\n            {'Name': 'tag-key', 'Values': ['backup', 'Backup']},\n        ]\n    ).get(\n        'Reservations', []\n    )\n\n    instances = sum(\n        [\n            [i for i in r['Instances']]\n            for r in reservations\n        ], [])\n\n    print \"Found %d instances that need backing up\" % len(instances)\n\n    to_tag = collections.defaultdict(list)\n\n    for instance in instances:\n        try:\n            retention_days = [\n                int(t.get('Value')) for t in instance['Tags']\n                if t['Key'] == 'Retention'][0]\n        except IndexError:\n            retention_days = 10\n\n        for dev in instance['BlockDeviceMappings']:\n            if dev.get('Ebs', None) is None:\n                continue\n            vol_id = dev['Ebs']['VolumeId']\n            print \"Found EBS volume %s on instance %s\" % (\n                vol_id, instance['InstanceId'])\n\n            snap = ec.create_snapshot(\n                VolumeId=vol_id,\n            )\n\n            to_tag[retention_days].append(snap['SnapshotId'])\n\n            print \"Retaining snapshot %s of volume %s from instance %s for %d days\" % (\n                snap['SnapshotId'],\n                vol_id,\n                instance['InstanceId'],\n                retention_days,\n            )\n\n\n    for retention_days in to_tag.keys():\n        delete_date = datetime.date.today() + datetime.timedelta(days=retention_days)\n        delete_fmt = delete_date.strftime('%Y-%m-%d')\n        print \"Will delete %d snapshots on %s\" % (len(to_tag[retention_days]), delete_fmt)\n        ec.create_tags(\n            Resources=to_tag[retention_days],\n            Tags=[\n                {'Key': 'DeleteOn', 'Value': delete_fmt},\n                {'Key': 'Name', 'Value': \"LIVE-BACKUP\"}\n            ]\n        )\n\ufeff<\/code><\/pre>\n<p>Also, you can decide on the retention time for the snapshot.<\/p>\n<p>By default, the code sets the retention days as 10. If you want to reduce or increase the retention time, you can change the following parameter in the code.<\/p>\n<p>retention_days = 10<\/p>\n<p>The python script will create a snapshot with a tag key &#8220;Deletion&#8221; and &#8220;Date&#8221; as the value that is calculated based on the retention days. This will help in deleting the snapshots which are older than the retention time.<\/p>\n<h3 id=\"lambda-function-to-automate-snapshot-creation\">Lambda Function To Automate Snapshot Creation<\/h3>\n<p>Now that we have our python script ready for creating snapshots, it has to deployed as a Lambda function.<\/p>\n<p>Triggering the Lambda function totally depends on your use case.<\/p>\n<p>For demo purposes, we will set up cloudwatch triggers to execute the lambda function whenever a snapshot is required.<\/p>\n<p>Follow the steps given below for creating a lambda function.<\/p>\n<p><strong>Step 1: <\/strong>Head over to lambda service page and select &#8220;create lambda function&#8221;.<\/p>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/create-lamda-fucntion-min-1.png\" class=\"kg-image\" alt=\"lambda function creation for EBS snapshot automation.\" loading=\"lazy\"><\/figure>\n<p><strong>Step 2: <\/strong>Choose &#8220;Author from Scratch&#8221; and python 2.7 runtime. Also, select an exiting IAM role with snapshot create permissions.<\/p>\n<p>Click &#8220;Create Function&#8221; function button after filling up the details.<\/p>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/ebs-snapshot-lambda-fucntion-min-1.png\" class=\"kg-image\" alt=\"create lambda function for EBS snapshot.\" loading=\"lazy\"><\/figure>\n<p><strong>Step 3: <\/strong>On the next page, if you scroll down, you will find the function code editor. Copy the python script from the above section to the editor and save it.<\/p>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/save-lamda-code-min-1.png\" class=\"kg-image\" alt=\"Save python script for EBS snapshot autoamtion.\" loading=\"lazy\"><\/figure>\n<p>Once saved, click the &#8220;Test&#8221; button. It will open an evet pop up. Just enter an event name and click create it.<\/p>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/lamda-code-test-min-1.png\" class=\"kg-image\" alt=\"Create lambda event for EBS snapshot python code.\" loading=\"lazy\"><\/figure>\n<p>Click &#8220;Test&#8221; button again and you will see the code getting executed and its logs as show blow. As per the code, it should create snapshots of all volumes if a instance has a tag named &#8220;Backup:True&#8221;.<\/p>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/lamda-test-execution-result-min-1.png\" class=\"kg-image\" alt=\"Test EBS snapshot python script.\" loading=\"lazy\"><\/figure>\n<p><strong>Step 4:<\/strong> Now you have a Lamda function ready to create snapshots.<\/p>\n<p>You have to decide what triggers you need to invoke the lambda function. If you click the &#8220;Add Trigger&#8221; Button from the function dashboard, it will list all the possible trigger options as shown below. You can configure one based on your use case. It can be API gateway wall or a cloudwatch even trigger like I explained above.<\/p>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/cloudwatch-lamda-event-trigger-min-1.png\" class=\"kg-image\" alt=\"Add lambda trigger for ec2 backup.\" loading=\"lazy\"><\/figure>\n<p>For example, I if choose cloudwatch event trigger, It will look like the following.<\/p>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/lamda-cloudwatch-even-trigger-min-1.png\" class=\"kg-image\" alt=\"Add schedule expression for EBS snapshot creation.\" loading=\"lazy\"><\/figure>\n<h3 id=\"ebs-snapshot-deletion-automation-using-lambda\">EBS Snapshot Deletion Automation Using Lambda<\/h3>\n<p>We have seen how to create a lambda function and create \u00a0EBS snapshots of ec2 instances tagged with a &#8220;<code>backup<\/code>&#8221; tag. We cannot keep the snapshots piling up over time. That&#8217;s the reason we used the retention days in the python code. It tags the snapshot with the deletion date.<\/p>\n<p>The deletion python script scans for snapshots with a tag with a value that matches the current date. If a snapshot matches the requirement, it will delete that snapshot. This lambda function runs every day to remove the old snapshots.<\/p>\n<p>Create a lambda function with the cloudwatch event schedule as one day. You can follow the same steps I explained above for creating the lambda function.<\/p>\n<p>Here is the python code for snapshot deletion.<\/p>\n<pre><code>import boto3\nimport re\nimport datetime\n\nec = boto3.client('ec2')\niam = boto3.client('iam')\n\ndef lambda_handler(event, context):\n    account_ids = list()\n    try:\n        \"\"\"\n        You can replace this try\/except by filling in `account_ids` yourself.\n        Get your account ID with:\n        &gt; import boto3\n        &gt; iam = boto3.client('iam')\n        &gt; print iam.get_user()['User']['Arn'].split(':')[4]\n        \"\"\"\n        iam.get_user()\n    except Exception as e:\n        # use the exception message to get the account ID the function executes under\n        account_ids.append(re.search(r'(arn:aws:sts::)([0-9]+)', str(e)).groups()[1])\n\n    delete_on = datetime.date.today().strftime('%Y-%m-%d')\n    filters = [\n        {'Name': 'tag-key', 'Values': ['DeleteOn']},\n        {'Name': 'tag-value', 'Values': [delete_on]},\n    ]\n    snapshot_response = ec.describe_snapshots(OwnerIds=account_ids, Filters=filters)\n\n    for snap in snapshot_response['Snapshots']:\n        print \"Deleting snapshot %s\" % snap['SnapshotId']\n        ec.delete_snapshot(SnapshotId=snap['SnapshotId'])<\/code><\/pre>\n<h2 id=\"how-to-restore-ebs-snapshot\">How To Restore EBS Snapshot<\/h2>\n<p>You can restore a snapshot in two ways.<\/p>\n<ol>\n<li>Restore the EBS Volume from the snapshot.<\/li>\n<li>Restore EC2 Instance from a snapshot<\/li>\n<\/ol>\n<p>You can optionally change \u00a0following while restoring a snapshot<\/p>\n<ol>\n<li>Volume Size<\/li>\n<li>Disk Type<\/li>\n<li>Availability Zone<\/li>\n<\/ol>\n<h2 id=\"restore-ebs-volume-from-a-ebs-snapshot\">Restore EBS Volume from a EBS Snapshot<\/h2>\n<p>Follow the steps given below to restore a snapshot to a EBS volume.<\/p>\n<p><strong>Step 1:<\/strong> Head over to snapshots, select the snapshot you want to restore, select the &#8220;Actions&#8221; dropdown, and click create volume.<\/p>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/ebs-snapshot-create-volume-min-1.png\" class=\"kg-image\" alt=\"create volume from EBS snapshot.\" loading=\"lazy\"><\/figure>\n<p><strong>Step 2: <\/strong>Fill in the required details and click &#8220;create volume&#8221; option.<\/p>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/create-volume-from-snapshot-min-1.png\" class=\"kg-image\" alt=\"EBS volume information for EBS restore.\" loading=\"lazy\"><\/figure>\n<p>That&#8217;s it. Your volume will be created. You can <a href=\"https:\/\/devopscube.com\/mount-ebs-volume-ec2-instance\/\" rel=\"noreferrer noopener\">mount this volume<\/a> to the required instance to access its data.<\/p>\n<h2 id=\"restore-ec2-instance-from-ebs-snapshot\">Restore EC2 Instance From EBS Snapshot<\/h2>\n<p>You can restore an ec2 instance from a EBS snapshot with two simple steps.<\/p>\n<ol>\n<li><a href=\"https:\/\/devopscube.com\/packer-tutorial-for-beginners\/\" rel=\"noreferrer noopener\">Create an AMI <\/a>(ec2 machine Image) from the snapshot.<\/li>\n<li>Launch an instance from the AMI created from the snapshot.<\/li>\n<\/ol>\n<p>Follow the below steps.<\/p>\n<p><strong>Step 1:<\/strong> Head over to snapshots, select the snapshot you want to restore, select the &#8220;<code>Actions<\/code>&#8221; dropdown, and click create an image.<\/p>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/create-ami-from-snapshot-min-1.png\" class=\"kg-image\" alt=\"Create AMI from EBS snapshot.\" loading=\"lazy\"><\/figure>\n<p><strong>Step 2: <\/strong>Enter the AMI name, description, and modify the required parameters. Click &#8220;<code>Create Image<\/code>&#8221; to register the AMI.<\/p>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/create-ec2-ami-image-from-snapshot-min-1.png\" class=\"kg-image\" alt=\"parameters for creating AMI from EBS snapshot\" loading=\"lazy\" width=\"710\" height=\"313\" srcset=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w600\/2025\/03\/create-ec2-ami-image-from-snapshot-min-1.png 600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/create-ec2-ami-image-from-snapshot-min-1.png 710w\"><\/figure>\n<p><strong>Step 3:<\/strong> Now, select AMIs from the left panel menu, select the AMI, and from the &#8220;Actions&#8221; drop-down, select launch.<\/p>\n<p>It will take you to the generic instance launch wizard. You can launch the VM as you normally do with any ec2 instance creation.<\/p>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/create-ami-snapshot-min-1.png\" class=\"kg-image\" alt=\"Launch EC2 instance from the ec2 EBS backup.\" loading=\"lazy\"><\/figure>\n<h2 id=\"aws-ebs-snapshot-features\">AWS EBS Snapshot Features<\/h2>\n<p>Following are the key features of EBS snapshots.<\/p>\n<ol>\n<li><strong>Snapshots Backend Storage is s3:<\/strong> \u00a0Whenever you take a snapshot, it gets stored in S3.<\/li>\n<li><strong>EBS snapshots are incremental:<\/strong> Every time you request a Snapshot of your EBS volume, only the changed data in the disk (delta) is copied to the new one. So irrespective of the number of snapshots, you will only pay to changed data present in the Volume. Meaning, your consistent data never gets duplicated between Snapshots. For example, your disk storage can be 20 GB, and snapshot storage can be 30 GB due to the changes notified during every snapshot creation. You can read more <a href=\"https:\/\/docs.aws.amazon.com\/AWSEC2\/latest\/UserGuide\/EBSSnapshots.html?ref=devopscube.com#how_snapshots_work\" rel=\"noreferrer noopener\">about this here <\/a><\/li>\n<\/ol>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/snapshot_1a-1.png\" class=\"kg-image\" alt=\"AWS EBS snapshot logic explained.\" loading=\"lazy\" width=\"636\" height=\"629\" srcset=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w600\/2025\/03\/snapshot_1a-1.png 600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/snapshot_1a-1.png 636w\"><\/figure>\n<h2 id=\"ebs-snapshot-best-practices\">EBS Snapshot Best Practices<\/h2>\n<p>Following are some best practices you can follow to manage EBS snapshots.<\/p>\n<ol>\n<li><strong>Standard Tagging: <\/strong>Tag your EBS volumes with standard tags across all your environments. This helps in a well-managed snapshot lifecycle management using the life cycle manager. Tags also help in <strong>tracking the cost<\/strong> associated with snapshots. You can have billing reposts based on tags.<\/li>\n<li><strong>Application Data Consistency:<\/strong> To have consistency for your snapshot backups, it is recommended to stop the IO activity on your disk and perform the disk snapshot.<\/li>\n<li><strong>Simultaneous Snapshot request:<\/strong> Snapshots do not affect disk performance, however, the simultaneous request could affect the disk performance.<\/li>\n<\/ol>\n<h2 id=\"conclusion\">Conclusion<\/h2>\n<p>In this article we have seen three methods to post an EBS snapshot automation.<\/p>\n<p>You can choose a method that suits your project needs, which complies with the organization&#8217;s security standards.<\/p>\n<p>Either you are looking for a solution to take snapshots or trying to migrate to snapshot lifecycle manager.<\/p>\n<p>Either way, leave a comment below!<\/p>\n<hr>\n<p><strong>Ngu\u1ed3n:<\/strong> <a href=\"https:\/\/devopscube.com\/automate-ebs-snapshot-creation-deletion\/\" target=\"_blank\" rel=\"noopener noreferrer\">How to Automate EBS Snapshot Creation  [ AWS Ec2 Backup ] \u2014 DevOpsCube<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Source: https:\/\/devopscube.com\/automate-ebs-snapshot-creation-deletion\/<\/p>\n","protected":false},"author":0,"featured_media":1054,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1053","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-devops"],"_links":{"self":[{"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/posts\/1053","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/types\/post"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1053"}],"version-history":[{"count":0,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/posts\/1053\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/media\/1054"}],"wp:attachment":[{"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1053"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1053"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1053"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}