Skip to content

Instantly share code, notes, and snippets.

@pmolchanov
Created September 7, 2016 18:00
Show Gist options
  • Save pmolchanov/1d0aae12bb009b88aa43b447168b4206 to your computer and use it in GitHub Desktop.
Save pmolchanov/1d0aae12bb009b88aa43b447168b4206 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