

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

# Infrastructure Composer에서 외부 파일 참조
<a name="using-composer-external-files"></a>

외부 파일을 AWS Serverless Application Model (AWS SAM) 템플릿과 함께 사용하여 반복된 코드를 재사용하고 프로젝트를 구성할 수 있습니다. 예를 들어 OpenAPI 사양에 설명된 Amazon API Gateway REST API 리소스가 여러 개 있을 수 있습니다. 템플릿에서 OpenAPI 사양 코드를 복제하는 대신 하나의 외부 파일을 생성하고 각 리소스에 대해 참조할 수 있습니다.

AWS Infrastructure Composer 는 다음과 같은 외부 파일 사용 사례를 지원합니다.
+ 외부 OpenAPI 사양 파일에서 정의한 API Gateway REST API 리소스입니다.
+ AWS Step Functions 외부 상태 시스템 정의 파일로 정의된 상태 시스템 리소스입니다.

지원되는 리소스에 대한 외부 파일 구성에 대한 자세한 내용은 다음을 참조하세요.
+ `[ DefinitionBody](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-resource-api.html#sam-api-definitionbody)`(`AWS::Serverless::Api`일 때)
+ `[ DefinitionUri](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-resource-statemachine.html#sam-statemachine-definitionuri)`(`AWS::Serverless::StateMachine`일 때)

**참고**  
Infrastructure Composer 콘솔에서 Infrastructure Composer를 사용하여 외부 파일을 참조하려면 **로컬 동기화** 모드에서 Infrastructure Composer를 사용해야 합니다. 자세한 내용은 [Infrastructure Composer 콘솔에서 프로젝트를 로컬로 동기화하고 저장](using-composer-project-local-sync.md) 단원을 참조하십시오.

**Topics**
+ [Infrastructure Composer 외부 참조 파일의 모범 사례](using-composer-external-files-best-practices.md)
+ [Infrastructure Composer에서 외부 파일 참조 생성](using-composer-external-files-new.md)
+ [Infrastructure Composer에서 외부 파일 참조가 있는 프로젝트 로드](using-composer-external-files-load.md)
+ [Infrastructure Composer에서 외부 파일을 참조하는 애플리케이션 생성](using-composer-external-files-examples-example3.md)
+ [Infrastructure Composer를 사용하여 OpenAPI 사양 외부 파일 참조](using-composer-external-files-examples-example1.md)

# Infrastructure Composer 외부 참조 파일의 모범 사례
<a name="using-composer-external-files-best-practices"></a>

## 로컬 IDE에서 Infrastructure Composer 사용
<a name="using-composer-external-files-best-practices-ide"></a>

로컬 **동기화 모드에서 로컬** IDE와 함께 Infrastructure Composer를 사용하는 경우 로컬 IDE를 사용하여 외부 파일을 보고 수정할 수 있습니다. 템플릿에서 참조되는 지원되는 외부 파일의 콘텐츠는 Infrastructure Composer 캔버스에서 자동으로 업데이트됩니다. 자세한 내용은 [Infrastructure Composer 콘솔을 로컬 IDE에 연결](other-services-ide.md)를 참조하세요.

## 프로젝트의 상위 디렉터리 내에 외부 파일 유지
<a name="using-composer-external-files-best-practices-directory"></a>

프로젝트의 상위 디렉터리 내에 하위 디렉터리를 생성하여 외부 파일을 구성할 수 있습니다. Infrastructure Composer는 프로젝트의 상위 디렉터리 외부의 디렉터리에 저장된 외부 파일에 액세스할 수 없습니다.

## 를 사용하여 애플리케이션 배포 AWS SAM CLI
<a name="using-composer-external-files-best-practices-sam"></a>

애플리케이션을에 배포할 때 AWS 클라우드로컬 외부 파일을 먼저 Amazon Simple Storage Service(Amazon S3)와 같은 액세스 가능한 위치에 업로드해야 합니다. AWS SAM CLI를 사용하여이 프로세스를 자동으로 촉진할 수 있습니다. 자세한 내용은 *AWS Serverless Application Model 개발자 안내서*의 [ 배포 시 로컬 파일 업로드](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/deploy-upload-local-files.html)를 참조하세요.

# Infrastructure Composer에서 외부 파일 참조 생성
<a name="using-composer-external-files-new"></a>

지원되는 **리소스의 리소스 속성** 패널에서 외부 파일 참조를 생성할 수 있습니다.

**외부 파일 참조를 생성하려면**

1. **API Gateway** 또는 **Step Functions** 향상된 구성 요소 카드에서 **세부 정보를** 선택하여 **리소스 속성 ** 패널을 불러옵니다.

1. **외부 파일 사용** 옵션을 찾아 선택합니다.

1. 외부 파일의 상대 경로를 지정합니다. 파일에서 외부 `template.yaml` 파일까지의 경로입니다.

   예를 들어 다음 프로젝트의 구조에서 `api-spec.yaml` 외부 파일을 참조하려면를 상대 경로`./api-spec.yaml`로 지정합니다.

   ```
   demo
   ├── api-spec.yaml
   ├── src
   │ └── Function
   │ ├── index.js
   │ └── package.json
   └── template.yaml
   ```
**참고**  
외부 파일과 지정된 경로가 없는 경우 Infrastructure Composer에서 생성합니다.

1. 변경 사항을 **저장합니다**.

# Infrastructure Composer에서 외부 파일 참조가 있는 프로젝트 로드
<a name="using-composer-external-files-load"></a>

이 페이지에 나열된 단계에 따라 외부 파일 참조가 있는 Infrastructure Composer 프로젝트를 로드합니다.

**Infrastructure Composer 콘솔에서**

1. 에 나열된 단계를 완료합니다[Infrastructure Composer 콘솔에서 기존 프로젝트 템플릿 가져오기](using-composer-project-import-template.md).

1. Infrastructure Composer가 프로젝트의 루트 폴더에 연결하라는 메시지를 표시하는지 확인합니다.

브라우저가 파일 시스템 액세스 API를 지원하는 경우 Infrastructure Composer는 프로젝트의 루트 폴더에 연결하라는 메시지를 표시합니다. Infrastructure Composer는 프로젝트를 **로컬 동기화** 모드로 열어 외부 파일을 지원합니다. 참조된 외부 파일이 지원되지 않는 경우 오류 메시지가 표시됩니다. 오류 메시지에 대한 자세한 내용은 섹션을 참조하세요[문제 해결](ref-troubleshooting.md).

**Toolkit for VS Code에서**

1. 에 나열된 단계를 완료합니다[에서 Infrastructure Composer에 액세스 AWS Toolkit for Visual Studio Code](setting-up-composer-access-ide.md).

1. Infrastructure Composer에서 보려는 템플릿을 엽니다.

템플릿에서 Infrastructure Composer에 액세스하면 Infrastructure Composer가 외부 파일을 자동으로 감지합니다. 참조된 외부 파일이 지원되지 않는 경우 오류 메시지가 표시됩니다. 오류 메시지에 대한 자세한 내용은 섹션을 참조하세요[문제 해결](ref-troubleshooting.md).

# Infrastructure Composer에서 외부 파일을 참조하는 애플리케이션 생성
<a name="using-composer-external-files-examples-example3"></a>

이 예제에서는를 AWS SAM CLI 사용하여 상태 시스템 정의에 대한 외부 파일을 참조하는 애플리케이션을 생성합니다. 그런 다음 외부 파일을 올바르게 참조하여 Infrastructure Composer에 프로젝트를 로드합니다.

**예제**

1. 먼저 AWS SAM CLI **sam init** 명령을 사용하여 라는 새 애플리케이션을 초기화합니다`demo`. 대화형 흐름 중에 **다단계 워크플로** 빠른 시작 템플릿을 선택합니다.

   ```
   $ sam init
   
   ...
   
   Which template source would you like to use?
           1 - AWS Quick Start Templates
           2 - Custom Template Location
   Choice: 1
   
   Choose an AWS Quick Start application template
           1 - Hello World Example
           2 - Multi-step workflow
           3 - Serverless API
           4 - Scheduled task
           ...
   Template: 2
   
   Which runtime would you like to use?
           1 - dotnet6
           2 - dotnetcore3.1
           ...
           15 - python3.7
           16 - python3.10
           17 - ruby2.7
   Runtime: 16
   
   Based on your selections, the only Package type available is Zip.
   We will proceed to selecting the Package type as Zip.
   
   Based on your selections, the only dependency manager available is pip.
   We will proceed copying the template using pip.
   
   Would you like to enable X-Ray tracing on the function(s) in your application?  [y/N]: ENTER
   
   Would you like to enable monitoring using CloudWatch Application Insights?
   For more info, please view https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/cloudwatch-application-insights.html [y/N]: ENTER
   
   Project name [sam-app]: demo
   
       -----------------------
       Generating application:
       -----------------------
       Name: demo
       Runtime: python3.10
       Architectures: x86_64
       Dependency Manager: pip
       Application Template: step-functions-sample-app
       Output Directory: .
       Configuration file: demo/samconfig.toml
       
       Next steps can be found in the README file at demo/README.md
   
   ...
   ```

   이 애플리케이션은 상태 시스템 정의에 대한 외부 파일을 참조합니다.

   ```
   ...
   Resources:
     StockTradingStateMachine:
       Type: AWS::Serverless::StateMachine
       Properties:
         DefinitionUri: statemachine/stock_trader.asl.json
   ...
   ```

   외부 파일은 애플리케이션의 `statemachine` 하위 디렉터리에 있습니다.

   ```
   demo
   ├── README.md
   ├── __init__.py
   ├── functions
   │   ├── __init__.py
   │   ├── stock_buyer
   │   ├── stock_checker
   │   └── stock_seller
   ├── samconfig.toml
   ├── statemachine
   │   └── stock_trader.asl.json
   ├── template.yaml
   └── tests
   ```

1. 그런 다음 콘솔에서 Infrastructure Composer에 애플리케이션을 로드합니다. Infrastructure Composer **홈** 페이지에서 ** CloudFormation 템플릿 로드를** 선택합니다.

1. `demo` 프로젝트 폴더를 선택하고 프롬프트가 파일을 볼 수 있도록 허용합니다. `template.yaml` 파일을 선택하고 **생성을** 선택합니다. 메시지가 표시되면 **변경 사항 저장**을 선택합니다.  
![\[프로젝트 폴더가 선택된 Infrastructure Composer 프로젝트 폴더 열기 창과 선택할 준비가 된 생성.\]](http://docs.aws.amazon.com/ko_kr/infrastructure-composer/latest/dg/images/aac_use_ex_15.png)

Infrastructure Composer는 외부 상태 시스템 정의 파일을 자동으로 감지하여 로드합니다. **StockTradingStateMachine** 리소스를 선택하고 **세부 정보를** 선택하여 **리소스 속성** 패널을 표시합니다. 여기서 Infrastructure Composer가 외부 상태 시스템 정의 파일에 자동으로 연결되었음을 확인할 수 있습니다.

![\[API Gateway 리소스 속성 패널이 표시된 Infrastructure Composer 캔버스 보기에는 외부 참조 파일의 구성이 표시됩니다.\]](http://docs.aws.amazon.com/ko_kr/infrastructure-composer/latest/dg/images/aac_use_ex_03.png)


상태 시스템 정의 파일에 대한 모든 변경 사항은 Infrastructure Composer에 자동으로 반영됩니다.

# Infrastructure Composer를 사용하여 OpenAPI 사양 외부 파일 참조
<a name="using-composer-external-files-examples-example1"></a>

이 예제에서는 콘솔의 Infrastructure Composer를 사용하여 API Gateway를 정의하는 외부 OpenAPI 사양 파일을 참조합니다REST API.

먼저 Infrastructure Composer **홈** 페이지에서 새 프로젝트를 생성합니다.

그런 다음 **메뉴에서** **로컬 동기화** 활성화를 선택하여 **로컬 동기화를 활성화합니다**. 라는 새 폴더를 생성하고 `demo`프롬프트가 파일을 볼 수 있도록 허용한 다음 **활성화를** 선택합니다. 메시지가 표시되면 **변경 사항 저장**을 선택합니다.

![\[데모 프로젝트 폴더가 선택된 상태에서 Infrastructure Composer 로컬 동기화 활성화 창과 활성화 버튼을 선택할 준비가 되었습니다.\]](http://docs.aws.amazon.com/ko_kr/infrastructure-composer/latest/dg/images/aac_use_ex_11.png)


그런 다음 Amazon API Gateway 카드를 캔버스로 드래그합니다. **세부 정보를** 선택하여 **리소스 속성** 패널을 불러옵니다.

![\[리소스 속성 패널이 열려 있는 캔버스의 API Gateway 리소스입니다.\]](http://docs.aws.amazon.com/ko_kr/infrastructure-composer/latest/dg/images/aac_use_ex_12.png)


**리소스 속성** 패널에서 다음을 구성하고 **저장합니다**.
+ **API 정의에 외부 파일 사용** 옵션을 선택합니다.
+ **외부 파일의 상대 경로**`./api-spec.yaml`로 입력

![\[API 정의에 외부 파일 사용 아래에 표시된 확인란과 정의된 외부 파일의 상대 경로를 보여주는 창입니다.\]](http://docs.aws.amazon.com/ko_kr/infrastructure-composer/latest/dg/images/aac_use_ex_13.png)


이렇게 하면 로컬 시스템에 다음 디렉터리가 생성됩니다.

```
demo
└── api-spec.yaml
```

이제 로컬 시스템에서 외부 파일을 구성할 수 있습니다. IDE를 사용하여 프로젝트 폴더에 `api-spec.yaml` 있는를 엽니다. 내용을 다음과 같이 바꿉니다.

```
openapi: '3.0'
info: {}
paths:
  /:
    get:
      responses: {}
    post:
      x-amazon-apigateway-integration:
        credentials:
          Fn::GetAtt:
            - ApiQueuesendmessageRole
            - Arn
        httpMethod: POST
        type: aws
        uri:
          Fn::Sub: arn:${AWS::Partition}:apigateway:${AWS::Region}:sqs:path/${AWS::AccountId}/${Queue.QueueName}
        requestParameters:
          integration.request.header.Content-Type: '''application/x-www-form-urlencoded'''
        requestTemplates:
          application/json: Action=SendMessage&MessageBody={"data":$input.body}
        responses:
          default:
            statusCode: 200
      responses:
        '200':
          description: 200 response
```

Infrastructure Composer **템플릿** 보기에서 Infrastructure Composer가 외부 파일을 참조하도록 템플릿을 자동으로 업데이트했음을 확인할 수 있습니다.

![\[외부 파일을 참조하도록 구성된 인프라 코드를 보여주는 Infrastructure Composer 템플릿 보기입니다.\]](http://docs.aws.amazon.com/ko_kr/infrastructure-composer/latest/dg/images/aac_use_ex_07.png)
