如何使用 aws cdk 列出所有已部署的 aws 资源

How to list all deployed aws resources with aws cdk

我有一个 AWS Cdk 部署器应用程序,它在 AWS 中部署了多个资源。该应用程序使用一个配置文件作为输入文件,并使用它在 Fargate 集群中部署了多个 ecs 任务,并将它们放在应用程序负载均衡器后面。

有什么方法可以获取我 运行 cdk deploy --all 时正在部署的所有 components/AWS 服务。我试图在不使用单独的 boto3 函数的情况下了解 cdk 是否提供了任何方式。

合成后,来自 cdk.out CloudAssembly:

import aws_cdk.cx_api as cx_api

cloud_assembly = cx_api.CloudAssembly("cdk.out")
resources = [stack.template["Resources"] for stack in cloud_assembly.stacks]

部署后,使用 DescribeStackResources or ListStackResources API:

aws cloudformation describe-stack-resources --stack-name MyStack

两个 return CloudFormation 资源信息列表,但内容不同。 CloudAssembly 资源来自 cdk synth 生成的本地模板。来自 boto3 或 CLI 的资源 return 是已部署的具有解析名称的云资源。