Skip to content
Menu
Tech Automation Blog
  • About Author
  • Contact
Tech Automation Blog

Script to generate AWS S3 Bucket inventory

Posted on August 26, 2019February 27, 2022

Amazon Simple Storage Service (S3) is Amazon provided cloud based scalable, high speed Object storage service. According to Amazon – “Amazon Simple Storage Service (Amazon S3) is an object storage service that offers industry-leading scalability, data availability, security, and performance. This means customers of all sizes and industries can use it to store and protect any amount of data for a range of use cases, such as websites, mobile applications, backup and restore, archive, enterprise applications, IoT devices, and big data analytics. Amazon S3 provides easy-to-use management features so you can organize your data and configure finely-tuned access controls to meet your specific business, organizational, and compliance requirements. Amazon S3 is designed for 99.999999999% (11 9’s) of durability, and stores data for millions of applications for companies all around the world.”

Refer here for more information on Amazon S3 service.

The script provided below will help you to generate a quick inventory of S3 Buckets in your Account. I have provided very basic inventory script here. However, feel free to add your stuff. It assumes you have already setup your aws credentials and Powershell SDK to run on your system. If you face any issue setting those, please refer following documents to set those:

  • https://docs.aws.amazon.com/powershell/latest/userguide/specifying-your-aws-credentials.html
  • https://aws.amazon.com/powershell/

Let me know if this is helpful!

<#
.SYNOPSIS
	Script to generate CSV File with details of Amazon S3 Buckets in an AWS Account.

.DESCRIPTION
	Script to generate CSV File with details of Amazon S3 Buckets in an AWS Account.
	NOTE : Set up AWS Credentials with Proper region default before running this script. 

.NOTES

	Author: Arindam Hazra
	Version: 1.0.0
#>

$date = Get-Date -UFormat "%m-%d-%Y"
$currentDir = $(Get-Location).Path

$oFile = "$($currentDir)\S3Buckets_Details_$($date).csv"
if(Test-Path $oFile){Remove-Item $oFile -Force}

"S3 Bucket Name,Creation Date" | Out-File $oFile -Append -Encoding ascii 

Get-S3Bucket | ForEach-Object{
    $s3BucketName = $createDate = ""
    $s3BucketName = $_.BucketName
    $createDate = $_.CreationDate
	#Here we have associated Tags with the S3 Bucket. You may use it to further parse Tags.
    $tags = Get-S3BucketTagging -BucketName $s3BucketName

    "$s3BucketName,$createDate" |  Out-File $oFile -Append -Encoding ascii 
}
Exit

Before running aws scripts, set up your aws credentials following provided documentation above.

This image has an empty alt attribute; its file name is image-22.png
aws credential file sample

Download above script and save it with a .ps1 file extension. After that, Open aws powershell sdk tool console. Once, it is open run the script saved previously.

Run Powershell script

Once the script execution completes, it will generate a CSV file output like below screenshot:

Output CSV File

Share this:

  • Click to share on X (Opens in new window) X
  • Click to share on Facebook (Opens in new window) Facebook
  • Click to share on LinkedIn (Opens in new window) LinkedIn
May 2025
M T W T F S S
 1234
567891011
12131415161718
19202122232425
262728293031  
« May    

Recent Posts

  • Monitor and alert Azure Service Health issues May 5, 2020
  • AWS IAM User access review May 3, 2020
  • Integrate Azure Security Center with Event Hub April 28, 2020
  • Add Tags to Azure Subscription April 24, 2020
  • Automate Azure billing report in Excel March 6, 2020

Categories

©2025 Tech Automation Blog | Powered by SuperbThemes