

# CloudFormation 템플릿 Outputs 구문
<a name="outputs-section-structure"></a>

선택 사항인 `Outputs` 섹션은 스택의 출력 값을 선언합니다. 이러한 출력 값은 다양한 방식으로 사용할 수 있습니다.
+ **리소스 관련 중요한 세부 정보 수집** - 출력은 리소스 관련 중요 정보를 편리하게 수집할 수 있는 방법입니다. 예를 들면 스택의 S3 버킷 이름을 출력하면 버킷을 보다 쉽게 찾을 수 있습니다. CloudFormation 콘솔의 **출력** 탭이나 [describe-stacks](service_code_examples.md#describe-stacks-sdk) CLI 명령을 사용하여 출력 값을 볼 수 있습니다.
+ **교차 스택 참조** - 출력 값을 다른 스택으로 가져와서 [교차 스택 참조를 생성](using-cfn-stack-exports.md)할 수 있습니다. 이는 여러 스택에서 리소스 또는 구성을 공유해야 할 때 유용합니다.

**중요**  
CloudFormation은 `Outputs` 섹션에 포함한 정보를 삭제하거나 난독화하지 않습니다. 이 섹션을 사용하여 암호나 보안 암호와 같은 민감한 정보를 출력하지 않는 것이 좋습니다.  
출력값은 스택 작업이 완료된 후에 사용할 수 있습니다. 스택 상태가 `IN_PROGRESS` [상태](view-stack-events.md#cfn-console-view-stack-data-resources-status-codes) 중 하나일 때는 스택 출력 값을 사용할 수 없습니다. 출력값을 항상 사용할 수 있는 것은 아니므로 서비스 런타임과 스택 출력값 간에 종속성을 설정하지 않는 것이 좋습니다.

## 구문
<a name="outputs-section-syntax"></a>

`Outputs` 섹션은 키 이름 `Outputs`로 이루어집니다. 템플릿 안에 최대 60개 출력을 선언할 수 있습니다.

다음 예제에서는 `Outputs` 섹션의 구조를 보여줍니다.

### JSON
<a name="outputs-section-structure-syntax.json"></a>

모든 출력 선언을 괄호 안에 포함합니다. 출력이 여러 개인 경우 쉼표로 구분합니다.

```
"Outputs" : {
  "OutputLogicalID" : {
    "Description" : "Information about the value",
    "Value" : "Value to return",
    "Export" : {
      "Name" : "Name of resource to export"
    }
  }
}
```

### YAML
<a name="outputs-section-structure-syntax.yaml"></a>

```
Outputs:
  OutputLogicalID:
    Description: Information about the value
    Value: Value to return
    Export:
      Name: Name of resource to export
```

### 출력 필드
<a name="outputs-section-structure-output-fields"></a>

`Outputs` 섹션은 다음 필드를 포함할 수 있습니다.

**논리적 ID(**논리명이라고도 함)**  
현재 출력의 식별자입니다. 논리적 ID는 영숫자(`a–z`, `A–Z`, `0–9`)여야 하며 템플릿 내에서 고유해야 합니다.

**`Description` (선택 사항)**  
출력값을 설명하는 `String` 유형입니다. 설명 선언 값은 0\$11023바이트 길이의 리터럴 문자열이어야 합니다. 파라미터나 함수를 사용하여 설명을 지정할 수 없습니다.

**`Value`(필수)**  
[describe-stacks](service_code_examples.md#describe-stacks-sdk) 명령에 의해 반환되는 속성의 값입니다. 출력의 값에는 리터럴, 파라미터 참조, 가상 파라미터, 매핑 값 또는 내장 함수가 포함될 수 있습니다.

**`Export` (선택 사항)**  
교차 스택 참조를 위해 내보낼 리소스 출력의 이름입니다.  
내장 함수를 사용하여 내보내기의 `Name` 값을 사용자 지정할 수 있습니다.  
자세한 내용은 [배포된 CloudFormation 스택에서 내보낸 출력 가져오기](using-cfn-stack-exports.md) 섹션을 참조하세요.

출력과 조건을 연결하려면 템플릿의 [Conditions](conditions-section-structure.md) 섹션에 조건을 정의합니다.

## 예제
<a name="outputs-section-structure-examples"></a>

다음 예제에서는 스택 출력의 작동 방식을 보여줍니다.

**Topics**
+ [스택 출력](#outputs-section-structure-examples-stack-output)
+ [`Fn::Sub`를 사용하여 내보내기 이름 사용자 지정](#outputs-section-structure-examples-cross-stack)
+ [`Fn::Join`를 사용하여 내보내기 이름 사용자 지정](#outputs-section-structure-examples-join-export-name)
+ [`Fn::Join`을 사용하여 구성된 URL 반환](#outputs-section-structure-examples-join-export-url)

### 스택 출력
<a name="outputs-section-structure-examples-stack-output"></a>

다음 예제에서는 `BackupLoadBalancerDNSName` 이름의 출력이 `BackupLoadBalancer` 조건이 true일 때만 논리적 ID가 `CreateProdResources`인 리소스의 DNS 이름을 반환합니다. 이름이 `InstanceID`인 출력은 논리적 ID `EC2Instance`와 함께 EC2 인스턴스의 ID를 반환합니다.

#### JSON
<a name="outputs-section-structure-example.json"></a>

```
"Outputs" : {
  "BackupLoadBalancerDNSName" : {
    "Description": "The DNSName of the backup load balancer",  
    "Value" : { "Fn::GetAtt" : [ "BackupLoadBalancer", "DNSName" ]},
    "Condition" : "CreateProdResources"
  },
  "InstanceID" : {
    "Description": "The Instance ID",  
    "Value" : { "Ref" : "EC2Instance" }
  }
}
```

#### YAML
<a name="outputs-section-structure-example.yaml"></a>

```
Outputs:
  BackupLoadBalancerDNSName:
    Description: The DNSName of the backup load balancer
    Value: !GetAtt BackupLoadBalancer.DNSName
    Condition: CreateProdResources
  InstanceID:
    Description: The Instance ID
    Value: !Ref EC2Instance
```

### `Fn::Sub`를 사용하여 내보내기 이름 사용자 지정
<a name="outputs-section-structure-examples-cross-stack"></a>

다음 예제에서는 `StackVPC`는 VPC의 ID를 반환하고 나서, 스택 이름에 추가된 `VPCID` 이름을 사용하여 교차 스택 참조 값을 내보냅니다.

#### JSON
<a name="outputs-section-structure-cross-stack-example.json"></a>

```
"Outputs" : {
  "StackVPC" : {
    "Description" : "The ID of the VPC",
    "Value" : { "Ref" : "MyVPC" },
    "Export" : {
      "Name" : {"Fn::Sub": "${AWS::StackName}-VPCID" }
    }
  }
}
```

#### YAML
<a name="outputs-section-structure-cross-stack-example.yaml"></a>

```
Outputs:
  StackVPC:
    Description: The ID of the VPC
    Value: !Ref MyVPC
    Export:
      Name: !Sub "${AWS::StackName}-VPCID"
```

`Fn::Sub` 함수에 대한 자세한 내용은 [https://docs.aws.amazon.com/AWSCloudFormation/latest/TemplateReference/intrinsic-function-reference-sub.html](https://docs.aws.amazon.com/AWSCloudFormation/latest/TemplateReference/intrinsic-function-reference-sub.html) 단원을 참조하십시오.

### `Fn::Join`를 사용하여 내보내기 이름 사용자 지정
<a name="outputs-section-structure-examples-join-export-name"></a>

또한 `Fn::Join` 함수를 사용하여 파라미터, 리소스 속성 및 기타 문자열을 기반으로 값을 구성할 수 있습니다.

다음 예제에서는 `Fn::Sub` 함수 대신 `Fn::Join` 함수를 사용하여 내보내기 이름을 사용자 지정합니다. 예제 `Fn::Join` 함수는 콜론을 구분자로 사용하여 스택 이름과 이름 `VPCID`를 연결합니다.

#### JSON
<a name="outputs-section-structure-join-export-name-example.json"></a>

```
"Outputs" : {
  "StackVPC" : {
    "Description" : "The ID of the VPC",
    "Value" : { "Ref" : "MyVPC" },
    "Export" : {
      "Name" : { "Fn::Join" : [ ":", [ { "Ref" : "AWS::StackName" }, "VPCID" ] ] }
    }
  }
}
```

#### YAML
<a name="outputs-section-structure-join-export-name-example.yaml"></a>

```
Outputs:
  StackVPC:
    Description: The ID of the VPC
    Value: !Ref MyVPC
    Export:
      Name: !Join [ ":", [ !Ref "AWS::StackName", VPCID ] ]
```

`Fn::Join` 함수에 대한 자세한 내용은 [https://docs.aws.amazon.com/AWSCloudFormation/latest/TemplateReference/intrinsic-function-reference-join.html](https://docs.aws.amazon.com/AWSCloudFormation/latest/TemplateReference/intrinsic-function-reference-join.html) 단원을 참조하십시오.

### `Fn::Join`을 사용하여 구성된 URL 반환
<a name="outputs-section-structure-examples-join-export-url"></a>

WordPress 사이트를 생성하는 템플릿에 대한 이전 예제에서 `InstallURL`은 `Fn::Join` 함수 호출에서 반환된 문자열로, `http://`, 리소스 `ElasticLoadBalancer`의 DNS 이름, `/wp-admin/install.php`를 연결합니다. 출력 값은 다음과 비슷합니다.

```
http://mywptests-elasticl-1gb51l6sl8y5v-206169572.aws-region.elb.amazonaws.com/wp-admin/install.php
```

#### JSON
<a name="outputs-section-structure-examples-join-export-url.json"></a>

```
{
    "Outputs": {
        "InstallURL": {
            "Value": {
                "Fn::Join": [
                    "",
                    [
                        "http://",
                        {
                            "Fn::GetAtt": [
                                "ElasticLoadBalancer",
                                "DNSName"
                            ]
                        },
                        "/wp-admin/install.php"
                    ]
                ]
            },
            "Description": "Installation URL of the WordPress website"
        }
    }
}
```

#### YAML
<a name="outputs-section-structure-examples-join-export-url.yaml"></a>

```
Outputs:
  InstallURL:
    Value: !Join 
      - ''
      - - 'http://'
        - !GetAtt 
          - ElasticLoadBalancer
          - DNSName
        - /wp-admin/install.php
    Description: Installation URL of the WordPress website
```

`Fn::Join` 함수에 대한 자세한 내용은 [https://docs.aws.amazon.com/AWSCloudFormation/latest/TemplateReference/intrinsic-function-reference-join.html](https://docs.aws.amazon.com/AWSCloudFormation/latest/TemplateReference/intrinsic-function-reference-join.html) 단원을 참조하십시오.