This article will demonstrate how to get a session token using the AWS CLI
Get AWS Session Token through CLI
Start by opening up the command prompt on your machine:
Inside the command prompt, make sure that you have installed the AWS CLI by checking for its version:
You should get the following output on your screen:
After that, the next step is to configure the AWS Credentials, for this type the following command in the command prompt:
And you will see the following output on the terminal:
As you can see, it is asking for the Access Key ID, after that, it will ask about the Secret Access Key, so type that in as well. After that, it will ask about the Default Region and the output format, so choose that according to your requirements:
Once the aws credentials have been configured, you can move on to the next command to get the session tokens. To get a session token, we need to use the “sts” command. To know about this command, simply type:
You will get the following output:
As you can see, there is a sub-command “get-session-token”. So, type the following command in the cmd:
After that, hit “enter” and then wait for a couple of seconds, and you will get your session key token on the command prompt:
As you can see, this includes the Session Token, Access Key ID, Secret Access key and even the expiration date for this token. That was all about this guide.
Conclusion
To get the session token (temporary credentials for AWS services), ensure that you have installed the AWS CLI tools on your machine and configured the AWS credentials. After that, use the “sts” command and the sub-command “get-session-token”. The session token will contain the Access Key ID, the Secret Access Key, Session Key, and the expiration date for this session token.