How-to perform a simple AWS/EC2 rest API call with Curl
03:43 02 Apr 2020

Has anyone used cUrl to manage the AWS (EC2) rest API? Here I picked the simplest possible call, listing running instances. Am I missing something or am I clearly showing ignorance of proper cUrl usage? The only real lead I have is this post from 2014 aside from the scattered AWS docs which don't show an actual complete example. (I do realize there are SDKs). It's a curl expert I need...I guess and someone to help me get past the over-use of the word "canonical" by the AWS tech writer.

Rest API DescribeImages Action Create Canonical Request

Bash:

amz_access_key_ID="????"
amz_ec2_secret="????"
amz_host=ec2.amazonaws.com
amz_date8=`date -u "+%Y%m%d"`
amz_date_http=`date -uR`
amz_date_rfc8601=`date -u "+%Y%m%dT%H%M%SZ"`
amz_content_type="application/json"
amz_credential="${amz_access_key_ID}/${amz_date8}/us-west-2/ec2/aws4_request"
amz_signed_headers="${amz_host};${amz_date_rfc8601};${amz_content_type}"
amz_signature=`echo -en ${amz_signed_headers} | openssl sha256 -hmac ${amz_ec2_secret} -binary | base64`
params="Action:DescribeInstances;Version:2016-11-15;X-Amz-Algorithm:AWS4-HMAC-SHA256;X-Amz-Credential:${amz_credential};X-Amz-Date:${amz_date_rfc8601};X-Amz-SignedHeaders:${amz_signed_headers};X-Amz-Signature:${amz_signature}"
curl -X POST -H "Content-Type:${amz_content_type}" -H "Date:${amz_date_http}" -H "Host:${amz_host}" -F "${params}" http://ec2.amazonaws.com/

Result from Amazon:


Type Status Report

Message Encountered an Internal Error

Description The server encountered an unexpected condition that prevented it from fulfilling the request.


amazon-web-services rest curl amazon-ec2