Skip to content

Instantly share code, notes, and snippets.

@TiloGit
Last active May 23, 2025 17:25
Show Gist options
  • Save TiloGit/454b9750a014931421f5db1fbb005653 to your computer and use it in GitHub Desktop.
Save TiloGit/454b9750a014931421f5db1fbb005653 to your computer and use it in GitHub Desktop.
AWS S3 cURL example with (AWS Signature Version 4) for Google Cloud (GCP) and IBM Cloud Contnet Object Storage COS
## IBM Cloud Test upload curl style
# make sure your endpoint is align with your S3 bucket otherwise you get "The specified bucket does not exist"
# seems that IBM want AWS Sign V4 (AWS Signature Version 4)
# curl feature --aws-sigv4 (requires newer curl like 8.x) consider using container if your local curl is not new enough
# docker run -ti curlimages/curl sh
date=`date +%Fat%s`
fileName="test-tilo-${date}.txt"
echo "test tilo here at $date" > $fileName
s3Bucket="my-icos-bucket-mon01"
s3AccessKey="d5zzzzzzzzzzzzzzzzcba05"
s3SecretKey="03zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz043"
s3Region="any"
curl -X PUT \
--user "${s3AccessKey}":"${s3SecretKey}" \
--aws-sigv4 "aws:amz:${s3Region}:s3" \
--upload-file ${fileName} \
https://s3.mon01.cloud-object-storage.appdomain.cloud/${s3Bucket}/${fileName}
## Google Cloud Storage Test upload curl style
# make sure your endpoint is align with your S3 bucket otherwise you get "The specified bucket does not exist"
# seems that IBM want AWS Sign V4
# curl feature --aws-sigv4 (requires newer curl like 8.x) consider using container if your local curl is not new enough
# docker run -ti curlimages/curl sh
date=`date +%Fat%s`
fileName="test-tilo-${date}.txt"
echo "test tilo here at $date" > $fileName
s3Bucket="my-bucket-gcp123"
s3AccessKey="GOOG1EMzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzB4FQ7W"
s3SecretKey="vRhzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzVZ"
s3Region="any"
curl -X PUT \
--user "${s3AccessKey}":"${s3SecretKey}" \
--aws-sigv4 "aws:amz:${s3Region}:s3" \
--upload-file ${fileName} \
http://storage.googleapis.com/${s3Bucket}/${fileName}
##here an old sign style (works for GCP but not ICOS)
## Google Cloud Test upload curl style
## AWS Signature V2
date=`date +%Fat%s`
dateFormatted=`date -R`
s3Bucket="my-tst-blob-gcs-bucket956"
fileName="test-tilo-${date}.txt"
echo "test tilo here at $date" > $fileName
s3AccessKey="GOOG1EMZzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzM5YT"
s3SecretKey="SizzzzzzzzzzzzzzzzzzzzzzKL"
relativePath="/${s3Bucket}/${fileName}"
contentType="application/octet-stream"
stringToSign="PUT\n\n${contentType}\n${dateFormatted}\n${relativePath}"
signature=`echo -en ${stringToSign} | openssl sha1 -hmac ${s3SecretKey} -binary | base64`
curl -X PUT -T "${fileName}" \
-H "Host: ${s3Bucket}.storage.googleapis.com" \
-H "Date: ${dateFormatted}" \
-H "Content-Type: ${contentType}" \
-H "Authorization: AWS ${s3AccessKey}:${signature}" \
http://storage.googleapis.com/${fileName}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment