Get a list of s3 buckets associated with amazon access key using powershell?

Jim P. picture Jim P. · May 21, 2015 · Viewed 10.1k times · Source

I have tried googling how I could retrieve a list of available s3 buckets associated with an Amazon Access Key, but either I am searching the wrong terms, or I haven't went through enough results.

I have an access key and secret key, but I do not know the bucket name(s) associated with either the account or IAM user.

How can I get a list of the bucket names available using Powershell and AWS Tools?

Answer

Anthony Neace picture Anthony Neace · May 21, 2015

Assuming that you've already set up your AWS Credentials the way you want, you can simply call Get-S3Bucket. This invokes ListBuckets, and returns a collection of S3Bucket objects that are visible to you:

Example:

# With credentials stored in the SDK store:
PS C:\> Get-S3Bucket

CreationDate                                                BucketName
------------                                                ----------
5/20/2015 2:00:00 PM                                        MyBucket1
5/21/2015 4:00:00 PM                                        MyBucket2

 # With credentials passed inline:    
PS C:\> Get-S3Bucket -AccessKey "accKey" -SecretKey "secKey" -Region "us-east-1"

CreationDate                                                BucketName
------------                                                ----------
5/20/2015 2:00:00 PM                                        MyBucket1
5/21/2015 4:00:00 PM                                        MyBucket2