Get all AWS EBS snapshots across all profiles and regions

By Saad Khamis

June 26, 2024

18463 views

In this blog, I will share a script to retrieve all AWS EBS snapshots across all profiles and regions, along with associated volume and EC2 information where available. You can choose to display the results, export them to a file, or both.

For each snapshot, I will retrieve the following attributes: Profile, Region, SnapshotId, Name, Encrypted, VolumeId, VolumeName, VolumeStatus, EC2InstanceId, EC2Name, and EC2State. You can also retrieve other attributes if needed.

Explore my other articles about AWS services:

Introduction

Amazon EBS snapshots You can back up the data on your Amazon EBS volumes by making point-in-time copies, known as Amazon EBS snapshots.

I required a summary list of EBS snapshots across all profiles and regions, along with associated volume and EC2 information where available. To accomplish this, I utilized PowerShell and AWS Tools for PowerShell.

Prerequisites

To execute the script provided in this blog, you need to:

  1. Install and configure AWS Tools for PowerShell.
  2. Log in to all necessary AWS accounts and profiles.
  3. Configure your IAM permissions to allow access to Amazon EC2.

PowerShell Cmdlets

Here are the PowerShell cmdlets we will use.

  1. Get-AWSCredential Returns an AWSCredentials object initialized with from either credentials currently set as default in the shell or saved and associated with the supplied name from the local credential store.
  2. Get-Culture Gets the current culture set in the operating system.
  3. Get-EC2Instance Describes the specified instances or all instances.
  4. Get-EC2Region Describes the Regions that are enabled for your account, or all Regions.
  5. Get-EC2Snapshot Describes the specified EBS snapshots available to you or all of the EBS snapshots available to you.
  6. Get-EC2Volume Describes the specified EBS volumes or all of your EBS volumes.

Retrieve EBS snapshots within a single profile and region

First, I used Get-EC2Snapshot cmdlet to retrieve EBS snapshots within a single profile and region.

Retrieve information about an EBS snapshot volume

Second, I used Get-EC2Volume cmdlet to retrieve information about an EBS snapshot volume.

Retrieve information about an EBS snapshot volume attachments

I used the Get-EC2Instance cmdlet to retrieve information about EBS snapshot volume attachments. In my environment, each volume is connected to only one EC2 instance. I will retrieve only the EC2 name and its state.

Compile requested EBS snapshot information along with associated volume and EC2 details

Third, I used Get-EC2Instance cmdlet to retrieve information about an EBS snapshot volume.

Compile requested EBS snapshot information within a single profile and region

Fourth, I will iterate through the above steps for each EBS snapshot.

  • To expedite processing, I will fetch all available EC2 instances and volumes within the specified profile and region, then filter them based on the snapshot criteria.
  • Additionally, I will address cases where the EBS snapshot volume does not exist and where the EBS snapshot volume attachment does exist.

Compile requested EBS snapshot information across all profiles and enabled regions

Finally, I will iterate through the aforementioned steps across all profiles and enabled regions.

  • To expedite processing, I will fetch all available EC2 instances and volumes within the specified profile and region, then filter them based on the snapshot criteria.
  • Additionally, I will address cases where the EBS snapshot volume does not exist and where the EBS snapshot volume attachment does exist.

Conclusion

Congratulations on reaching the end of this blog! Despite potentially challenging or lengthy code, you’ve made it through. Well done!

I utilized PowerShell and AWS Tools for PowerShell to create a script that retrieves all AWS EBS snapshots across all profiles and regions, including associated volume and EC2 information when available. You have the option to display the results, export them to a file, or both.

Did you find this blog easy to follow and helpful? I would love to hear your feedback and suggestions. Please let me know in the comments below.

Disclaimer

Purpose of the code contained in blog is solely for learning and demo purposes. Author will not be held responsible for any failure or damages caused due to any other usage.

Comments

There's no comments

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Posts

List all AWS Certificate Manager certificates

By Saad Khamis 14105 views July 31, 2024

Get all AWS EC2 instances across all profiles and regions

By Saad Khamis 33201 views November 27, 2023