AWS

How to Generate AWS Session Token

Session Token is a great way to ensure security when you are granting access to your account to some other user. These session tokens work as security credentials that are temporary and allow you to control when the access of the other user expires with your AWS account. When these security credentials or session tokens expire, any command or action done by the other user will not affect any of your AWS services.

This article will elaborate on the method of generating session tokens.

Generating Session Tokens

To generate the session tokens for AWS, you need to ensure that the AWS CLI tools are installed on your machine and that the AWS credentials are configured with your AWS CLI. So, let’s move to the first step, ensuring that the AWS CLI tools are installed on your machine. For this, open up either a command prompt or a PowerShell, and then type in the following command inside that:

aws --version

When you execute this command, you will see the following output on the terminal:

This confirms that you have AWS CLI tools installed on your machine. However, if the AWS CLi tools are not installed, click here to install AWS CLI.

After that, you need to configure the AWS Credentials. Type the following command inside the PowerShell:

aws configure

After that, you will be asked to provide your AWS Access Key ID, Secret Access Key, Preferred Region, and the default output format:

So provide these details in the PowerShell when they are asked. After that, your AWS credentials have been configured. After that, you can move on to get your session token.

To generate a new session token type, the following command:

aws sts get-session-token

Once you type that command, you will have to wait for a few seconds, then you will get the following output on the terminal:

As you can see, you get your session token on the PowerShell. This session token includes things:

  • Access Key ID
  • Secret Access Key
  • Session Token
  • Expiration Date for the Session Token

You can provide these details to the user to whom you want to provide access to AWS services.

Generate Session Token for a Specific Duration

The “get-session-token” command can also be used to generate a Session Token for a specific duration. To do this, you need to use the “–duration-seconds” flag to specify the duration in the form of seconds. Use the following command to generate the aws session tokens for 1800 seconds (30mins):

aws sts get-session-token --duration-seconds 180

You will get the following output:

You have successfully generated an AWS Session Token for 30 mins.

Conclusion

The AWS Session Tokens can be easily generated with the AWS CLI. To do that, use the “aws sts get-session-token” command in either the command prompt or the PowerShell, and after a few seconds, you will have the details of your Session Tokens. You can also generate the session tokens for a specific amount of time using the “–duration-seconds” flags with the previous command. This Post has taught you to generate AWS Sessions Tokens.

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.