Skip to content

Instantly share code, notes, and snippets.

@rvrsh3ll
Forked from pmolchanov/S3UpDown.ps1
Created August 21, 2022 15:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rvrsh3ll/68d39d2db80cfd25d0f8bbf782cab2e2 to your computer and use it in GitHub Desktop.
Save rvrsh3ll/68d39d2db80cfd25d0f8bbf782cab2e2 to your computer and use it in GitHub Desktop.
Quick n Dirty S3 Upload/Download for Powershell
# Upload
&{
$ErrorActionPreference = 'Stop'
$AWSRegion = "us-east-1"
$AWSAccessKeyId = "TODO: Access Key"
$AWSSecretAccessKey = "TODO: Secret Access Key"
$BucketName = "TODO: Bucket Name"
[System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") | Out-Null
$OpenFileDialog = New-Object System.Windows.Forms.OpenFileDialog
$OpenFileDialog.ShowDialog() | Out-Null
Write-S3Object -BucketName $BucketName -Key "upload.s3" -File $OpenFileDialog.FileName -Region "$AWSRegion" -AccessKey "$AWSAccessKeyId" -SecretKey "$AWSSecretAccessKey"
}
# Download
&{
$ErrorActionPreference = 'Stop'
$AWSRegion = "us-east-1"
$AWSAccessKeyId = "TODO: Access Key"
$AWSSecretAccessKey = "TODO: Secret Access Key"
$BucketName = "TODO: Bucket Name"
[System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms") | Out-Null
$FolderBrowserDialog = New-Object System.Windows.Forms.FolderBrowserDialog
$FolderBrowserDialog.ShowDialog() | Out-Null
$File = [System.IO.Path]::Combine($FolderBrowserDialog.SelectedPath,"download.s3")
Read-S3Object -BucketName $BucketName -Key "upload.s3" -File $File -Region "$AWSRegion" -AccessKey "$AWSAccessKeyId" -SecretKey "$AWSSecretAccessKey"
Remove-S3Object -BucketName $BucketName -Key "upload.s3" -Force -Region "$AWSRegion" -AccessKey "$AWSAccessKeyId" -SecretKey "$AWSSecretAccessKey"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment