title: AWS SSO login to credentials as environment variables
body: <p>Given that logging-in with <code>aws login sso</code> is successful.</p>
  <pre><code>Successully logged into Start URL: *****
  </code></pre>
  <p>From here I want to start my service that requires the following environment variables with AWS credentials to be set:</p>
  <ul>
  <li><code>AWS_ACCESS_KEY_ID</code></li>
  <li><code>AWS_SECRET_ACCESS_KEY</code></li>
  <li><code>AWS_SESSION_TOKEN</code></li>
  </ul>
  <p>How can I extract those variables into the current shell?</p>
  <h3>A workaround which I am currently using:</h3>
  <p>I found a possible workaround that works for me: I noticed that after I login and run <code>aws sts get-caller-identity</code> it creates files in the <code>~/.aws</code> directory, from where it can be parsed with script like:</p>
  <pre><code>#!/usr/bin/env bash
  
  set -e
  
  AWS_ACCESS_KEY_ID=$(cat ~/.aws/cli/cache/*.json | jq '.Credentials.AccessKeyId' --raw-output)
  AWS_SECRET_ACCESS_KEY=$(cat ~/.aws/cli/cache/*.json | jq '.Credentials.SecretAccessKey' --raw-output)
  AWS_SESSION_TOKEN=$(cat ~/.aws/cli/cache/*.json | jq '.Credentials.SessionToken' --raw-output)
  
  &gt;&amp;2 echo &quot;✨ you need to eval output of this script in your current window:&quot;
  &gt;&amp;2 echo '    eval $('$0')'
  &gt;&amp;2 echo &quot;&quot;
  echo &quot;export AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID}&quot;
  echo &quot;export AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY}&quot;
  echo &quot;export AWS_SESSION_TOKEN=${AWS_SESSION_TOKEN}&quot;
  </code></pre>
  <p>After <em>evaluating</em> the output of this script with <code>eval $(./parse-aws-cache.sh)</code> the environment variables are set, and I can start my service consuming AWS credentials.</p>
  <p>It works for me for today, but I have some doubts about this solution:</p>
  <ul>
  <li>I cannot see where this behavior is documented in AWS;</li>
  <li>also reading from a directory named <em>something cache</em> does not seem reliable;</li>
  <li>I have no idea how portable it is to work on other machines with a different configuration.</li>
  </ul>
  <p>Ideally, I would expect an answer which either:</p>
  <ul>
  <li>provides another, more reliable way of sourcing those environment variables;</li>
  <li>or gives a reasonable confirmation that the method of parsing those variables from the cache file is actually ok to use.</li>
  </ul>