上市 AWS 资源使用 AWS CloudFormation - 适用于 .NET 的 AWS 开发工具包
AWS 文档中描述的 AWS 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅中国的 AWS 服务入门

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

上市 AWS 资源使用 AWS CloudFormation

此示例向您展示如何使用 适用于 .NET 的 AWS 开发工具包 列出资源 AWS CloudFormation 堆栈。该示例使用低级别API。应用程序不使用引数,但只需收集用户凭据可访问的所有堆栈的信息,然后显示有关这些堆栈的信息。

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------------------------------------------------"); } } }