0

在我的詹金斯建设工作我使用这个命令来承担AWS角色:AWS PowerShell中使用-STSRole:请求中包含的安全令牌是无效的

$Creds = (Use-STSRole -Region us-east-1 -RoleArn arn:aws:iam::$IAM_ACCOUNT_ID`:role/$IAM_ROLE -RoleSessionName jenkins).Credentials 

,我发现了以下错误:

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

将AWS角色更改为无效角色不会更改错误消息。

当登录到服务器并直接使用Powershell中的命令时,它工作正常。

aws sts assume-role --role-arn arn:aws:iam::%IAM_ACCOUNT_ID%:role/%IAM_ROLE% --role-session-name jenkins-deploy 

完整的错误消息:

Use-STSRole : The security token included in the request is invalid. 
At C:\Users\svc-jenkins.WIN-KLBFC355P8D\AppData\Local\Temp\jenkins4822311255190032778.ps1:5 char:11 
+ $Creds = (Use-STSRole -Region us-east-1 -RoleArn arn:aws:iam::$e ... 
+   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    + CategoryInfo   : InvalidOperation: (Amazon.PowerShe...seSTSRoleCmdlet:UseSTSRoleCmdlet) [Use-STSRole], InvalidOperationException 
    + FullyQualifiedErrorId : Amazon.SecurityToken.AmazonSecurityTokenServiceException,Amazon.PowerShell.Cmdlets.STS.UseSTSRoleCmdlet 

回答

0

这似乎与在存储在AWS不正确的凭据型材

如果我使用AWS CLI命令也适用。

这些地方使用Get-AWSCredentials上市:

Get-AWSCredentials -ListStoredCredentials 

然后清除使用Remove-AWSCredentialProfile

Remove-AWSCredentialProfile -ProfileName {MyProfileName} 

如果使用的是旧版本的AWS PowerShell的工具,你可以用Clear-AWSCredentials代替:

Clear-AWSCredentials -ProfileName <String> 
相关问题