首页 > 解决方案 > 为什么我收到 aws ExpiredToken:请求中包含的安全令牌已过期?

问题描述

我正在尝试测试一个 github 项目 - https://github.com/charlottemach/cross-account-aws-iam-roles关于 aws 上的 terraform 和两个帐户,假定角色。我在本地从我的电脑运行这个 terraform 脚本。当然,我在 .aws\config 中添加了两个配置文件

[default]
region = eu-west-1
output = json

[profile prod]
region = eu-north-1
output = json

[profile utils]
region = eu-north-1
output = json

和 .aws\credentials

[default]
aws_access_key_id = xxx
aws_secret_access_key = xxxx

[prod]
aws_access_key_id = xxx
aws_secret_access_key = xxxx

[utils]
aws_access_key_id = xxx
aws_secret_access_key = xxxx

问题是我收到错误。我找不到任何解决此问题的方法。首先我运行 terraform init 它执行成功,现在我运行 terraform plan 并且出现以下错误:

terraform plan
Refreshing Terraform state in-memory prior to plan...
The refreshed state will be used to calculate this plan, but will not be
persisted to local or remote state storage.


Error: error configuring Terraform AWS Provider: error validating provider credentials: error calling 
sts:GetCallerIdentity: ExpiredToken: The security token included in the request is expired
    status code: 403, request id: xxxx-xxx



Error: error configuring Terraform AWS Provider: error validating provider credentials: error calling 
sts:GetCallerIdentity: ExpiredToken: The security token included in the request is expired
    status code: 403, request id: xxxx-xxx

标签: amazon-web-servicesterraform

解决方案


Terraform 将环境变量优先于配置文件。检查以确保您的环境中没有设置 AWS_SECURITY_TOKEN 或 AWS_ACCESS_KEY_ID。

如果这两个都缺失,请运行env TF_LOG=TRACE terraform plan. 这将提供非常详细的日志,并让您知道您正在提取哪些身份验证信息。


推荐阅读