Home > database >  How to list all deployed aws resources with aws cdk
How to list all deployed aws resources with aws cdk

Time:03-25

I have an AWS Cdk deployer application that deployed multiple resources in AWS. The application uses a config file that acts as an input file and using that it deployed multiple was ecs task in a fargate cluster and placed them behind an application load balancer.

Is there any way to get all the components/AWS services that are being deployed when I run cdk deploy --all. I'm trying to understand without using a separate boto3 function if there is any way which was cdk provides.

CodePudding user response:

After synth, from the 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"]]

After deploy, with the DescribeStackResources or ListStackResources APIs:

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

Both return lists of CloudFormation Resource information, but with different content. The CloudAssembly resources are from the local template generated by cdk synth. The Resources returned from boto3 or the CLI are the deployed cloud resources with resolved names.

CodePudding user response:

Since CDK generates CloudFormation templates that contain all resource definitions, you can inspect them to get a comprehensive list of created resources.

By default, the templates are generated in the cdk.out directory. If you want, you can customize it with the -o flag during synth: cdk synth --all -o ./templates and inspect the folder contents.

  • Related