2

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.

Mark B
  • 183,023
  • 24
  • 297
  • 295
Dcook
  • 899
  • 7
  • 32

1 Answers1

5

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.

fedonev
  • 20,327
  • 2
  • 25
  • 34
  • using the above code I am getting error: `'CloudAssembly' object is not subscribable` In my deployer application I have 3 stacks.Each one I did `cdk synth stackname` and then ran the above `CloudAssembly ` code – Dcook Mar 25 '22 at 03:01
  • @Dcook My bad. I fixed the code and tested that it now works. If you first synth with `cdk synth --all`, the script will output a list with 3 maps - one map of resources for each of your app's stacks. – fedonev Mar 25 '22 at 07:41