aws cdk 使用非默认配置文件

aws cdk to use non-default profile

我不想使用我的默认 aws 配置文件和帐户进行 cdk 开发

所以我使用 aws configure --profile cdkprof 创建了一个新帐户和一个新配置文件 cdkprof

我已在 ~/.aws/credentials~/.aws/config 文件中验证新配置文件正确创建。 运行ning export AWS_PROFILE=cdkprof && aws configure list && aws sts get-caller-identity returns 我的个人资料详细信息正确。

我也出口了

这些在 bash 中可作为环境变量使用。

但是当我尝试 运行 :

$ npx cdk bootstrap --profile cdkprof   

我收到错误

Unable to resolve AWS account to use. It must be either configured when you define your CDK or through the environment

如何通过 cdk 命令使用我的新配置文件和帐户?

谢谢。

默认情况下,CDK 命令将使用默认的 AWS CLI 配置文件。但是,您可以通过将其添加到处理 CDK 命令的文件来为项目指定命名配置文件。对于 TypeScript 项目,这是在项目根目录的 cdk.json 中完成的:

{
  "app": "npx ts-node --prefer-ts-exts bin/project.ts",
  "profile": "cdkprof",
  "context": {
    ...
  }
}

然后,当您 运行 命令如 cdk bootstrap 时将使用您命名的配置文件。

这对我有用:cdk bootstrap aws://[ACCOUNT-NUMBER]/[REGION] --profile [YOUR PROFILE]