Amazon S3 PowerShell commands

I recently purchased a QNap NAS to store all of our photos, and I am backing it up to Amazon AWS S3. I want to be able to manage it via S3 PowerShell, and am finding that the documentation and other available bits and pieces related to managing S3 via PowerShell are lacking. As such, This is a document outlining what I have found.

Getting started

Next, set the credentials to be the default credentials for this and all future powershell sessions.

Initialize-AWSDefaults -ProfileName MyProfileName -Region us-west-2

Now, I can create a new bucket. I want to create the bucket via PowerShell. If I create the bucket via the S3 console, I will be unable to fully manage it with PowerShell in the future, so let’s start right.

If I want to expire (delete) any of this data, I could add the following in my parameters above. The below will delete anything that has been in S3/Glacier for 365 days. Since I am using this as a backup of our family’s most precious photos, I will not be expiring any data.

What if I want to download a group of files. This recently happened. I downloaded a number of photos from the camera to our Qnap and the next day headed out to the airport for a flight. My daughter asked me “you did copy those photos to the computer, right? I need them”. Well, no I didn’t. Thankfully, the Qnap uploads files quite rapidly to S3, so the images were in my S3 bucket. Here is what I did to download all the photos in the required folder, while waiting at the airport gate.