我正在尝试使用 npx cdk diff 以及由 1Password 管理的凭据来部署 CDK 堆栈。我需要假设一个特定的 AWS 角色 (admin@ontology-dev) 来执行部署,但即使我可以在 AWS 控制台中使用假设的角色访问 AWS 资源,我仍然遇到凭证问题。
环境设置: 由 1Password 管理的凭证:我在默认配置文件中使用 credential_process 通过自定义 1password.sh 脚本检索 AWS 凭证。
配置文件配置:
这是我的
~/.aws/config
和 ~/.aws/credentials
设置:
~/.aws/config:
[default]
region = eu-west-1
duration_seconds = 10800
mfa_serial = arn:aws:iam::<my-iam-account-id>:mfa/toseef.ahmed
output = json
[profile admin@dev-profile]
role_arn = arn:aws:iam::<dev-account-id>:role/DevAdmin-CAM
source_profile = default
region = eu-west-1
duration_seconds = 10800
~/.aws/凭证:
[default]
credential_process = bash -c '$HOME/.aws/1password.sh'
1密码.sh:
#!/usr/bin/env bash
# Define 1Password parameters
ACCOUNT="myAccount"
VAULT="myValut"
ACCESS_ITEM="AWS-Access-Key"
# Retrieve access key, secret key, and OTP from 1Password
ACCESS_KEY=$(op read --account $ACCOUNT "op://$VAULT/$ACCESS_ITEM/Access Key ID")
SECRET=$(op read --account $ACCOUNT "op://$VAULT/$ACCESS_ITEM/Secret Access Key")
OTP=$(op read --account $ACCOUNT "op://$VAULT/$ACCESS_ITEM/one-time password?attribute=otp")
export ACCESS_KEY
export SECRET
访问测试:运行
aws sts get-caller-identity --profile admin@<dev-profile>
工作正常,
它给了我
{
"UserId": ""XXXAW757OFXXXXXXXXXX:XXX065653XXXXXXXXX"",
"Account": "<dev-account-id>",
"Arn": "arn:aws:sts::<dev-account-id>:assumed-role/DevAdmin-CAM/1730656531XXXXXXXX"
}
之后当我跑步时
aws s3 ls s3://<my-bucket name>/
我获取了存储桶中的文件列表。
但是,当我
run npx cdk diff -c account=dev -c environment=development --verbose
使用相同的配置文件时,我收到以下错误:
Need to perform AWS calls for account <target-account-id>, but no credentials have been configured
错误输出 这是 npx cdk diff 的详细输出的一部分:
[17:08:38] Resolving default credentials
Could not assume arn:aws:iam::<account-id>:role/cdk-hnb659fds-lookup-role-<dev-account-id>-eu-west-1, proceeding anyway.
[19:55:48] Reading cached notices from /Users/toseef.ahmed/.cdk/cache/notices.json
Need to perform AWS calls for account <dev-account-id>, but no credentials have been configured
非常感谢您的帮助。
如果您认为信息不足,请多多包涵。这是我第一次在这种设置中工作。
:,您必须提供您的AWS账户ID,而不是像这样直接提供。 <>,这个关键字的意思是,你必须把它替换成原来的。 另外,Diff 只显示前一个 stage 和新 stage 之间的差异,不用于部署。