

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 使用 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/zh_tw/infrastructure-composer/latest/dg/images/aac_use_ex_11.png)


接著，將 Amazon API Gateway 卡拖曳到畫布上。選取**詳細資訊**以顯示**資源屬性**面板。

![畫布上的 API Gateway 資源，並開啟資源屬性面板。](http://docs.aws.amazon.com/zh_tw/infrastructure-composer/latest/dg/images/aac_use_ex_12.png)


從**資源屬性**面板中，設定下列項目並**儲存**。
+ 選取**使用外部檔案進行 api 定義**選項。
+ 輸入 `./api-spec.yaml`做為**外部檔案的相對路徑**

![視窗顯示標記在使用外部檔案進行 api 定義下的核取方塊，以及定義外部檔案的相對路徑。](http://docs.aws.amazon.com/zh_tw/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/zh_tw/infrastructure-composer/latest/dg/images/aac_use_ex_07.png)
