25. February 2017 18:18
by Aaron Medacco
1 Comments

PowerShell Script for Uploading a Local Directory to an S3 Bucket on AWS

25. February 2017 18:18 by Aaron Medacco | 1 Comments

For those needing to upload several files to S3 that are on a local directory, I've put together a simple PowerShell snippet for sending all files in a directory to a specified S3 bucket.

PowerShell S3 Upload

If you have sub-directories within a directory, those will also be copied up as long as there are files within them.

This script makes use of the AWS CLI:

$bucketName = "Your Bucket Name"; #For example, "s3://my-bucket-name"
$relativePath = "Your Relative Path"; #For example, "objects" or "myfolder/objects"
aws s3 sync $relativePath $bucketName;
Write-Host "Done";

You can also download the file here

Don't forget to swap in the name of your bucket name and the relative path of the directory from where you execute the script in the appropriate variables. And keep in mind that you can also choose to use an absolute path to the source directory instead of relative. 

If instead you want to download objects from an S3 bucket to your local directory, just swap the order of the variables in the command like this:

aws s3 sync $bucketName $relativePath;

This uses the 'sync' command within the S3 library of the AWS CLI. You can find the reference for that here.

Cheers!

Comments (1) -

Thank for this simple upload process

Add comment

Copyright © 2016-2017 Aaron Medacco