AWS

How to Get AWS Session Token

Session Tokens are a great way to create temporary credentials that can allow a particular user access to the AWS resources under your account (Root and IAM both). The best thing about these session tokens is that the security credentials expire after a set amount of time, and any command or action done by the user will not be executed on the AWS services. However, to get the session token, you need to make sure that you have installed the AWS CLI tools and you have Configured them.

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:

aws --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:

aws configure

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:

aws sts help

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:

aws sts get-session-token

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.

About the author

Abdul Mannan

I am curious about technology and writing and exploring it is my passion. I am interested in learning new skills and improving my knowledge and I hold a bachelor's degree in computer science.