

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 使用基础设施编排器引用OpenAPI规范外部文件
<a name="using-composer-external-files-examples-example1"></a>

此示例使用控制台中的 Infrastructure Composer 来引用定义 API Gateway 的外部OpenAPI规范文件REST API。

首先，从基础设施编排器**主页**创建一个新项目。

**接下来，从**菜单**中选择 “**激活本地同步**”，激活本地同步。**创建一个名为的新文件夹`demo`，允许提示查看文件，然后选择 “**激活**”。出现提示时，选择**保存更改**。

![Infrastructure Composer Activate 本地同步窗口已选中演示项目文件夹，“激活” 按钮已准备就绪，可供选择。](http://docs.aws.amazon.com/zh_cn/infrastructure-composer/latest/dg/images/aac_use_ex_11.png)


接下来，将 Amazon API Gateway 卡片拖到画布上。选择**详细信息**以打开**资源属性**面板。

![画布上有一个 API Gateway 资源，资源属性面板处于打开状态。](http://docs.aws.amazon.com/zh_cn/infrastructure-composer/latest/dg/images/aac_use_ex_12.png)


在**资源属性**面板中，配置以下内容并**保存**。
+ 选择 “**使用外部文件进行 API 定义**” 选项。
+ 输入`./api-spec.yaml`作为**外部文件的相对路径**

![一个窗口，显示在 “使用外部文件进行 api 定义” 下标记的复选框以及定义的外部文件的相对路径。](http://docs.aws.amazon.com/zh_cn/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
```

在基础设施编排器**模板**视图中，您可以看到基础设施编排器已自动更新您的模板以引用外部文件。

![“基础设施编排器” 模板视图显示配置为引用外部文件的基础架构代码。](http://docs.aws.amazon.com/zh_cn/infrastructure-composer/latest/dg/images/aac_use_ex_07.png)
