Listing AWS resources using AWS CloudFormation - AWS SDK for .NET

Do you want to deploy your .NET applications to AWS in just a few simple clicks? Try our new .NET CLI tooling for a simplified deployment experience! Read our blog post and submit your feedback on GitHub!

For additional information, see the section for the deployment tool in this guide.

Listing AWS resources using AWS CloudFormation

This example shows you how to use the AWS SDK for .NET to list the resources in AWS CloudFormation stacks. The example uses the low-level API. The application takes no arguments, but simply gathers information for all stacks that are accessible to the user's credentials and then displays information about those stacks.

using System; using System.Threading.Tasks; using Amazon.CloudFormation; using Amazon.CloudFormation.Model; namespace CFNListResources { class Program { static async Task Main(string[] args) { // Create the CloudFormation client var cfnClient = new AmazonCloudFormationClient(); // List the resources for each stack await ListResources(cfnClient, await cfnClient.DescribeStacksAsync()); } // // Method to list stack resources and other information private static async Task ListResources( IAmazonCloudFormation cfnClient, DescribeStacksResponse responseDescribeStacks) { Console.WriteLine("Getting CloudFormation stack information..."); foreach (Stack stack in responseDescribeStacks.Stacks) { // Basic information for each stack Console.WriteLine("\n------------------------------------------------"); Console.WriteLine($"\nStack: {stack.StackName}"); Console.WriteLine($" Status: {stack.StackStatus.Value}"); Console.WriteLine($" Created: {stack.CreationTime}"); // The tags of each stack (etc.) if(stack.Tags.Count > 0) { Console.WriteLine(" Tags:"); foreach (Tag tag in stack.Tags) Console.WriteLine($" {tag.Key}, {tag.Value}"); } // The resources of each stack DescribeStackResourcesResponse responseDescribeResources = await cfnClient.DescribeStackResourcesAsync(new DescribeStackResourcesRequest{ StackName = stack.StackName}); if(responseDescribeResources.StackResources.Count > 0) { Console.WriteLine(" Resources:"); foreach(StackResource resource in responseDescribeResources.StackResources) Console.WriteLine($" {resource.LogicalResourceId}: {resource.ResourceStatus}"); } } Console.WriteLine("\n------------------------------------------------"); } } }