Created
June 20, 2017 14:16
-
-
Save plivox/a876f8ecf30c6eb9776f4eeee1ccab16 to your computer and use it in GitHub Desktop.
AWS S3 Get file with PowerShell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function S3-Get([string]$uri, [string]$bucket) { | |
$date = Get-Date -format "ddd, dd MMM yyyy HH:mm:ss zz00" | |
$content_type = "text/plain" | |
$request = "GET`n`n${content_type}`n${date}`n${bucket}" | |
# | |
# Bash equivalent is: | |
# $ echo -en ... | openssl sha1 -hmac ... -binary | base64 | |
# | |
$hmacsha = New-Object System.Security.Cryptography.HMACSHA1 | |
$hmacsha.key = [Text.Encoding]::ASCII.GetBytes($AWS_SECRET_ACCESS_KEY) | |
$signature = $hmacsha.ComputeHash([Text.Encoding]::ASCII.GetBytes($request)) | |
$signature = [Convert]::ToBase64String($signature) | |
curl --insecure ` | |
-H "Date: ${date}" ` | |
-H "Content-Type: ${content_type}" ` | |
-H "Authorization: AWS ${AWS_ACCESS_KEY_ID}:${signature}" "${uri}${bucket}" | |
} | |
# Exemple: | |
# S3-Get "s3_url ... " "/my_bucket" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Require curl for Windows, install with chocolatey:
$ choco install curl