I have an s3 bucket with prefixes for stage
and production
. After QA, I want to copy all objects from stage to production. I'm trying to understand how I can do this with one command.
My googling only brings up the following, which is for copying a single object:
http://docs.aws.amazon.com/powershell/latest/reference/items/Copy-S3Object.html
I was able to upload a folder at one time in the following way
Write-S3Object -BucketName $bucketName -Folder $myfolder -Keyprefix $Keyprefix
But the Copy-S3Object
command it doesn't seem to accept a prefix and a destination prefix, for example.
What's the best way to do this?
OK, looks like the AWS CLI is a good solution in many situations, but I'm actually constrained to use Powershell here.
Here is my solution:
$objects = Get-S3Object -BucketName $bucketName -KeyPrefix $stageKeyPrefix
foreach($object in $objects) {
$prodKey = $object.Key -replace $stageKeyPrefix, $prodKeyPrefix
Copy-S3Object -BucketName $bucket -Key $object.Key -DestinationKey $prodKey
}
Believe you can only do this through the AWS Command Line Interface, see below snippet as example.
$folder = "c:\temp\MyDirectory\"
$bucket = "AWS BUCKET"
$folder = "FOLDER PREFIX"
aws s3 cp $folder s3://$bucket/$version/ --recursive
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With