

 AWS SDK for .NET V3가 유지 관리 모드로 전환되었습니다.

[AWS SDK for .NET V4](https://docs.aws.amazon.com/sdk-for-net/v4/developer-guide/welcome.html)로 마이그레이션하는 것이 좋습니다. 마이그레이션 방법에 대한 자세한 내용과 정보는 [유지 관리 모드 공지](https://aws.amazon.com/blogs/developer/aws-sdk-for-net-v3-maintenance-mode-announcement/)를 참조하세요.

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

# 를 CloudFormation 사용하여 액세스 AWS SDK for .NET
<a name="cloudformation-apis-intro"></a>

는 AWS 인프라 배포를 예측 가능하고 반복적으로 생성하고 프로비저닝[AWS CloudFormation](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/)하는를 AWS SDK for .NET 지원합니다.

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

는 CloudFormation 클라이언트를 위한 APIs AWS SDK for .NET 제공합니다. APIs 사용하면 템플릿 및 스택과 같은 CloudFormation 기능을 사용할 수 있습니다. 이 섹션에는 이러한 API로 작업할 때 따를 수 있는 패턴을 보여주는 몇 가지 예제가 포함되어 있습니다. 전체 API 세트를 보려면 [AWS SDK for .NET API 참조](https://docs.aws.amazon.com/sdkfornet/v3/apidocs/)를 참조하세요(그리고 "Amazon.CloudFormation"으로 스크롤하세요).

 AWS CloudFormation APIs는 [AWSSDK.CloudFormation](https://www.nuget.org/packages/AWSSDK.CloudFormation/) 패키지에서 제공됩니다.

## 사전 조건
<a name="w2aac19c15c11b7"></a>

시작하기 전에 먼저 [환경 및 프로젝트를 설정](net-dg-config.md)해야 합니다. 또한 [SDK 기능](net-dg-sdk-features.md)의 정보를 검토합니다.

## 주제
<a name="w2aac19c15c11b9"></a>

**Topics**
+ [

## API
](#w2aac19c15c11b5)
+ [

## 사전 조건
](#w2aac19c15c11b7)
+ [

## 주제
](#w2aac19c15c11b9)
+ [AWS 리소스 나열](cfn-list-resources.md)

# 를 사용하여 AWS 리소스 나열 AWS CloudFormation
<a name="cfn-list-resources"></a>

이 예제에서는를 사용하여 CloudFormation 스택의 리소스를 나열 AWS SDK for .NET 하는 방법을 보여줍니다. 이 예제에서는 하위 수준 API를 사용합니다. 애플리케이션에 인수가 없지만 단순히 사용자 보안 인증으로 액세스할 수 있는 모든 스택에 대한 정보를 수집한 다음 해당 스택에 대한 정보를 표시합니다.

## SDK 레퍼런스
<a name="w2aac19c15c11c13b5b1"></a>

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

프로그래밍 요소:
+ 네임스페이스 [Amazon.CloudFormation](https://docs.aws.amazon.com/sdkfornet/v3/apidocs/items/CloudFormation/NCloudFormation.html)

  클래스 [AmazonCloudFormationClient](https://docs.aws.amazon.com/sdkfornet/v3/apidocs/items/CloudFormation/TCloudFormationClient.html)
+ 네임스페이스 [Amazon.CloudFormation.Model](https://docs.aws.amazon.com/sdkfornet/v3/apidocs/items/CloudFormation/NCloudFormationModel.html)

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

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

  클래스 [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)

  클래스 [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)

```
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;
        }
    }
```