

 AWS SDK untuk .NET V3 telah memasuki mode pemeliharaan.

Kami menyarankan Anda bermigrasi ke [AWS SDK untuk .NET V4](https://docs.aws.amazon.com/sdk-for-net/v4/developer-guide/welcome.html). Untuk detail dan informasi tambahan tentang cara bermigrasi, silakan lihat [pengumuman mode pemeliharaan](https://aws.amazon.com/blogs/developer/aws-sdk-for-net-v3-maintenance-mode-announcement/) kami.

Terjemahan disediakan oleh mesin penerjemah. Jika konten terjemahan yang diberikan bertentangan dengan versi bahasa Inggris aslinya, utamakan versi bahasa Inggris.

# Mengakses CloudFormation dengan AWS SDK untuk .NET
<a name="cloudformation-apis-intro"></a>

 AWS SDK untuk .NET Dukungan [AWS CloudFormation](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/), yang menciptakan dan menyediakan penyebaran AWS infrastruktur dapat diprediksi dan berulang kali.

## APIs
<a name="w2aac19c15c11b5"></a>

 AWS SDK untuk .NET Menyediakan APIs untuk CloudFormation klien. Ini APIs memungkinkan Anda untuk bekerja dengan CloudFormation fitur seperti template dan tumpukan. Bagian ini berisi sejumlah kecil contoh yang menunjukkan pola yang dapat Anda ikuti saat bekerja dengan ini APIs. Untuk melihat set lengkap APIs, lihat [Referensi AWS SDK untuk .NET API](https://docs.aws.amazon.com/sdkfornet/v3/apidocs/) (dan gulir ke “Amazon. CloudFormation“).

Yang AWS CloudFormation APIs disediakan oleh [AWSSDK. CloudFormation](https://www.nuget.org/packages/AWSSDK.CloudFormation/)paket.

## Prasyarat
<a name="w2aac19c15c11b7"></a>

Sebelum Anda mulai, pastikan Anda telah [mengatur lingkungan dan proyek Anda](net-dg-config.md). Juga tinjau informasi di[Fitur SDK](net-dg-sdk-features.md).

## Topik
<a name="w2aac19c15c11b9"></a>

**Topics**
+ [APIs](#w2aac19c15c11b5)
+ [Prasyarat](#w2aac19c15c11b7)
+ [Topik](#w2aac19c15c11b9)
+ [AWS Sumber daya daftar](cfn-list-resources.md)

# Daftar AWS sumber daya menggunakan AWS CloudFormation
<a name="cfn-list-resources"></a>

Contoh ini menunjukkan cara menggunakan daftar sumber daya dalam CloudFormation tumpukan. AWS SDK untuk .NET Contoh menggunakan API tingkat rendah. Aplikasi tidak mengambil argumen, tetapi hanya mengumpulkan informasi untuk semua tumpukan yang dapat diakses oleh kredensi pengguna dan kemudian menampilkan informasi tentang tumpukan tersebut.

## Referensi SDK
<a name="w2aac19c15c11c13b5b1"></a>

NuGet paket:
+ [AWSSDK.CloudFormation](https://www.nuget.org/packages/AWSSDK.CloudFormation/)

Elemen pemrograman:
+ [Namespace Amazon. CloudFormation](https://docs.aws.amazon.com/sdkfornet/v3/apidocs/items/CloudFormation/NCloudFormation.html)

  Kelas [AmazonCloudFormationClient](https://docs.aws.amazon.com/sdkfornet/v3/apidocs/items/CloudFormation/TCloudFormationClient.html)
+ [Namespace Amazon. CloudFormation.Model](https://docs.aws.amazon.com/sdkfornet/v3/apidocs/items/CloudFormation/NCloudFormationModel.html)

  Kelas [ICloudFormationPaginatorFactory. DescribeStacks](https://docs.aws.amazon.com/sdkfornet/v3/apidocs/items/CloudFormation/MICloudFormationPaginatorFactoryDescribeStacksDescribeStacksRequest.html)

  Kelas [DescribeStackResourcesRequest](https://docs.aws.amazon.com/sdkfornet/v3/apidocs/items/CloudFormation/TDescribeStackResourcesRequest.html)

  Kelas [DescribeStackResourcesResponse](https://docs.aws.amazon.com/sdkfornet/v3/apidocs/items/CloudFormation/TDescribeStackResourcesResponse.html)

  [Stack](https://docs.aws.amazon.com/sdkfornet/v3/apidocs/items/CloudFormation/TStack.html) Kelas

  Kelas [StackResource](https://docs.aws.amazon.com/sdkfornet/v3/apidocs/items/CloudFormation/TStackResource.html)

  [Tag](https://docs.aws.amazon.com/sdkfornet/v3/apidocs/items/CloudFormation/TTag.html) Kelas

```
using Amazon.CloudFormation;
using Amazon.CloudFormation.Model;
using Amazon.Runtime;

namespace CloudFormationActions;

public static class HelloCloudFormation
{
    public static IAmazonCloudFormation _amazonCloudFormation;

    static async Task Main(string[] args)
    {
        // Create the CloudFormation client
        _amazonCloudFormation = new AmazonCloudFormationClient();
        Console.WriteLine($"\nIn Region: {_amazonCloudFormation.Config.RegionEndpoint}");

        // List the resources for each stack
        await ListResources();
    }

    /// <summary>
    /// Method to list stack resources and other information.
    /// </summary>
    /// <returns>True if successful.</returns>
    public static async Task<bool> ListResources()
    {
        try
        {
            Console.WriteLine("Getting CloudFormation stack information...");

            // Get all stacks using the stack paginator.
            var paginatorForDescribeStacks =
                _amazonCloudFormation.Paginators.DescribeStacks(
                    new DescribeStacksRequest());
            await foreach (Stack stack in paginatorForDescribeStacks.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 _amazonCloudFormation.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------------------------------------------------");
            return true;
        }
        catch (AmazonCloudFormationException ex)
        {
            Console.WriteLine("Unable to get stack information:\n" + ex.Message);
            return false;
        }
        catch (AmazonServiceException ex)
        {
            if (ex.Message.Contains("Unable to get IAM security credentials"))
            {
                Console.WriteLine(ex.Message);
                Console.WriteLine("If you are usnig SSO, be sure to install" +
                                  " the AWSSDK.SSO and AWSSDK.SSOOIDC packages.");
            }
            else
            {
                Console.WriteLine(ex.Message);
                Console.WriteLine(ex.StackTrace);
            }

            return false;
        }
        catch (ArgumentNullException ex)
        {
            if (ex.Message.Contains("Options property cannot be empty: ClientName"))
            {
                Console.WriteLine(ex.Message);
                Console.WriteLine("If you are using SSO, have you logged in?");
            }
            else
            {
                Console.WriteLine(ex.Message);
                Console.WriteLine(ex.StackTrace);
            }

            return false;
        }
    }
```