How can we generate the session token in aws

12,786

Solution 1

$aws sts get-session-token --duration-seconds 129600

Here 129600 can be any time you want to specify after which the keys will expire. This command will give the output like below.

{
   "Credentials": {
       "SecretAccessKey": "Sb5pXXXXXQY3/qPoL/jUjMyXXXXXuev/0j3vXs",
       "SessionToken": "FQoGZXIvYXdzENv//////////wEaDEeLj11xTbnBk6azRCKsAacCiJK85DSXExJ81GtHrkEyev8eedQcFY4EoM00PsD1FAEMOfzQclVEFsoh9Y4ZHUjgGmCPRUnYCLNc2NnHkadvmI+MT7jRRa1Mo2HA/HYStOOwEyfXFYG91MNj9rVXXXXXXXXA6+7FF6jcxj3cr1U9CDB9hjW+jGq4UgjxXXXXXXXCoIidDjl4Z911zIzP/Q+FYA1R2CUz5Y32EUaMzR+bQvmheUolLOq3wU=",
       "Expiration": "2018-11-14T21:29:56Z",
       "AccessKeyId": "ASIXXXXXXXXZ27X"
   }
}

Solution 2

You don't.

AWS_SESSION_TOKEN is not used when you have IAM User access and secret keys.

It's only needed when you use IAM Role - either through Cross-account access, or EC2 instance role, etc.

Share:
12,786

Related videos on Youtube

Vandhana
Author by

Vandhana

Updated on September 18, 2022

Comments

  • Vandhana
    Vandhana almost 2 years

    i have aws access key and secret key with me. i wanted session token to be updated in aws credential file (~/.aws/credentials), how will i get it?

    I want them to be generated in command line.

  • Vandhana
    Vandhana over 5 years
    Actually i want them to be used for a distcp command. so without session token its throwing error..
  • MLu
    MLu over 5 years
    The error is because you most likely have a session token set in you shell. Unset it and you'll be fine.
  • Vandhana
    Vandhana over 5 years
    i am completely new to aws. how shd i do that?
  • MLu
    MLu over 5 years
    @Vandhana run env | grep ^AWS_ and update your question with the output. I'll tell you what's wrong then. Also - are you on EC2 instance or on your laptop?
  • Vandhana
    Vandhana over 5 years
    EC2 instance means? i m working on a server provided for my project. and for the above command i didn't get any output :(
  • MLu
    MLu over 5 years
  • Vandhana
    Vandhana over 5 years
    Actually the keys are provided to us from a 3rd party tool, to upload few files. they gave secret key, access key and s3 path. i see aws been installed in my server.for doint distcp from hadoop to aws, i am getting some error as session token is not provided. hope the abov information helps
  • Vandhana
    Vandhana over 5 years
    stackoverflow.com/questions/53222825/aws-file-upload same as this question... but i dont see anyone answerd this :|