AWS CDK Python(未找到凭证)

AWS CDK Python (No Credentials Found)

我在使用 AWS CDK 设置虚拟环境后尝试使用命令 CDK Bootstrap。这是我的应用程序的代码,上面的命令从中提取凭据。

#!/usr/bin/env python3

from aws_cdk import core

from hello.hello_stack import MyStack


app = core.App()
MyStack(app, "hello-cdk-1", env={'account':'IDHERE','region': 'us-east-2'})
MyStack(app, "hello-cdk-2", env={'account':'IDHERE','region': 'us-west-2'})

app.synth()

很明显我把accountID拿出来了。 使用命令 CDK Bootstrap 时,这是我的错误输出

 ❌  Environment aws://ACCOUNTIDHERE/us-west-2 failed bootstrapping: Error: Need to perform AWS calls for account ACCOUNTIDHERE, but no credentials found. Tried: default credentials.
    at CredentialsCache.getCredentials (/usr/local/lib/node_modules/aws-cdk/lib/api/util/sdk.ts:261:11)
    at CredentialsCache.get (/usr/local/lib/node_modules/aws-cdk/lib/api/util/sdk.ts:223:25)
    at SDK.cloudFormation (/usr/local/lib/node_modules/aws-cdk/lib/api/util/sdk.ts:117:20)
    at Object.deployStack (/usr/local/lib/node_modules/aws-cdk/lib/api/deploy-stack.ts:56:15)
    at Object.bootstrapEnvironment (/usr/local/lib/node_modules/aws-cdk/lib/api/bootstrap-environment.ts:93:10)
    at /usr/local/lib/node_modules/aws-cdk/bin/cdk.ts:270:24
    at async Promise.all (index 1)
Need to perform AWS calls for account ACCOUNTIDHERE, but no credentials found. Tried: default credentials.

你一开始是运行aws configure吗? 尝试cat ~/.aws/credentials,如果你看到类似一切的东西一定没问题:

[default]
region = us-east-1
aws_access_key_id = *********************
aws_secret_access_key = ******************************************

或者您在 [default] 部分中没有 aws_access_key_id/aws_secret_access_key。 您可以在此处阅读所有这些信息 - https://cdkworkshop.com/15-prerequisites/200-account.html(官方 CDK Workshop)。

我的根目录中安装了一些东西,阻止我的节点模块执行 cdk。我重新映像了我的 Mac 并且成功了。谢谢。

只需尝试使用环境变量: AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY AWS_DEFAULT_REGION

https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-envvars.html

对我有用。

我用的是cdk版本1.57.0