Last active
January 24, 2024 21:08
-
-
Save bdelbosc/1c35c69827b764682d0927aab9c8cf9f to your computer and use it in GitHub Desktop.
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
#!/bin/bash -e | |
bucket=$1 | |
shift | |
filename=$1 | |
shift | |
contentType=$1 | |
shift | |
# Grab the config values | |
configFile="/path/to/.aws/credentials" | |
eval $(cat $configFile | grep -P "^\w+=.*$") | |
# Calculate the signature. | |
resource="/${bucket}/${filename}" | |
dateValue=$(date -R) | |
stringToSign="PUT\n\n${contentType}\n${dateValue}\n${resource}" | |
signature=$(echo -en ${stringToSign} | openssl sha1 -hmac ${aws_secret_access_key} -binary | base64) | |
# Output the Date and Authorization headers values | |
echo "${dateValue}|AWS ${aws_access_key_id}:${signature}" |
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
// Gatling upload of file (blobFilename, blobPath, blobMimeType) into bucket with a PUT request (limited to 5g) | |
.exec(session => { | |
val script = "/path/to/awsS3Sign.sh " + | |
bucket + " " + session("blobFilename").as[String] + " " + session("blobMimeType").as[String] | |
val scriptOutput: String = script.!! | |
val dateHeader: String = scriptOutput.substring(0, scriptOutput.indexOf('|')) | |
val authorizationHeader: String = scriptOutput.substring(scriptOutput.indexOf('|') + 1).trim() | |
println("Upload " + session("blobFilename").as[String]) | |
session.set("awsDate", dateHeader) | |
.set("awsAuth", authorizationHeader) | |
}) | |
.exec( | |
http("s3 upload") | |
.put("https://" + bucket + ".s3.amazonaws.com/${blobFilename}") | |
.header("Host", bucket + ".s3.amazonaws.com") | |
.header("Date", "${awsDate}") | |
.header("Content-Type", "${blobMimeType}") | |
.header("Authorization", "${awsAuth}") | |
.body(RawFileBody("${blobPath}")) | |
.check(status.in(200)) | |
) | |
// Disable the cache because S3 does not handle the If-None-Match header | |
val httpProtocol = http.disableCaching |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment