Skip to content

Instantly share code, notes, and snippets.

@inokoshi
Last active May 10, 2016 03:58
Show Gist options
  • Save inokoshi/fb9558f04474817a9f89573e50c06544 to your computer and use it in GitHub Desktop.
Save inokoshi/fb9558f04474817a9f89573e50c06544 to your computer and use it in GitHub Desktop.
#!/bin/bash
access_key_id=$1
access_key_secret=$2
instance_id=$3
dbname=$4
start_time=$5
end_time=$6
now=`date -u "+%Y-%m-%dT%H:%M:%SZ"`
signature_nonce=`openssl rand -hex 8`
params="AccessKeyId=${access_key_id}&Action=DescribeSlowLogs&DBInstanceId=${instance_id}&DBName=${dbname}&EndTime=${end_time}&Format=json&RegionId=cn-hangzhou&SignatureMethod=HMAC-SHA1&SignatureNonce=${signature_nonce}&SignatureVersion=1.0&StartTime=${start_time}&TimeStamp=${now}&Version=2014-08-15"
params_escape=`echo -n "${params}" | perl -MURI::Escape -lne 'print uri_escape($_)' | sed "s/%3A/%253A/g"`
signature=`echo -n "GET&%2F&${params_escape}" | openssl dgst -sha1 -hmac "${access_key_secret}&" -binary | openssl base64`
signature_escape=`echo -n "${signature}" | perl -MURI::Escape -lne 'print uri_escape($_)'`
curl -v "https://rds.aliyuncs.com/?${params}&Signature=${signature_escape}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment