

# 가져오기 작업 되돌리기
<a name="resource-import-revert"></a>

가져오기 작업을 되돌리려면 템플릿에서 제거할 리소스에 대한 `Retain` 삭제 정책을 지정하여 스택에서 삭제할 때 해당 리소스가 보존되도록 합니다.

## AWS Management Console을 사용하여 가져오기 작업 되돌리기
<a name="resource-import-revert-console"></a>

1. 스택에서 제거할 리소스에 대한 `Retain` [DeletionPolicy](https://docs.aws.amazon.com/AWSCloudFormation/latest/TemplateReference/aws-attribute-deletionpolicy.html)를 지정합니다. 다음 예제 템플릿에서 `GamesTable`는 이러한 되돌리기 작업의 대상입니다.  
**Example JSON**  

   ```
   {
       "AWSTemplateFormatVersion": "2010-09-09",
       "Description": "Import test",
       "Resources": {
           "ServiceTable":{
              "Type":"AWS::DynamoDB::Table",
              "Properties":{
                 "TableName":"Service",
                 "AttributeDefinitions":[
                    {
                       "AttributeName":"key",
                       "AttributeType":"S"
                    }
                 ],
                 "KeySchema":[
                    {
                       "AttributeName":"key",
                       "KeyType":"HASH"
                    }
                 ],
                 "ProvisionedThroughput":{
                    "ReadCapacityUnits":5,
                    "WriteCapacityUnits":1
                 }
              }
           },
           "GamesTable": {
               "Type": "AWS::DynamoDB::Table",
               "DeletionPolicy": "Retain",
               "Properties": {
                   "TableName": "Games",
                   "AttributeDefinitions": [
                       {
                           "AttributeName": "key",
                           "AttributeType": "S"
                       }
                   ],
                   "KeySchema": [
                       {
                           "AttributeName": "key",
                           "KeyType": "HASH"
                       }
                   ],
                   "ProvisionedThroughput": {
                       "ReadCapacityUnits": 5,
                       "WriteCapacityUnits": 1
                   }
               }
           }
       }
   }
   ```

1. CloudFormation 콘솔을 열어 스택 업데이트를 수행하여 삭제 정책을 적용합니다.

   1. **스택** 페이지에서 스택을 선택한 상태에서 **업데이트**를 선택한 다음, **Update stack(standard)(스택 업데이트(표준))**를 선택합니다.

   1. **Prepare template(템플릿 준비)**에서 **Replace current template(현재 템플릿 바꾸기)**을 선택합니다.

   1. **Specify template(템플릿 지정)**에서 `GamesTable`에 `DeletionPolicy` 속성이 설정된 업데이트된 소스 템플릿을 제공한 후, **다음**을 선택합니다.
      + **Amazon S3 URL**을 선택한 다음 텍스트 상자에 업데이트된 소스 템플릿의 URL을 지정합니다.
      + **템플릿 파일 업로드**를 선택한 다음 업데이트된 소스 템플릿 파일을 찾습니다.

   1. **Specify stack details(스택 세부 정보 지정)** 페이지에서 어떤 변경도 필요하지 않습니다. **다음**을 선택합니다.

   1. **Configure stack options(스택 옵션 구성)** 페이지에서 어떤 변경도 필요하지 않습니다. **다음**을 선택합니다.

   1. ***MyStack* 검토** 페이지에서 변경 사항을 검토합니다. 템플릿에 IAM 리소스가 포함되어 있는 경우 **이 템플릿이 IAM 리소스를 생성할 수 있음을 확인합니다**(I acknowledge that this template may create IAM resources)를 선택하여 템플릿에서 IAM 리소스를 사용하도록 지정합니다. 자세한 내용은 [CloudFormation 템플릿에서 IAM 리소스 승인](control-access-with-iam.md#using-iam-capabilities) 섹션을 참조하세요. 그런 다음 변경 세트를 생성하여 소스 스택을 업데이트하거나 소스 스택을 직접 업데이트하십시오.

1. 스택 템플릿에서 리소스, 관련 파라미터 및 출력을 제거합니다. 이 예제에서는 이제 소스 템플릿이 다음과 같이 보입니다.  
**Example JSON**  

   ```
   {
       "AWSTemplateFormatVersion": "2010-09-09",
       "Description": "Import test",
       "Resources": {
           "ServiceTable":{
              "Type":"AWS::DynamoDB::Table",
              "Properties":{
                 "TableName":"Service",
                 "AttributeDefinitions":[
                    {
                       "AttributeName":"key",
                       "AttributeType":"S"
                    }
                 ],
                 "KeySchema":[
                    {
                       "AttributeName":"key",
                       "KeyType":"HASH"
                    }
                 ],
                 "ProvisionedThroughput":{
                    "ReadCapacityUnits":5,
                    "WriteCapacityUnits":1
                 }
              }
           }
       }
   }
   ```

1. 2단계를 반복하여 리소스(`GamesTable`)와 관련 파라미터 및 출력을 스택에서 삭제합니다.

## AWS CLI을 사용하여 가져오기 작업 되돌리기
<a name="resource-import-revert-cli"></a>

1. 스택에서 제거할 리소스에 대한 `Retain` [DeletionPolicy](https://docs.aws.amazon.com/AWSCloudFormation/latest/TemplateReference/aws-attribute-deletionpolicy.html)를 지정합니다. 다음 예제 템플릿에서 `GamesTable`는 이러한 되돌리기 작업의 대상입니다.  
**Example JSON**  

   ```
   {
       "AWSTemplateFormatVersion": "2010-09-09",
       "Description": "Import test",
       "Resources": {
           "ServiceTable":{
              "Type":"AWS::DynamoDB::Table",
              "Properties":{
                 "TableName":"Service",
                 "AttributeDefinitions":[
                    {
                       "AttributeName":"key",
                       "AttributeType":"S"
                    }
                 ],
                 "KeySchema":[
                    {
                       "AttributeName":"key",
                       "KeyType":"HASH"
                    }
                 ],
                 "ProvisionedThroughput":{
                    "ReadCapacityUnits":5,
                    "WriteCapacityUnits":1
                 }
              }
           },
           "GamesTable": {
               "Type": "AWS::DynamoDB::Table",
               "DeletionPolicy": "Retain",
               "Properties": {
                   "TableName": "Games",
                   "AttributeDefinitions": [
                       {
                           "AttributeName": "key",
                           "AttributeType": "S"
                       }
                   ],
                   "KeySchema": [
                       {
                           "AttributeName": "key",
                           "KeyType": "HASH"
                       }
                   ],
                   "ProvisionedThroughput": {
                       "ReadCapacityUnits": 5,
                       "WriteCapacityUnits": 1
                   }
               }
           }
       }
   }
   ```

1. 스택을 업데이트하여 삭제 정책을 리소스에 적용합니다.

   ```
   aws cloudformation update-stack --stack-name MyStack
   ```

1. 스택 템플릿에서 리소스, 관련 파라미터 및 출력을 제거합니다. 이 예제에서는 이제 소스 템플릿이 다음과 같이 보입니다.  
**Example JSON**  

   ```
   {
       "AWSTemplateFormatVersion": "2010-09-09",
       "Description": "Import test",
       "Resources": {
           "ServiceTable":{
              "Type":"AWS::DynamoDB::Table",
              "Properties":{
                 "TableName":"Service",
                 "AttributeDefinitions":[
                    {
                       "AttributeName":"key",
                       "AttributeType":"S"
                    }
                 ],
                 "KeySchema":[
                    {
                       "AttributeName":"key",
                       "KeyType":"HASH"
                    }
                 ],
                 "ProvisionedThroughput":{
                    "ReadCapacityUnits":5,
                    "WriteCapacityUnits":1
                 }
              }
           }
       }
   }
   ```

1. 스택을 업데이트하여 리소스(`GamesTable`)와 관련 파라미터 및 출력을 스택에서 삭제합니다.

   ```
   aws cloudformation update-stack --stack-name MyStack
   ```