Powershell is a useful tool for automation in Windows. AWS provides CLI tools for Powershell, including a full interface for their Simple Storage Service. If you want to automate sending files to S3 buckets, it’s pretty simple.
Setting Up the Powershell CLI
First, you’ll need to install the general AWS.Tools package, which manages all the modules for various services. Say yes to the prompts if you get an untrusted warning:
You can then install the S3 specific module:
You’ll need to link your account to the tools. There are a few methods to handle credentials—you can specify them per command, per session, or for all sessions. If this is a script running on your own machine, you’ll probably want to just set your account credentials once using the default credential store:
Note that you should create an IAM user for this, rather than using your root account.
Uploading Files
Once linked, uploading files is very easy. To upload to the root of a bucket, give the Cmdlet a bucket name and a path to the file:
To upload to a specific location, you’ll need to give it a string Key, making sure to manually specify the filename as well:
And, to sync a whole folder, use the -Folder parameter. Optionally, you can upload the folder to a subdirectory by specifying a prefix for each item:
For more documentation on other S3-related Cmdlets, you can read the reference for the module.