

# 如何解决 AWS::ApiGateway::RestAPI 资源中的只写属性问题
<a name="generate-IaC-apigateway-restapi"></a>

本主题介绍如何解决在使用 IaC 生成器时的 [https://docs.aws.amazon.com/AWSCloudFormation/latest/TemplateReference/aws-resource-apigateway-restapi.html](https://docs.aws.amazon.com/AWSCloudFormation/latest/TemplateReference/aws-resource-apigateway-restapi.html) 资源只写属性问题。

## 问题
<a name="apigateway-restapi-write-only-properties-issue"></a>

当生成的模板包含 `AWS::ApiGateway::RestApi` 资源时，会生成警告，指明 `Body`、`BodyS3Location` 和 `CloneFrom` 属性将标识为 `UNSUPPORTED_PROPERTIES`。这是因为这些是可选的只写属性。IaC 生成器不知道这些属性是否曾应用于资源，因此生成的模板中会忽略这些属性。

## 解决方案
<a name="apigateway-restapi-write-only-properties-resolution"></a>

要为您的 REST API 设置 `Body` 属性，请更新生成的模板。

1. 使用 Amazon API Gateway [https://docs.aws.amazon.com/apigateway/latest/api/API_GetExport.html](https://docs.aws.amazon.com/apigateway/latest/api/API_GetExport.html) API 操作下载 API。例如，通过使用 [https://docs.aws.amazon.com/cli/latest/reference/apigateway/get-export.html](https://docs.aws.amazon.com/cli/latest/reference/apigateway/get-export.html) AWS CLI 命令。有关更多信息，请参阅《API Gateway 开发人员指南》**中的[从 API Gateway 导出 REST API](https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-export-api.html)。

1. 从 `GetExport` API 操作的响应中检索 `Body` 属性。将其上传到 Amazon S3 存储桶。

1. 下载生成的模板。

1. 将 `BodyS3Location/Bucket` 和 `BodyS3Location/Key` 属性添加到模板中，指定存储 `Body` 的桶名称和密钥。

1. 在 IaC 生成器控制台中打开生成的模板，然后选择**导入编辑的模板**。