![](/img/trans.png)
[英]R on EC2 not connecting to AthenaDB in a seperate AWS account, keeps throwing "Unable to load AWS credentials from any provider in the chain"
[英]Unable to access AWS account through terraform AWS provider --
我遇到问题,状态码是:401
“创建 ec2 实例:authfailure:aws 无法验证提供的访问凭据 │ 状态代码:401,请求 ID:d103063f-0b26-4b84-9719-886e62b0e2b1”
实例代码:
resource "aws_instance" "test-EC2" {
instance_type = "t2.micro"
ami = "ami-07ffb2f4d65357b42"
}
我检查了 AMI 区域仍然无法正常工作
任何帮助,将不胜感激
我正在寻找一种通过 AWS 提供的管理控制台创建和销毁令牌的方法。 我正在了解需要访问密钥、秘密密钥和令牌的 terraform AWS 提供商。
如错误消息中所述: creating ec2 instance: authfailure: aws was not able to validate the provided access credentials │ status code: 401, request id: d103063f-0b26-4b84-9719-886e62b0e2b1"
。
很明显,terraform 无法使用 terraform AWS-provider 对自己进行身份验证。
您必须在 terraform 配置中有一个提供程序块,才能使用其中一种受支持的方式进行身份验证。
provider "aws" {
region = var.aws_region
}
通常,以下是通过 AWS-terraform 提供程序获得 AWS 身份验证的方法。
有关详细信息,请查看: https ://registry.terraform.io/providers/hashicorp/aws/latest/docs#authentication-and-configuration
默认情况下,如果您已经以编程方式登录到您的 AWS 账户,AWS-terraform 提供商将使用这些凭证。
例如:
如果您使用aws_access_key_id
和aws_secret_access_key
对自己进行身份验证,那么您可能拥有这些凭据的配置文件。 您可以在$HOME/.aws/credentials
配置文件中查看此信息。
export AWS_PROFILE="name_of_profile_using_secrets"
如果您有 SSO 用户进行身份验证
$HOME/.aws/config
中有一个可用的 sso 配置文件 在这种情况下,您需要使用以下命令使用相应的 aws sso 配置文件登录aws sso login --profile <sso_profile_name>
aws configure sso
[....] # configure your SSO
export AWS_PROFILE=<your_sso_profile>
您是否在 terraform 配置中定义了 aws 提供程序?
provider "aws" {
region = var.aws_region
profile = var.aws_profile
}
如果您在本地运行它,请设置 IAM 用户配置文件(使用 aws configure)并在当前会话中导出该配置文件。
aws configure --profile xxx
导出 AWS_PROFILE=xxx
一旦你设置了配置文件,这应该可以工作。
如果您在 Github Action 等任何管道中运行此部署,您还可以使用 OpenId connect 来避免任何 accesskey 和 secretkey。
请在此处找到 OpenId 连接的详细设置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.