pythonamazon-web-servicesboto3aws-cdk

How to list all deployed aws resources with aws cdk


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.


Solution

  • 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.