title: How to use AWS CLI to get all access keys only by how old they are
body: <p>I want to create a script, and perhaps run it in a cron job every 24 hours, which will list all access keys older than 60 days.</p>
  <p>I also want to shove the keys older than 60 days into an array so I can iterate over it and perform other options.</p>
  <p>I'm looking at <a href="https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_access-keys.html" rel="nofollow noreferrer">Managing access keys for IAM users - AWS Identity and Access Management</a> and it has a <code>aws iam get-access-key-last-used</code> command but that's not what I want.  But it's the closet thing I can find.</p>
  <p>What I want to get the key where current date - <code>creation date &gt; 60 days</code>.</p>
  <p>I'm imagining my script would look something like this:</p>
  <pre><code># some of this is pseudocode just to 
  # communicate what I'm envisioning.
  # I don't actually know what to put
  # here yet; need assistance.
  
  myCommand = &quot;aws cli get key where age &gt; 60&quot;
  staleKeys=( $( $myCommand) )
  
  for key in &quot;${staleKeys[@]}&quot;
  do
     # log &quot;${key}&quot;
     # run another aws cli command with ${key} as a value
  done
  </code></pre>
  <p>Is this possible from the AWS CLI?</p>