

Doc AWS SDK 예제 GitHub 리포지토리에서 더 많은 SDK 예제를 사용할 수 있습니다. [AWS](https://github.com/awsdocs/aws-doc-sdk-examples) 

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

# AWS SDKs CloudFormation 사용에 대한 기본 예제
<a name="cloudformation_code_examples_basics"></a>

다음 코드 예제에서는 AWS CloudFormation SDKs에서의 기본 사항을 AWS 사용하는 방법을 보여줍니다.

**Contents**
+ [안녕하세요 CloudFormation](cloudformation_example_cloudformation_Hello_section.md)
+ [작업](cloudformation_code_examples_actions.md)
  + [`CancelUpdateStack`](cloudformation_example_cloudformation_CancelUpdateStack_section.md)
  + [`ContinueUpdateRollback`](cloudformation_example_cloudformation_ContinueUpdateRollback_section.md)
  + [`CreateStack`](cloudformation_example_cloudformation_CreateStack_section.md)
  + [`DeleteStack`](cloudformation_example_cloudformation_DeleteStack_section.md)
  + [`DescribeStackEvents`](cloudformation_example_cloudformation_DescribeStackEvents_section.md)
  + [`DescribeStackResource`](cloudformation_example_cloudformation_DescribeStackResource_section.md)
  + [`DescribeStackResources`](cloudformation_example_cloudformation_DescribeStackResources_section.md)
  + [`DescribeStacks`](cloudformation_example_cloudformation_DescribeStacks_section.md)
  + [`EstimateTemplateCost`](cloudformation_example_cloudformation_EstimateTemplateCost_section.md)
  + [`GetTemplate`](cloudformation_example_cloudformation_GetTemplate_section.md)
  + [`ListStackResources`](cloudformation_example_cloudformation_ListStackResources_section.md)
  + [`ListStacks`](cloudformation_example_cloudformation_ListStacks_section.md)
  + [`UpdateStack`](cloudformation_example_cloudformation_UpdateStack_section.md)
  + [`ValidateTemplate`](cloudformation_example_cloudformation_ValidateTemplate_section.md)

# 안녕하세요 CloudFormation
<a name="cloudformation_example_cloudformation_Hello_section"></a>

다음 코드 예제에서는 CloudFormation를 사용하여 시작하는 방법을 보여 줍니다.

------
#### [ .NET ]

**SDK for .NET (v4)**  
 GitHub에 더 많은 내용이 있습니다. [AWS 코드 예 리포지토리](https://github.com/awsdocs/aws-doc-sdk-examples/tree/main/dotnetv4/CloudFormation#code-examples)에서 전체 예를 찾고 설정 및 실행하는 방법을 배워보세요.

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

namespace CloudFormationActions;

public static class HelloCloudFormation
{
    public static IAmazonCloudFormation _amazonCloudFormation = null!;

    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());
            if (paginatorForDescribeStacks.Stacks != null)
            {
                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 != null && 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 != null && 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;
        }
    }
```
+  API 세부 정보는 *AWS SDK for .NET API 참조*의 [DescribeStackResources](https://docs.aws.amazon.com/goto/DotNetSDKV4/cloudformation-2010-05-15/DescribeStackResources)를 참조하세요.

------

# AWS SDKs CloudFormation 를 사용하기 위한 작업
<a name="cloudformation_code_examples_actions"></a>

다음 코드 예제에서는 AWS SDKs를 사용하여 개별 CloudFormation 작업을 수행하는 방법을 보여줍니다. 각 예제에는 GitHub에 대한 링크가 포함되어 있습니다. 여기에서 코드 설정 및 실행에 대한 지침을 찾을 수 있습니다.

이러한 발췌문은 CloudFormation API를 호출하며 컨텍스트에서 실행해야 하는 더 큰 프로그램에서 발췌한 코드입니다. [AWS SDKs CloudFormation 사용 시나리오](cloudformation_code_examples_scenarios.md)에서 컨텍스트에 맞는 작업을 볼 수 있습니다.

 다음 예제에는 가장 일반적으로 사용되는 작업만 포함되어 있습니다. 전체 목록은 [AWS CloudFormation API 참조](https://docs.aws.amazon.com/AWSCloudFormation/latest/APIReference/Welcome.html)를 참조하세요.

**Topics**
+ [`CancelUpdateStack`](cloudformation_example_cloudformation_CancelUpdateStack_section.md)
+ [`ContinueUpdateRollback`](cloudformation_example_cloudformation_ContinueUpdateRollback_section.md)
+ [`CreateStack`](cloudformation_example_cloudformation_CreateStack_section.md)
+ [`DeleteStack`](cloudformation_example_cloudformation_DeleteStack_section.md)
+ [`DescribeStackEvents`](cloudformation_example_cloudformation_DescribeStackEvents_section.md)
+ [`DescribeStackResource`](cloudformation_example_cloudformation_DescribeStackResource_section.md)
+ [`DescribeStackResources`](cloudformation_example_cloudformation_DescribeStackResources_section.md)
+ [`DescribeStacks`](cloudformation_example_cloudformation_DescribeStacks_section.md)
+ [`EstimateTemplateCost`](cloudformation_example_cloudformation_EstimateTemplateCost_section.md)
+ [`GetTemplate`](cloudformation_example_cloudformation_GetTemplate_section.md)
+ [`ListStackResources`](cloudformation_example_cloudformation_ListStackResources_section.md)
+ [`ListStacks`](cloudformation_example_cloudformation_ListStacks_section.md)
+ [`UpdateStack`](cloudformation_example_cloudformation_UpdateStack_section.md)
+ [`ValidateTemplate`](cloudformation_example_cloudformation_ValidateTemplate_section.md)

# CLI로 `CancelUpdateStack` 사용
<a name="cloudformation_example_cloudformation_CancelUpdateStack_section"></a>

다음 코드 예시는 `CancelUpdateStack`의 사용 방법을 보여 줍니다.

------
#### [ CLI ]

**AWS CLI**  
**진행 중인 스택 업데이트를 취소하는 방법**  
다음 `cancel-update-stack` 명령은 `myteststack` 스택의 스택 업데이트를 취소합니다.  

```
aws cloudformation cancel-update-stack --stack-name myteststack
```
+  API 세부 정보는 *AWS CLI 명령 참조*의 [CancelUpdateStack](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/cloudformation/cancel-update-stack.html) 섹션을 참조하세요.

------
#### [ PowerShell ]

**Tools for PowerShell V4**  
**예 1: 지정된 스택에 대한 업데이트를 취소합니다.**  

```
Stop-CFNUpdateStack -StackName "myStack"
```
+  API 세부 정보는 *AWS Tools for PowerShell Cmdlet 참조(V4)*의 [CancelUpdateStack](https://docs.aws.amazon.com/powershell/v4/reference)을 참조하세요.

**Tools for PowerShell V5**  
**예 1: 지정된 스택에 대한 업데이트를 취소합니다.**  

```
Stop-CFNUpdateStack -StackName "myStack"
```
+  API 세부 정보는 *AWS Tools for PowerShell Cmdlet 참조(V5)*의 [CancelUpdateStack](https://docs.aws.amazon.com/powershell/v5/reference)을 참조하세요.

------

# CLI로 `ContinueUpdateRollback` 사용
<a name="cloudformation_example_cloudformation_ContinueUpdateRollback_section"></a>

다음 코드 예시는 `ContinueUpdateRollback`의 사용 방법을 보여 줍니다.

------
#### [ CLI ]

**AWS CLI**  
**업데이트 롤백을 재시도하는 방법**  
다음 `continue-update-rollback` 예제에서는 이전에 실패한 스택 업데이트에서 롤백 작업을 재개합니다.  

```
aws cloudformation continue-update-rollback \
    --stack-name my-stack
```
이 명령은 출력을 생성하지 않습니다.  
+  API 세부 정보는 *AWS CLI 명령 참조*의 [ContinueUpdateRollback](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/cloudformation/continue-update-rollback.html) 섹션을 참조하세요.

------
#### [ PowerShell ]

**Tools for PowerShell V4**  
**예 1: 이름이 지정된 스택의 롤백을 계속합니다. 스택은 'UPDATE\$1ROLLBACK\$1FAILED' 상태여야 합니다. 계속된 롤백이 성공하면 스택은 'UPDATE\$1ROLLBACK\$1COMPLETE' 상태가 됩니다.**  

```
Resume-CFNUpdateRollback -StackName "myStack"
```
+  API 세부 정보는 *AWS Tools for PowerShell Cmdlet 참조(V4)*의 [ContinueUpdateRollback](https://docs.aws.amazon.com/powershell/v4/reference)을 참조하세요.

**Tools for PowerShell V5**  
**예 1: 이름이 지정된 스택의 롤백을 계속합니다. 스택은 'UPDATE\$1ROLLBACK\$1FAILED' 상태여야 합니다. 계속된 롤백이 성공하면 스택은 'UPDATE\$1ROLLBACK\$1COMPLETE' 상태가 됩니다.**  

```
Resume-CFNUpdateRollback -StackName "myStack"
```
+  API 세부 정보는 *AWS Tools for PowerShell Cmdlet 참조(V5)*의 [ContinueUpdateRollback](https://docs.aws.amazon.com/powershell/v5/reference)을 참조하세요.

------

# CLI로 `CreateStack` 사용
<a name="cloudformation_example_cloudformation_CreateStack_section"></a>

다음 코드 예시는 `CreateStack`의 사용 방법을 보여 줍니다.

------
#### [ CLI ]

**AWS CLI**  
** AWS CloudFormation 스택을 생성하려면**  
다음 `create-stacks` 명령에서는 `sampletemplate.json` 템플릿을 사용하여 이름이 `myteststack`인 스택을 생성합니다.  

```
aws cloudformation create-stack --stack-name myteststack --template-body file://sampletemplate.json --parameters ParameterKey=KeyPairName,ParameterValue=TestKey ParameterKey=SubnetIDs,ParameterValue=SubnetID1\\,SubnetID2
```
출력:  

```
{
    "StackId": "arn:aws:cloudformation:us-east-1:123456789012:stack/myteststack/466df9e0-0dff-08e3-8e2f-5088487c4896"
}
```
자세한 내용을 알아보려면 *AWS CloudFormation 사용 설명서*의 스택을 참조하세요.  
+  API 세부 정보는 *AWS CLI 명령 참조*의 [CreateStack](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/cloudformation/create-stack.html) 섹션을 참조하세요.

------
#### [ PowerShell ]

**Tools for PowerShell V4**  
**예 1: 지정된 이름으로 새 스택을 생성합니다. 템플릿은 사용자 지정 파라미터를 사용하여 제공된 콘텐츠에서 구문 분석됩니다. 여기서, 'PK1' 및 'PK2'는 템플릿 콘텐츠에 선언된 파라미터의 이름을 나타내고, 'PV1' 및 'PV2'는 해당 파라미터의 값을 나타냅니다. 사용자 지정 파라미터는 'ParameterKey' 및 'ParameterValue' 대신 'Key' 및 'Value'를 사용하여 지정할 수도 있습니다. 스택 생성이 실패하면 롤백되지 않습니다.**  

```
New-CFNStack -StackName "myStack" `
             -TemplateBody "{TEMPLATE CONTENT HERE}" `
             -Parameter @( @{ ParameterKey="PK1"; ParameterValue="PV1" }, @{ ParameterKey="PK2"; ParameterValue="PV2" }) `
             -DisableRollback $true
```
**예 2: 지정된 이름으로 새 스택을 생성합니다. 템플릿은 사용자 지정 파라미터를 사용하여 제공된 콘텐츠에서 구문 분석됩니다. 여기서, 'PK1' 및 'PK2'는 템플릿 콘텐츠에 선언된 파라미터의 이름을 나타내고, 'PV1' 및 'PV2'는 해당 파라미터의 값을 나타냅니다. 사용자 지정 파라미터는 'ParameterKey' 및 'ParameterValue' 대신 'Key' 및 'Value'를 사용하여 지정할 수도 있습니다. 스택 생성이 실패하면 롤백됩니다.**  

```
$p1 = New-Object -Type Amazon.CloudFormation.Model.Parameter
$p1.ParameterKey = "PK1"
$p1.ParameterValue = "PV1"

$p2 = New-Object -Type Amazon.CloudFormation.Model.Parameter
$p2.ParameterKey = "PK2"
$p2.ParameterValue = "PV2"

New-CFNStack -StackName "myStack" `
             -TemplateBody "{TEMPLATE CONTENT HERE}" `
             -Parameter @( $p1, $p2 ) `
             -OnFailure "ROLLBACK"
```
**예 3: 지정된 이름으로 새 스택을 생성합니다. 템플릿은 사용자 지정 파라미터를 사용하여 Amazon S3 URL에서 가져옵니다. 여기서, 'PK1'은 템플릿 콘텐츠에 선언된 파라미터의 이름을 나타내고, 'PV1'은 해당 파라미터의 값을 나타냅니다. 사용자 지정 파라미터는 'ParameterKey' 및 'ParameterValue' 대신 'Key' 및 'Value'를 사용하여 지정할 수도 있습니다. 스택 생성이 실패하면 롤백됩니다(-DisableRollback \$1false를 지정하는 것과 동일).**  

```
New-CFNStack -StackName "myStack" `
             -TemplateURL https://s3.amazonaws.com/amzn-s3-demo-bucket/templatefile.template `
             -Parameter @{ ParameterKey="PK1"; ParameterValue="PV1" }
```
**예 4: 지정된 이름으로 새 스택을 생성합니다. 템플릿은 사용자 지정 파라미터를 사용하여 Amazon S3 URL에서 가져옵니다. 여기서, 'PK1'은 템플릿 콘텐츠에 선언된 파라미터의 이름을 나타내고, 'PV1'은 해당 파라미터의 값을 나타냅니다. 사용자 지정 파라미터는 'ParameterKey' 및 'ParameterValue' 대신 'Key' 및 'Value'를 사용하여 지정할 수도 있습니다. 스택 생성이 실패하면 롤백됩니다(-DisableRollback \$1false를 지정하는 것과 동일). 지정된 알림 AEN은 게시된 스택 관련 이벤트를 수신합니다.**  

```
New-CFNStack -StackName "myStack" `
             -TemplateURL https://s3.amazonaws.com/amzn-s3-demo-bucket/templatefile.template `
             -Parameter @{ ParameterKey="PK1"; ParameterValue="PV1" } `
             -NotificationARN @( "arn1", "arn2" )
```
+  API 세부 정보는 *AWS Tools for PowerShell Cmdlet 참조(V4)*의 [CreateStack](https://docs.aws.amazon.com/powershell/v4/reference)을 참조하세요.

**Tools for PowerShell V5**  
**예 1: 지정된 이름으로 새 스택을 생성합니다. 템플릿은 사용자 지정 파라미터를 사용하여 제공된 콘텐츠에서 구문 분석됩니다. 여기서, 'PK1' 및 'PK2'는 템플릿 콘텐츠에 선언된 파라미터의 이름을 나타내고, 'PV1' 및 'PV2'는 해당 파라미터의 값을 나타냅니다. 사용자 지정 파라미터는 'ParameterKey' 및 'ParameterValue' 대신 'Key' 및 'Value'를 사용하여 지정할 수도 있습니다. 스택 생성이 실패하면 롤백되지 않습니다.**  

```
New-CFNStack -StackName "myStack" `
             -TemplateBody "{TEMPLATE CONTENT HERE}" `
             -Parameter @( @{ ParameterKey="PK1"; ParameterValue="PV1" }, @{ ParameterKey="PK2"; ParameterValue="PV2" }) `
             -DisableRollback $true
```
**예 2: 지정된 이름으로 새 스택을 생성합니다. 템플릿은 사용자 지정 파라미터를 사용하여 제공된 콘텐츠에서 구문 분석됩니다. 여기서, 'PK1' 및 'PK2'는 템플릿 콘텐츠에 선언된 파라미터의 이름을 나타내고, 'PV1' 및 'PV2'는 해당 파라미터의 값을 나타냅니다. 사용자 지정 파라미터는 'ParameterKey' 및 'ParameterValue' 대신 'Key' 및 'Value'를 사용하여 지정할 수도 있습니다. 스택 생성이 실패하면 롤백됩니다.**  

```
$p1 = New-Object -Type Amazon.CloudFormation.Model.Parameter
$p1.ParameterKey = "PK1"
$p1.ParameterValue = "PV1"

$p2 = New-Object -Type Amazon.CloudFormation.Model.Parameter
$p2.ParameterKey = "PK2"
$p2.ParameterValue = "PV2"

New-CFNStack -StackName "myStack" `
             -TemplateBody "{TEMPLATE CONTENT HERE}" `
             -Parameter @( $p1, $p2 ) `
             -OnFailure "ROLLBACK"
```
**예 3: 지정된 이름으로 새 스택을 생성합니다. 템플릿은 사용자 지정 파라미터를 사용하여 Amazon S3 URL에서 가져옵니다. 여기서, 'PK1'은 템플릿 콘텐츠에 선언된 파라미터의 이름을 나타내고, 'PV1'은 해당 파라미터의 값을 나타냅니다. 사용자 지정 파라미터는 'ParameterKey' 및 'ParameterValue' 대신 'Key' 및 'Value'를 사용하여 지정할 수도 있습니다. 스택 생성이 실패하면 롤백됩니다(-DisableRollback \$1false를 지정하는 것과 동일).**  

```
New-CFNStack -StackName "myStack" `
             -TemplateURL https://s3.amazonaws.com/amzn-s3-demo-bucket/templatefile.template `
             -Parameter @{ ParameterKey="PK1"; ParameterValue="PV1" }
```
**예 4: 지정된 이름으로 새 스택을 생성합니다. 템플릿은 사용자 지정 파라미터를 사용하여 Amazon S3 URL에서 가져옵니다. 여기서, 'PK1'은 템플릿 콘텐츠에 선언된 파라미터의 이름을 나타내고, 'PV1'은 해당 파라미터의 값을 나타냅니다. 사용자 지정 파라미터는 'ParameterKey' 및 'ParameterValue' 대신 'Key' 및 'Value'를 사용하여 지정할 수도 있습니다. 스택 생성이 실패하면 롤백됩니다(-DisableRollback \$1false를 지정하는 것과 동일). 지정된 알림 AEN은 게시된 스택 관련 이벤트를 수신합니다.**  

```
New-CFNStack -StackName "myStack" `
             -TemplateURL https://s3.amazonaws.com/amzn-s3-demo-bucket/templatefile.template `
             -Parameter @{ ParameterKey="PK1"; ParameterValue="PV1" } `
             -NotificationARN @( "arn1", "arn2" )
```
+  API 세부 정보는 *AWS Tools for PowerShell Cmdlet 참조(V5)*의 [CreateStack](https://docs.aws.amazon.com/powershell/v5/reference)을 참조하세요.

------

# CLI로 `DeleteStack` 사용
<a name="cloudformation_example_cloudformation_DeleteStack_section"></a>

다음 코드 예시는 `DeleteStack`의 사용 방법을 보여 줍니다.

------
#### [ CLI ]

**AWS CLI**  
**스택을 삭제하는 방법**  
다음 `delete-stack` 예제에서는 지정된 스택을 삭제합니다.  

```
aws cloudformation delete-stack \
    --stack-name my-stack
```
이 명령은 출력을 생성하지 않습니다.  
+  API 세부 정보는 *AWS CLI 명령 참조*의 [DeleteStack](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/cloudformation/delete-stack.html)을 참조하세요.

------
#### [ PowerShell ]

**Tools for PowerShell V4**  
**예 1: 지정된 스택을 삭제합니다.**  

```
Remove-CFNStack -StackName "myStack"
```
+  API 세부 정보는 *AWS Tools for PowerShell Cmdlet 참조(V4)*의 [DeleteStack](https://docs.aws.amazon.com/powershell/v4/reference)을 참조하세요.

**Tools for PowerShell V5**  
**예 1: 지정된 스택을 삭제합니다.**  

```
Remove-CFNStack -StackName "myStack"
```
+  API 세부 정보는 *AWS Tools for PowerShell Cmdlet 참조(V5)*의 [DeleteStack](https://docs.aws.amazon.com/powershell/v5/reference)을 참조하세요.

------

# CLI로 `DescribeStackEvents` 사용
<a name="cloudformation_example_cloudformation_DescribeStackEvents_section"></a>

다음 코드 예시는 `DescribeStackEvents`의 사용 방법을 보여 줍니다.

------
#### [ CLI ]

**AWS CLI**  
**스택 이벤트를 설명하려면**  
다음 `describe-stack-events` 예제에서는 지정된 스택의 가장 최근 이벤트 2개를 표시합니다.  

```
aws cloudformation describe-stack-events \
    --stack-name my-stack \
    --max-items 2

{
    "StackEvents": [
        {
            "StackId": "arn:aws:cloudformation:us-west-2:123456789012:stack/my-stack/d0a825a0-e4cd-xmpl-b9fb-061c69e99204",
            "EventId": "4e1516d0-e4d6-xmpl-b94f-0a51958a168c",
            "StackName": "my-stack",
            "LogicalResourceId": "my-stack",
            "PhysicalResourceId": "arn:aws:cloudformation:us-west-2:123456789012:stack/my-stack/d0a825a0-e4cd-xmpl-b9fb-061c69e99204",
            "ResourceType": "AWS::CloudFormation::Stack",
            "Timestamp": "2019-10-02T05:34:29.556Z",
            "ResourceStatus": "UPDATE_COMPLETE"
        },
        {
            "StackId": "arn:aws:cloudformation:us-west-2:123456789012:stack/my-stack/d0a825a0-e4cd-xmpl-b9fb-061c69e99204",
            "EventId": "4dd3c810-e4d6-xmpl-bade-0aaf8b31ab7a",
            "StackName": "my-stack",
            "LogicalResourceId": "my-stack",
            "PhysicalResourceId": "arn:aws:cloudformation:us-west-2:123456789012:stack/my-stack/d0a825a0-e4cd-xmpl-b9fb-061c69e99204",
            "ResourceType": "AWS::CloudFormation::Stack",
            "Timestamp": "2019-10-02T05:34:29.127Z",
            "ResourceStatus": "UPDATE_COMPLETE_CLEANUP_IN_PROGRESS"
        }
    ],
    "NextToken": "eyJOZXh0VG9XMPLiOiBudWxsLCAiYm90b190cnVuY2F0ZV9hbW91bnQiOiAyfQ=="
}
```
+  API 세부 정보는 *AWS CLI 명령 참조*의 [DescribeStackEvents](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/cloudformation/describe-stack-events.html) 섹션을 참조하세요.

------
#### [ PowerShell ]

**Tools for PowerShell V4**  
**예 1: 지정된 스택에 대한 모든 스택 관련 이벤트를 반환합니다.**  

```
Get-CFNStackEvent -StackName "myStack"
```
+  API 세부 정보는 *AWS Tools for PowerShell Cmdlet 참조(V4)*의 [DescribeStackEvents](https://docs.aws.amazon.com/powershell/v4/reference)를 참조하세요.

**Tools for PowerShell V5**  
**예 1: 지정된 스택에 대한 모든 스택 관련 이벤트를 반환합니다.**  

```
Get-CFNStackEvent -StackName "myStack"
```
+  API 세부 정보는 *AWS Tools for PowerShell Cmdlet 참조(V5)*의 [DescribeStackEvents](https://docs.aws.amazon.com/powershell/v5/reference)를 참조하세요.

------

# CLI로 `DescribeStackResource` 사용
<a name="cloudformation_example_cloudformation_DescribeStackResource_section"></a>

다음 코드 예시는 `DescribeStackResource`의 사용 방법을 보여 줍니다.

------
#### [ CLI ]

**AWS CLI**  
**스택 리소스에 대한 정보를 가져오려면**  
다음 `describe-stack-resource` 예제에서는 지정된 스택의 이름이 `MyFunction`인 리소스에 대한 세부 정보를 표시합니다.  

```
aws cloudformation describe-stack-resource \
    --stack-name MyStack \
    --logical-resource-id MyFunction
```
출력:  

```
{
    "StackResourceDetail": {
        "StackName": "MyStack",
        "StackId": "arn:aws:cloudformation:us-east-2:123456789012:stack/MyStack/d0a825a0-e4cd-xmpl-b9fb-061c69e99204",
        "LogicalResourceId": "MyFunction",
        "PhysicalResourceId": "my-function-SEZV4XMPL4S5",
        "ResourceType": "AWS::Lambda::Function",
        "LastUpdatedTimestamp": "2019-10-02T05:34:27.989Z",
        "ResourceStatus": "UPDATE_COMPLETE",
        "Metadata": "{}",
        "DriftInformation": {
            "StackResourceDriftStatus": "IN_SYNC"
        }
    }
}
```
+  API 세부 정보는 *AWS CLI 명령 참조*의 [DescribeStackResource](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/cloudformation/describe-stack-resource.html) 섹션을 참조하세요.

------
#### [ PowerShell ]

**Tools for PowerShell V4**  
**예 1: 논리적 ID "MyDBInstance"로 지정된 스택과 연결된 템플릿에서 식별된 리소스의 설명을 반환합니다.**  

```
Get-CFNStackResource -StackName "myStack" -LogicalResourceId "MyDBInstance"
```
+  API 세부 정보는 *AWS Tools for PowerShell Cmdlet 참조(V4)*의 [DescribeStackResource](https://docs.aws.amazon.com/powershell/v4/reference)를 참조하세요.

**Tools for PowerShell V5**  
**예 1: 논리적 ID "MyDBInstance"로 지정된 스택과 연결된 템플릿에서 식별된 리소스의 설명을 반환합니다.**  

```
Get-CFNStackResource -StackName "myStack" -LogicalResourceId "MyDBInstance"
```
+  API 세부 정보는 *AWS Tools for PowerShell Cmdlet 참조(V5)*의 [DescribeStackResource](https://docs.aws.amazon.com/powershell/v5/reference)를 참조하세요.

------

# CLI로 `DescribeStackResources` 사용
<a name="cloudformation_example_cloudformation_DescribeStackResources_section"></a>

다음 코드 예시는 `DescribeStackResources`의 사용 방법을 보여 줍니다.

------
#### [ CLI ]

**AWS CLI**  
**스택 리소스에 대한 정보를 가져오려면**  
다음 `describe-stack-resources` 예제에서는 지정된 스택의 리소스에 대한 세부 정보를 표시합니다.  

```
aws cloudformation describe-stack-resources \
    --stack-name my-stack
```
출력:  

```
{
    "StackResources": [
        {
            "StackName": "my-stack",
            "StackId": "arn:aws:cloudformation:us-west-2:123456789012:stack/my-stack/d0a825a0-e4cd-xmpl-b9fb-061c69e99204",
            "LogicalResourceId": "bucket",
            "PhysicalResourceId": "my-stack-bucket-1vc62xmplgguf",
            "ResourceType": "AWS::S3::Bucket",
            "Timestamp": "2019-10-02T04:34:11.345Z",
            "ResourceStatus": "CREATE_COMPLETE",
            "DriftInformation": {
                "StackResourceDriftStatus": "IN_SYNC"
            }
        },
        {
            "StackName": "my-stack",
            "StackId": "arn:aws:cloudformation:us-west-2:123456789012:stack/my-stack/d0a825a0-e4cd-xmpl-b9fb-061c69e99204",
            "LogicalResourceId": "function",
            "PhysicalResourceId": "my-function-SEZV4XMPL4S5",
            "ResourceType": "AWS::Lambda::Function",
            "Timestamp": "2019-10-02T05:34:27.989Z",
            "ResourceStatus": "UPDATE_COMPLETE",
            "DriftInformation": {
                "StackResourceDriftStatus": "IN_SYNC"
            }
        },
        {
            "StackName": "my-stack",
            "StackId": "arn:aws:cloudformation:us-west-2:123456789012:stack/my-stack/d0a825a0-e4cd-xmpl-b9fb-061c69e99204",
            "LogicalResourceId": "functionRole",
            "PhysicalResourceId": "my-functionRole-HIZXMPLEOM9E",
            "ResourceType": "AWS::IAM::Role",
            "Timestamp": "2019-10-02T04:34:06.350Z",
            "ResourceStatus": "CREATE_COMPLETE",
            "DriftInformation": {
                "StackResourceDriftStatus": "IN_SYNC"
            }
        }
    ]
}
```
+  API 세부 정보는 *AWS CLI 명령 참조*의 [DescribeStackResources](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/cloudformation/describe-stack-resources.html) 섹션을 참조하세요.

------
#### [ PowerShell ]

**Tools for PowerShell V4**  
**예제 1: 지정된 스택과 연결된 최대 100개의 AWS 리소스에 대한 리소스 설명을 반환합니다. 스택과 연결된 모든 리소스의 세부 정보를 얻으려면 결과의 수동 페이징도 지원하는 Get-CFNStackResourceSummary를 사용하세요.**  

```
Get-CFNStackResourceList -StackName "myStack"
```
**예 2: 논리적 ID "Ec2Instance"로 지정된 스택과 연결된 템플릿에서 식별된 Amazon EC2 인스턴스의 설명을 반환합니다.**  

```
Get-CFNStackResourceList -StackName "myStack" -LogicalResourceId "Ec2Instance"
```
**예 3: 인스턴스 ID "i-123456"으로 식별되는 Amazon EC2 인스턴스를 포함하는 스택과 연결된 최대 100개의 리소스에 대한 설명을 반환합니다. 스택과 연결된 모든 리소스의 세부 정보를 얻으려면 결과의 수동 페이징도 지원하는 Get-CFNStackResourceSummary를 사용하세요.**  

```
Get-CFNStackResourceList -PhysicalResourceId "i-123456"
```
**예 4: 논리적 ID "Ec2Instance"로 지정된 스택의 템플릿에서 식별된 Amazon EC2 인스턴스의 설명을 반환합니다. 스택은 포함된 리소스의 물리적 리소스 ID를 사용하여 식별됩니다. 이 경우에는 인스턴스 ID가 "i-123456"인 Amazon EC2 인스턴스입니다. 템플릿 콘텐츠에 따라 다른 물리적 리소스를 사용하여 스택을 식별할 수도 있습니다(예: Amazon S3 버킷).**  

```
Get-CFNStackResourceList -PhysicalResourceId "i-123456" -LogicalResourceId "Ec2Instance"
```
+  API 세부 정보는 *AWS Tools for PowerShell Cmdlet 참조(V4)*의 [DescribeStackResources](https://docs.aws.amazon.com/powershell/v4/reference)를 참조하세요.

**Tools for PowerShell V5**  
**예제 1: 지정된 스택과 연결된 최대 100개의 AWS 리소스에 대한 리소스 설명을 반환합니다. 스택과 연결된 모든 리소스의 세부 정보를 얻으려면 결과의 수동 페이징도 지원하는 Get-CFNStackResourceSummary를 사용하세요.**  

```
Get-CFNStackResourceList -StackName "myStack"
```
**예 2: 논리적 ID "Ec2Instance"로 지정된 스택과 연결된 템플릿에서 식별된 Amazon EC2 인스턴스의 설명을 반환합니다.**  

```
Get-CFNStackResourceList -StackName "myStack" -LogicalResourceId "Ec2Instance"
```
**예 3: 인스턴스 ID "i-123456"으로 식별되는 Amazon EC2 인스턴스를 포함하는 스택과 연결된 최대 100개의 리소스에 대한 설명을 반환합니다. 스택과 연결된 모든 리소스의 세부 정보를 얻으려면 결과의 수동 페이징도 지원하는 Get-CFNStackResourceSummary를 사용하세요.**  

```
Get-CFNStackResourceList -PhysicalResourceId "i-123456"
```
**예 4: 논리적 ID "Ec2Instance"로 지정된 스택의 템플릿에서 식별된 Amazon EC2 인스턴스의 설명을 반환합니다. 스택은 포함된 리소스의 물리적 리소스 ID를 사용하여 식별됩니다. 이 경우에는 인스턴스 ID가 "i-123456"인 Amazon EC2 인스턴스입니다. 템플릿 콘텐츠에 따라 다른 물리적 리소스를 사용하여 스택을 식별할 수도 있습니다(예: Amazon S3 버킷).**  

```
Get-CFNStackResourceList -PhysicalResourceId "i-123456" -LogicalResourceId "Ec2Instance"
```
+  API 세부 정보는 *AWS Tools for PowerShell Cmdlet 참조(V5)*의 [DescribeStackResources](https://docs.aws.amazon.com/powershell/v5/reference)를 참조하세요.

------

# AWS SDK 또는 CLI와 `DescribeStacks` 함께 사용
<a name="cloudformation_example_cloudformation_DescribeStacks_section"></a>

다음 코드 예시는 `DescribeStacks`의 사용 방법을 보여 줍니다.

------
#### [ CLI ]

**AWS CLI**  
** AWS CloudFormation 스택을 설명하려면**  
다음 `describe-stacks` 명령에서는 `myteststack` 스택에 대한 요약 정보를 보여줍니다.  

```
aws cloudformation describe-stacks --stack-name myteststack
```
출력:  

```
{
    "Stacks":  [
        {
            "StackId": "arn:aws:cloudformation:us-east-1:123456789012:stack/myteststack/466df9e0-0dff-08e3-8e2f-5088487c4896",
            "Description": "AWS CloudFormation Sample Template S3_Bucket: Sample template showing how to create a publicly accessible S3 bucket. **WARNING** This template creates an S3 bucket. You will be billed for the AWS resources used if you create a stack from this template.",
            "Tags": [],
            "Outputs": [
                {
                    "Description": "Name of S3 bucket to hold website content",
                    "OutputKey": "BucketName",
                    "OutputValue": "myteststack-s3bucket-jssofi1zie2w"
                }
            ],
            "StackStatusReason": null,
            "CreationTime": "2013-08-23T01:02:15.422Z",
            "Capabilities": [],
            "StackName": "myteststack",
            "StackStatus": "CREATE_COMPLETE",
            "DisableRollback": false
        }
    ]
}
```
자세한 내용을 알아보려면 *AWS CloudFormation 사용 설명서*의 스택을 참조하세요.  
+  API 세부 정보는 *AWS CLI 명령 참조*의 [DescribeStacks](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/cloudformation/describe-stacks.html)를 참조하세요.

------
#### [ Go ]

**SDK for Go V2**  
 GitHub에 더 많은 내용이 있습니다. [AWS 코드 예 리포지토리](https://github.com/awsdocs/aws-doc-sdk-examples/tree/main/gov2/workflows/user_pools_and_lambda_triggers#code-examples)에서 전체 예를 찾고 설정 및 실행하는 방법을 배워보세요.

```
import (
	"context"
	"log"

	"github.com/aws/aws-sdk-go-v2/aws"
	"github.com/aws/aws-sdk-go-v2/service/cloudformation"
)

// StackOutputs defines a map of outputs from a specific stack.
type StackOutputs map[string]string

type CloudFormationActions struct {
	CfnClient *cloudformation.Client
}

// GetOutputs gets the outputs from a CloudFormation stack and puts them into a structured format.
func (actor CloudFormationActions) GetOutputs(ctx context.Context, stackName string) StackOutputs {
	output, err := actor.CfnClient.DescribeStacks(ctx, &cloudformation.DescribeStacksInput{
		StackName: aws.String(stackName),
	})
	if err != nil || len(output.Stacks) == 0 {
		log.Panicf("Couldn't find a CloudFormation stack named %v. Here's why: %v\n", stackName, err)
	}
	stackOutputs := StackOutputs{}
	for _, out := range output.Stacks[0].Outputs {
		stackOutputs[*out.OutputKey] = *out.OutputValue
	}
	return stackOutputs
}
```
+  API 세부 정보는 *AWS SDK for Go API 참조*의 [DescribeStacks](https://pkg.go.dev/github.com/aws/aws-sdk-go-v2/service/cloudformation#Client.DescribeStacks)를 참조하세요.

------
#### [ PowerShell ]

**Tools for PowerShell V4**  
**예 1: 모든 사용자 스택을 설명하는 스택 인스턴스 컬렉션을 반환합니다.**  

```
Get-CFNStack
```
**예 2: 지정된 스택을 설명하는 스택 인스턴스를 반환합니다.**  

```
Get-CFNStack -StackName "myStack"
```
+  API 세부 정보는 *AWS Tools for PowerShell Cmdlet 참조(V4)*의 [DescribeStacks](https://docs.aws.amazon.com/powershell/v4/reference)를 참조하세요.

**Tools for PowerShell V5**  
**예 1: 모든 사용자 스택을 설명하는 스택 인스턴스 컬렉션을 반환합니다.**  

```
Get-CFNStack
```
**예 2: 지정된 스택을 설명하는 스택 인스턴스를 반환합니다.**  

```
Get-CFNStack -StackName "myStack"
```
+  API 세부 정보는 *AWS Tools for PowerShell Cmdlet 참조(V5)*의 [DescribeStacks](https://docs.aws.amazon.com/powershell/v5/reference)를 참조하세요.

------

# CLI로 `EstimateTemplateCost` 사용
<a name="cloudformation_example_cloudformation_EstimateTemplateCost_section"></a>

다음 코드 예시는 `EstimateTemplateCost`의 사용 방법을 보여 줍니다.

------
#### [ CLI ]

**AWS CLI**  
**템플릿 비용을 추정하려면**  
다음 `estimate-template-cost` 예제에서는 현재 폴더에서 이름이 `template.yaml`인 템플릿에 대한 예상 비용을 생성합니다.  

```
aws cloudformation estimate-template-cost \
    --template-body file://template.yaml
```
출력:  

```
{
    "Url": "http://calculator.s3.amazonaws.com/calc5.html?key=cloudformation/7870825a-xmpl-4def-92e7-c4f8dd360cca"
}
```
+  API 세부 정보는 *AWS CLI 명령 참조*의 [EstimateTemplateCost](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/cloudformation/estimate-template-cost.html) 섹션을 참조하세요.

------
#### [ PowerShell ]

**Tools for PowerShell V4**  
**예제 1: 템플릿을 실행하는 데 필요한 리소스를 설명하는 쿼리 문자열과 함께 AWS 월별 단순 계산기 URL을 반환합니다. 템플릿은 지정된 Amazon S3 URL에서 가져오고 단일 사용자 지정 파라미터가 적용됩니다. 파라미터는 'ParameterKey' 및 'ParameterValue' 대신 'Key' 및 'Value'를 사용하여 지정할 수도 있습니다.**  

```
Measure-CFNTemplateCost -TemplateURL https://s3.amazonaws.com/amzn-s3-demo-bucket/templatefile.template `
                        -Region us-west-1 `
                        -Parameter @{ ParameterKey="KeyName"; ParameterValue="myKeyPairName" }
```
**예제 2: 템플릿을 실행하는 데 필요한 리소스를 설명하는 쿼리 문자열과 함께 AWS 월별 단순 계산기 URL을 반환합니다. 템플릿은 제공된 콘텐츠에서 구문 분석되고 사용자 지정 매개 변수가 적용됩니다. 이 예에서는 템플릿 콘텐츠가 두 개의 파라미터 'KeyName'과 'InstanceType'을 선언했다고 가정합니다. 사용자 지정 파라미터는 'ParameterKey' 및 'ParameterValue' 대신 'Key' 및 'Value'를 사용하여 지정할 수도 있습니다.**  

```
Measure-CFNTemplateCost -TemplateBody "{TEMPLATE CONTENT HERE}" `
                        -Parameter @( @{ ParameterKey="KeyName"; ParameterValue="myKeyPairName" },`
                                      @{ ParameterKey="InstanceType"; ParameterValue="m1.large" })
```
**예제 3: New-Object를 사용하여 템플릿 파라미터 세트를 빌드하고 템플릿을 실행하는 데 필요한 리소스를 설명하는 쿼리 문자열과 함께 AWS Simple Monthly Calculator URL을 반환합니다. 템플릿은 제공된 콘텐츠에서 구문 분석되고 사용자 지정 매개 변수를 포함합니다. 이 예에서는 템플릿 콘텐츠가 두 개의 파라미터 'KeyName'과 'InstanceType'을 선언했다고 가정합니다.**  

```
$p1 = New-Object -Type Amazon.CloudFormation.Model.Parameter
$p1.ParameterKey = "KeyName"
$p1.ParameterValue = "myKeyPairName"

$p2 = New-Object -Type Amazon.CloudFormation.Model.Parameter
$p2.ParameterKey = "InstanceType"
$p2.ParameterValue = "m1.large"

Measure-CFNTemplateCost -TemplateBody "{TEMPLATE CONTENT HERE}" -Parameter @( $p1, $p2 )
```
+  API 세부 정보는 *AWS Tools for PowerShell Cmdlet 참조(V4)*의 [EstimateTemplateCost](https://docs.aws.amazon.com/powershell/v4/reference)를 참조하세요.

**Tools for PowerShell V5**  
**예제 1: 템플릿을 실행하는 데 필요한 리소스를 설명하는 쿼리 문자열과 함께 AWS 월별 단순 계산기 URL을 반환합니다. 템플릿은 지정된 Amazon S3 URL에서 가져오고 단일 사용자 지정 파라미터가 적용됩니다. 파라미터는 'ParameterKey' 및 'ParameterValue' 대신 'Key' 및 'Value'를 사용하여 지정할 수도 있습니다.**  

```
Measure-CFNTemplateCost -TemplateURL https://s3.amazonaws.com/amzn-s3-demo-bucket/templatefile.template `
                        -Region us-west-1 `
                        -Parameter @{ ParameterKey="KeyName"; ParameterValue="myKeyPairName" }
```
**예제 2: 템플릿을 실행하는 데 필요한 리소스를 설명하는 쿼리 문자열과 함께 AWS 월별 단순 계산기 URL을 반환합니다. 템플릿은 제공된 콘텐츠에서 구문 분석되고 사용자 지정 매개 변수가 적용됩니다. 이 예에서는 템플릿 콘텐츠가 두 개의 파라미터 'KeyName'과 'InstanceType'을 선언했다고 가정합니다. 사용자 지정 파라미터는 'ParameterKey' 및 'ParameterValue' 대신 'Key' 및 'Value'를 사용하여 지정할 수도 있습니다.**  

```
Measure-CFNTemplateCost -TemplateBody "{TEMPLATE CONTENT HERE}" `
                        -Parameter @( @{ ParameterKey="KeyName"; ParameterValue="myKeyPairName" },`
                                      @{ ParameterKey="InstanceType"; ParameterValue="m1.large" })
```
**예제 3: New-Object를 사용하여 템플릿 파라미터 세트를 빌드하고 템플릿을 실행하는 데 필요한 리소스를 설명하는 쿼리 문자열과 함께 AWS Simple Monthly Calculator URL을 반환합니다. 템플릿은 제공된 콘텐츠에서 구문 분석되고 사용자 지정 매개 변수를 포함합니다. 이 예에서는 템플릿 콘텐츠가 두 개의 파라미터 'KeyName'과 'InstanceType'을 선언했다고 가정합니다.**  

```
$p1 = New-Object -Type Amazon.CloudFormation.Model.Parameter
$p1.ParameterKey = "KeyName"
$p1.ParameterValue = "myKeyPairName"

$p2 = New-Object -Type Amazon.CloudFormation.Model.Parameter
$p2.ParameterKey = "InstanceType"
$p2.ParameterValue = "m1.large"

Measure-CFNTemplateCost -TemplateBody "{TEMPLATE CONTENT HERE}" -Parameter @( $p1, $p2 )
```
+  API 세부 정보는 *AWS Tools for PowerShell Cmdlet 참조(V5)*의 [EstimateTemplateCost](https://docs.aws.amazon.com/powershell/v5/reference)를 참조하세요.

------

# CLI로 `GetTemplate` 사용
<a name="cloudformation_example_cloudformation_GetTemplate_section"></a>

다음 코드 예시는 `GetTemplate`의 사용 방법을 보여 줍니다.

------
#### [ CLI ]

**AWS CLI**  
** AWS CloudFormation 스택의 템플릿 본문을 보려면**  
다음 `get-template` 명령에서는 `myteststack` 스택에 대한 템플릿을 보여줍니다.  

```
aws cloudformation get-template --stack-name myteststack
```
출력:  

```
{
    "TemplateBody": {
        "AWSTemplateFormatVersion": "2010-09-09",
        "Outputs": {
            "BucketName": {
                "Description": "Name of S3 bucket to hold website content",
                "Value": {
                    "Ref": "S3Bucket"
                }
            }
        },
        "Description": "AWS CloudFormation Sample Template S3_Bucket: Sample template showing how to create a publicly accessible S3 bucket. **WARNING** This template creates an S3 bucket. You will be billed for the AWS resources used if you create a stack from this template.",
        "Resources": {
            "S3Bucket": {
                "Type": "AWS::S3::Bucket",
                "Properties": {
                    "AccessControl": "PublicRead"
                }
            }
        }
    }
}
```
+  API 세부 정보는 *AWS CLI 명령 참조*의 [GetTemplate](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/cloudformation/get-template.html)을 참조하세요.

------
#### [ PowerShell ]

**Tools for PowerShell V4**  
**예 1: 지정된 스택과 연결된 템플릿을 반환합니다.**  

```
Get-CFNTemplate -StackName "myStack"
```
+  API 세부 정보는 *AWS Tools for PowerShell Cmdlet 참조(V4)*의 [GetTemplate](https://docs.aws.amazon.com/powershell/v4/reference)을 참조하세요.

**Tools for PowerShell V5**  
**예 1: 지정된 스택과 연결된 템플릿을 반환합니다.**  

```
Get-CFNTemplate -StackName "myStack"
```
+  API 세부 정보는 *AWS Tools for PowerShell Cmdlet 참조(V5)*의 [GetTemplate](https://docs.aws.amazon.com/powershell/v5/reference)을 참조하세요.

------

# CLI로 `ListStackResources` 사용
<a name="cloudformation_example_cloudformation_ListStackResources_section"></a>

다음 코드 예시는 `ListStackResources`의 사용 방법을 보여 줍니다.

------
#### [ CLI ]

**AWS CLI**  
**스택의 리소스를 나열하려면**  
다음 명령은 지정된 스택의 리소스 목록을 표시합니다.  

```
aws cloudformation list-stack-resources \
    --stack-name my-stack
```
출력:  

```
{
    "StackResourceSummaries": [
        {
            "LogicalResourceId": "bucket",
            "PhysicalResourceId": "my-stack-bucket-1vc62xmplgguf",
            "ResourceType": "AWS::S3::Bucket",
            "LastUpdatedTimestamp": "2019-10-02T04:34:11.345Z",
            "ResourceStatus": "CREATE_COMPLETE",
            "DriftInformation": {
                "StackResourceDriftStatus": "IN_SYNC"
            }
        },
        {
            "LogicalResourceId": "function",
            "PhysicalResourceId": "my-function-SEZV4XMPL4S5",
            "ResourceType": "AWS::Lambda::Function",
            "LastUpdatedTimestamp": "2019-10-02T05:34:27.989Z",
            "ResourceStatus": "UPDATE_COMPLETE",
            "DriftInformation": {
                "StackResourceDriftStatus": "IN_SYNC"
            }
        },
        {
            "LogicalResourceId": "functionRole",
            "PhysicalResourceId": "my-functionRole-HIZXMPLEOM9E",
            "ResourceType": "AWS::IAM::Role",
            "LastUpdatedTimestamp": "2019-10-02T04:34:06.350Z",
            "ResourceStatus": "CREATE_COMPLETE",
            "DriftInformation": {
                "StackResourceDriftStatus": "IN_SYNC"
            }
        }
    ]
}
```
+  API 세부 정보는 *AWS CLI 명령 참조*의 [ListStackResources](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/cloudformation/list-stack-resources.html) 섹션을 참조하세요.

------
#### [ PowerShell ]

**Tools for PowerShell V4**  
**예 1: 지정된 스택과 연결된 모든 리소스에 대한 설명을 반환합니다.**  

```
Get-CFNStackResourceSummary -StackName "myStack"
```
+  API 세부 정보는 **AWS Tools for PowerShell Cmdlet 참조(V4)의 [ListStackResources](https://docs.aws.amazon.com/powershell/v4/reference)를 참조하세요.

**Tools for PowerShell V5**  
**예 1: 지정된 스택과 연결된 모든 리소스에 대한 설명을 반환합니다.**  

```
Get-CFNStackResourceSummary -StackName "myStack"
```
+  API 세부 정보는 **AWS Tools for PowerShell Cmdlet 참조(V5)의 [ListStackResources](https://docs.aws.amazon.com/powershell/v5/reference)를 참조하세요.

------

# CLI로 `ListStacks` 사용
<a name="cloudformation_example_cloudformation_ListStacks_section"></a>

다음 코드 예시는 `ListStacks`의 사용 방법을 보여 줍니다.

------
#### [ CLI ]

**AWS CLI**  
** AWS CloudFormation 스택을 나열하려면**  
다음 `list-stacks` 명령에서는 상태가 `CREATE_COMPLETE`인 모든 스택에 대한 요약 내용을 보여줍니다.  

```
aws cloudformation list-stacks --stack-status-filter CREATE_COMPLETE
```
출력:  

```
[
    {
        "StackId": "arn:aws:cloudformation:us-east-1:123456789012:stack/myteststack/466df9e0-0dff-08e3-8e2f-5088487c4896",
        "TemplateDescription": "AWS CloudFormation Sample Template S3_Bucket: Sample template showing how to create a publicly accessible S3 bucket. **WARNING** This template creates an S3 bucket. You will be billed for the AWS resources used if you create a stack from this template.",
        "StackStatusReason": null,
        "CreationTime": "2013-08-26T03:27:10.190Z",
        "StackName": "myteststack",
        "StackStatus": "CREATE_COMPLETE"
    }
]
```
+  API 세부 정보는 *AWS CLI 명령 참조*의 [ListStacks](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/cloudformation/list-stacks.html) 섹션을 참조하세요.

------
#### [ PowerShell ]

**Tools for PowerShell V4**  
**예 1: 모든 스택에 대한 요약 정보를 반환합니다.**  

```
Get-CFNStackSummary
```
**예 2: 현재 생성 중인 모든 스택에 대한 요약 정보를 반환합니다.**  

```
Get-CFNStackSummary -StackStatusFilter "CREATE_IN_PROGRESS"
```
**예 3: 현재 생성 중이거나 업데이트 중인 모든 스택에 대한 요약 정보를 반환합니다.**  

```
Get-CFNStackSummary -StackStatusFilter @("CREATE_IN_PROGRESS", "UPDATE_IN_PROGRESS")
```
+  API 세부 정보는 *AWS Tools for PowerShell Cmdlet 참조(V4)*의 [ListStacks](https://docs.aws.amazon.com/powershell/v4/reference)를 참조하세요.

**Tools for PowerShell V5**  
**예 1: 모든 스택에 대한 요약 정보를 반환합니다.**  

```
Get-CFNStackSummary
```
**예 2: 현재 생성 중인 모든 스택에 대한 요약 정보를 반환합니다.**  

```
Get-CFNStackSummary -StackStatusFilter "CREATE_IN_PROGRESS"
```
**예 3: 현재 생성 중이거나 업데이트 중인 모든 스택에 대한 요약 정보를 반환합니다.**  

```
Get-CFNStackSummary -StackStatusFilter @("CREATE_IN_PROGRESS", "UPDATE_IN_PROGRESS")
```
+  API 세부 정보는 *AWS Tools for PowerShell Cmdlet 참조(V5)*의 [ListStacks](https://docs.aws.amazon.com/powershell/v5/reference)를 참조하세요.

------

# CLI로 `UpdateStack` 사용
<a name="cloudformation_example_cloudformation_UpdateStack_section"></a>

다음 코드 예시는 `UpdateStack`의 사용 방법을 보여 줍니다.

------
#### [ CLI ]

**AWS CLI**  
** AWS CloudFormation 스택을 업데이트하려면**  
다음 `update-stack` 명령에서는 `mystack` 스택의 템플릿 및 입력 파라미터를 업데이트합니다.  

```
aws cloudformation update-stack --stack-name mystack --template-url https://s3.amazonaws.com/sample/updated.template --parameters ParameterKey=KeyPairName,ParameterValue=SampleKeyPair ParameterKey=SubnetIDs,ParameterValue=SampleSubnetID1\\,SampleSubnetID2
```
다음 `update-stack` 명령에서는 `mystack` 스택의 `SubnetIDs` 파라미터값만 업데이트합니다. 파라미터값을 지정하지 않으면 템플릿에 지정된 기본값이 사용됩니다.  

```
aws cloudformation update-stack --stack-name mystack --template-url https://s3.amazonaws.com/sample/updated.template --parameters ParameterKey=KeyPairName,UsePreviousValue=true ParameterKey=SubnetIDs,ParameterValue=SampleSubnetID1\\,UpdatedSampleSubnetID2
```
다음 `update-stack` 명령에서는 `mystack` 스택에 스택 알림 주제 2개를 추가합니다.  

```
aws cloudformation update-stack --stack-name mystack --use-previous-template --notification-arns "arn:aws:sns:use-east-1:123456789012:mytopic1" "arn:aws:sns:us-east-1:123456789012:mytopic2"
```
자세한 내용을 알아보려면 *AWS CloudFormation 사용 설명서*의 [AWS CloudFormation 스택 업데이트](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-updating-stacks.html)를 참조하세요.  
+  API 세부 정보는 *AWS CLI 명령 참조*의 [UpdateStack](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/cloudformation/update-stack.html)을 참조하세요.

------
#### [ PowerShell ]

**Tools for PowerShell V4**  
**예 1: 지정된 템플릿 및 사용자 지정 파라미터를 사용하여 'myStack' 스택을 업데이트합니다. 'PK1'은 템플릿에 선언된 파라미터의 이름을 나타내고 'PV1'은 해당 값을 나타냅니다. 사용자 지정 파라미터는 'ParameterKey' 및 'ParameterValue' 대신 'Key' 및 'Value'를 사용하여 지정할 수도 있습니다.**  

```
Update-CFNStack -StackName "myStack" `
                -TemplateBody "{Template Content Here}" `
                -Parameter @{ ParameterKey="PK1"; ParameterValue="PV1" }
```
**예 2: 지정된 템플릿 및 사용자 지정 파라미터를 사용하여 'myStack' 스택을 업데이트합니다. 'PK1' 및 'PK2'는 템플릿에 선언된 파라미터의 이름을 나타내고, 'PV1' 및 'PV2'는 요청된 값을 나타냅니다. 사용자 지정 파라미터는 'ParameterKey' 및 'ParameterValue' 대신 'Key' 및 'Value'를 사용하여 지정할 수도 있습니다.**  

```
Update-CFNStack -StackName "myStack" `
                -TemplateBody "{Template Content Here}" `
                -Parameter @( @{ ParameterKey="PK1"; ParameterValue="PV1" }, @{ ParameterKey="PK2"; ParameterValue="PV2" } )
```
**예 3: 지정된 템플릿 및 사용자 지정 파라미터를 사용하여 'myStack' 스택을 업데이트합니다. 'PK1'은 템플릿에 선언된 파라미터의 이름을 나타내고 'PV2'는 해당 값을 나타냅니다. 사용자 지정 파라미터는 'ParameterKey' 및 'ParameterValue' 대신 'Key' 및 'Value'를 사용하여 지정할 수도 있습니다.**  

```
Update-CFNStack -StackName "myStack" -TemplateBody "{Template Content Here}" -Parameters @{ ParameterKey="PK1"; ParameterValue="PV1" }
```
**예 4: Amazon S3에서 가져온 지정된 템플릿 및 사용자 지정 파라미터를 사용하여 'myStack' 스택을 업데이트합니다. 'PK1' 및 'PK2'는 템플릿에 선언된 파라미터의 이름을 나타내고, 'PV1' 및 'PV2'는 요청된 값을 나타냅니다. 사용자 지정 파라미터는 'ParameterKey' 및 'ParameterValue' 대신 'Key' 및 'Value'를 사용하여 지정할 수도 있습니다.**  

```
Update-CFNStack -StackName "myStack" `
                -TemplateURL https://s3.amazonaws.com/amzn-s3-demo-bucket/templatefile.template `
                -Parameter @( @{ ParameterKey="PK1"; ParameterValue="PV1" }, @{ ParameterKey="PK2"; ParameterValue="PV2" } )
```
**예 5: Amazon S3에서 가져온 지정된 템플릿 및 사용자 지정 파라미터를 사용하여 이 예제에서 IAM 리소스를 포함하는 것으로 가정되는 'myStack' 스택을 업데이트합니다. 'PK1' 및 'PK2'는 템플릿에 선언된 파라미터의 이름을 나타내고, 'PV1' 및 'PV2'는 요청된 값을 나타냅니다. 사용자 지정 파라미터는 'ParameterKey' 및 'ParameterValue' 대신 'Key' 및 'Value'를 사용하여 지정할 수도 있습니다. IAM 리소스가 포함된 스택에서는 -Capabilities "CAPABILITY\$1IAM" 파라미터를 지정해야 합니다. 그렇지 않으면 업데이트가 실패하고 'InsufficientCapabilities' 오류가 발생합니다.**  

```
Update-CFNStack -StackName "myStack" `
                -TemplateURL https://s3.amazonaws.com/amzn-s3-demo-bucket/templatefile.template `
                -Parameter @( @{ ParameterKey="PK1"; ParameterValue="PV1" }, @{ ParameterKey="PK2"; ParameterValue="PV2" } ) `
                -Capabilities "CAPABILITY_IAM"
```
+  API 세부 정보는 *AWS Tools for PowerShell Cmdlet 참조(V4)*의 [UpdateStack](https://docs.aws.amazon.com/powershell/v4/reference)을 참조하세요.

**Tools for PowerShell V5**  
**예 1: 지정된 템플릿 및 사용자 지정 파라미터를 사용하여 'myStack' 스택을 업데이트합니다. 'PK1'은 템플릿에 선언된 파라미터의 이름을 나타내고 'PV1'은 해당 값을 나타냅니다. 사용자 지정 파라미터는 'ParameterKey' 및 'ParameterValue' 대신 'Key' 및 'Value'를 사용하여 지정할 수도 있습니다.**  

```
Update-CFNStack -StackName "myStack" `
                -TemplateBody "{Template Content Here}" `
                -Parameter @{ ParameterKey="PK1"; ParameterValue="PV1" }
```
**예 2: 지정된 템플릿 및 사용자 지정 파라미터를 사용하여 'myStack' 스택을 업데이트합니다. 'PK1' 및 'PK2'는 템플릿에 선언된 파라미터의 이름을 나타내고, 'PV1' 및 'PV2'는 요청된 값을 나타냅니다. 사용자 지정 파라미터는 'ParameterKey' 및 'ParameterValue' 대신 'Key' 및 'Value'를 사용하여 지정할 수도 있습니다.**  

```
Update-CFNStack -StackName "myStack" `
                -TemplateBody "{Template Content Here}" `
                -Parameter @( @{ ParameterKey="PK1"; ParameterValue="PV1" }, @{ ParameterKey="PK2"; ParameterValue="PV2" } )
```
**예 3: 지정된 템플릿 및 사용자 지정 파라미터를 사용하여 'myStack' 스택을 업데이트합니다. 'PK1'은 템플릿에 선언된 파라미터의 이름을 나타내고 'PV2'는 해당 값을 나타냅니다. 사용자 지정 파라미터는 'ParameterKey' 및 'ParameterValue' 대신 'Key' 및 'Value'를 사용하여 지정할 수도 있습니다.**  

```
Update-CFNStack -StackName "myStack" -TemplateBody "{Template Content Here}" -Parameters @{ ParameterKey="PK1"; ParameterValue="PV1" }
```
**예 4: Amazon S3에서 가져온 지정된 템플릿 및 사용자 지정 파라미터를 사용하여 'myStack' 스택을 업데이트합니다. 'PK1' 및 'PK2'는 템플릿에 선언된 파라미터의 이름을 나타내고, 'PV1' 및 'PV2'는 요청된 값을 나타냅니다. 사용자 지정 파라미터는 'ParameterKey' 및 'ParameterValue' 대신 'Key' 및 'Value'를 사용하여 지정할 수도 있습니다.**  

```
Update-CFNStack -StackName "myStack" `
                -TemplateURL https://s3.amazonaws.com/amzn-s3-demo-bucket/templatefile.template `
                -Parameter @( @{ ParameterKey="PK1"; ParameterValue="PV1" }, @{ ParameterKey="PK2"; ParameterValue="PV2" } )
```
**예 5: Amazon S3에서 가져온 지정된 템플릿 및 사용자 지정 파라미터를 사용하여 이 예제에서 IAM 리소스를 포함하는 것으로 가정되는 'myStack' 스택을 업데이트합니다. 'PK1' 및 'PK2'는 템플릿에 선언된 파라미터의 이름을 나타내고, 'PV1' 및 'PV2'는 요청된 값을 나타냅니다. 사용자 지정 파라미터는 'ParameterKey' 및 'ParameterValue' 대신 'Key' 및 'Value'를 사용하여 지정할 수도 있습니다. IAM 리소스가 포함된 스택에서는 -Capabilities "CAPABILITY\$1IAM" 파라미터를 지정해야 합니다. 그렇지 않으면 업데이트가 실패하고 'InsufficientCapabilities' 오류가 발생합니다.**  

```
Update-CFNStack -StackName "myStack" `
                -TemplateURL https://s3.amazonaws.com/amzn-s3-demo-bucket/templatefile.template `
                -Parameter @( @{ ParameterKey="PK1"; ParameterValue="PV1" }, @{ ParameterKey="PK2"; ParameterValue="PV2" } ) `
                -Capabilities "CAPABILITY_IAM"
```
+  API 세부 정보는 *AWS Tools for PowerShell Cmdlet 참조(V5)*의 [UpdateStack](https://docs.aws.amazon.com/powershell/v5/reference)을 참조하세요.

------

# CLI로 `ValidateTemplate` 사용
<a name="cloudformation_example_cloudformation_ValidateTemplate_section"></a>

다음 코드 예시는 `ValidateTemplate`의 사용 방법을 보여 줍니다.

------
#### [ CLI ]

**AWS CLI**  
** AWS CloudFormation 템플릿을 검증하려면**  
다음 `validate-template` 명령은 `sampletemplate.json` 템플릿의 유효성을 확인합니다.  

```
aws cloudformation validate-template --template-body file://sampletemplate.json
```
출력:  

```
{
    "Description": "AWS CloudFormation Sample Template S3_Bucket: Sample template showing how to create a publicly accessible S3 bucket. **WARNING** This template creates an S3 bucket. You will be billed for the AWS resources used if you create a stack from this template.",
    "Parameters": [],
    "Capabilities": []
}
```
자세한 내용은 AWS CloudFormation *AWS 사용 설명서의 CloudFormation *템플릿 작업을 참조하세요.  
+  API 세부 정보는 *AWS CLI 명령 참조*의 [ValidateTemplate](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/cloudformation/validate-template.html)을 참조하세요.

------
#### [ PowerShell ]

**Tools for PowerShell V4**  
**예 1: 지정된 템플릿 콘텐츠의 유효성을 확인합니다. 출력에는 템플릿의 기능, 설명 및 파라미터가 자세히 설명되어 있습니다.**  

```
Test-CFNTemplate -TemplateBody "{TEMPLATE CONTENT HERE}"
```
**예 2: Amazon S3 URL을 통해 액세스한 지정된 템플릿의 유효성을 확인합니다. 출력에는 템플릿의 기능, 설명 및 파라미터가 자세히 설명되어 있습니다.**  

```
Test-CFNTemplate -TemplateURL https://s3.amazonaws.com/amzn-s3-demo-bucket/templatefile.template
```
+  API 세부 정보는 *AWS Tools for PowerShell Cmdlet 참조(V4)*의 [ValidateTemplate](https://docs.aws.amazon.com/powershell/v4/reference)을 참조하세요.

**Tools for PowerShell V5**  
**예 1: 지정된 템플릿 콘텐츠의 유효성을 확인합니다. 출력에는 템플릿의 기능, 설명 및 파라미터가 자세히 설명되어 있습니다.**  

```
Test-CFNTemplate -TemplateBody "{TEMPLATE CONTENT HERE}"
```
**예 2: Amazon S3 URL을 통해 액세스한 지정된 템플릿의 유효성을 확인합니다. 출력에는 템플릿의 기능, 설명 및 파라미터가 자세히 설명되어 있습니다.**  

```
Test-CFNTemplate -TemplateURL https://s3.amazonaws.com/amzn-s3-demo-bucket/templatefile.template
```
+  API 세부 정보는 *AWS Tools for PowerShell Cmdlet 참조(V5)*의 [ValidateTemplate](https://docs.aws.amazon.com/powershell/v5/reference)을 참조하세요.

------