title: How-to perform a simple AWS/EC2 rest API call with Curl
body: <p>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 <a href="https://curl.haxx.se/mail/archive-2014-10/0006.html" rel="nofollow noreferrer">post</a> 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.</p>
  
  <p><a href="https://docs.aws.amazon.com/AWSEC2/latest/APIReference/Query-Requests.html" rel="nofollow noreferrer">Rest API</a>
  <a href="https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DescribeImages.html" rel="nofollow noreferrer">DescribeImages Action</a>
  <a href="https://docs.aws.amazon.com/general/latest/gr/sigv4-create-canonical-request.html" rel="nofollow noreferrer">Create Canonical Request</a></p>
  
  <p>Bash: </p>
  
  <pre><code>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/
  </code></pre>
  
  <p>Result from Amazon:</p>
  
  <pre><code>&lt;!doctype html&gt;&lt;html...HTTP Status 500 – Internal Server Error&lt;/h1&gt;&lt;hr class="line" /&gt;&lt;p&gt;&lt;b&gt;Type&lt;/b&gt; Status Report&lt;/p&gt;&lt;p&gt;&lt;b&gt;Message&lt;/b&gt; Encountered an Internal Error&lt;/p&gt;&lt;p&gt;&lt;b&gt;Description&lt;/b&gt; The server encountered an unexpected condition that prevented it from fulfilling the request.&lt;/p&gt;&lt;hr class="line" /&gt;&lt;/body&gt;
  </code></pre>