AWS PowerShell Use-STSRole : The security token included in the request is invalid

Question:

In my Jenkins build job I’m using this command to assume an AWS role:

I’m getting the following error:

Use-STSRole : The security token included in the request is invalid.

Changing the AWS Role to an invalid role does not change the error message.

It works fine when logging into the server and using the command in Powershell directly.

It also works if I use a AWS CLI command:

Full error message:

Answer:

It seems profiles with incorrect credentials where stored in AWS.

These where listed using Get-AWSCredentials:


Then cleared using Remove-AWSCredentialProfile:

If using an old version of AWS Powershell Tools you can use Clear-AWSCredentials instead:

Source:

AWS PowerShell Use-STSRole : The security token included in the request is invalid by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply