Skip to content

Instantly share code, notes, and snippets.

@ashee
Created March 14, 2012 17:28
Show Gist options
  • Save ashee/2038065 to your computer and use it in GitHub Desktop.
Save ashee/2038065 to your computer and use it in GitHub Desktop.
Bash script to make AWS REST calls
#!/bin/bash
KEY='<get from AWS>'
ASSOC_ID='<get from AWS>'
TS=$(date -u "+%Y-%m-%dT%H:%M:%SZ" | sed 's/:/%3A/g')
RPARMS="AWSAccessKeyId=$KEY&AssociateTag=$ASSOC_ID&ItemId=0679722769&Operation=ItemLookup&ResponseGroup=ItemAttributes%2COffers%2CImages%2CReviews&Service=AWSECommerceService&Timestamp=$TS&Version=2009-01-06"
read -r -d '' REQ <<EOF
GET
webservices.amazon.com
/onca/xml
$RPARMS
EOF
# sign - hash_hmac
PK='<get from AWS>' # private key
SR=$(echo -n "$REQ" | openssl dgst -sha256 -hmac $PK -binary | openssl enc -base64 | sed 's/+/%2B/g;s/=/%3D/g;')
R=$(echo -n "http://webservices.amazon.com/onca/xml?$RPARMS&Signature=$SR")
curl "$R"
@lupo-ch
Copy link

lupo-ch commented Jul 2, 2018

Thank you very much! Good Luck!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment