

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

# HttpApiCorsConfiguration
<a name="sam-property-httpapi-httpapicorsconfiguration"></a>

管理您的 HTTP 的跨源资源共享 (CORS)。 APIs使用字符串指定允许使用的域，或使用其他 Cors 配置指定词典。注意：Cors 要求 SAM 修改你的 OpenAPI 定义，因此它仅适用于属性中`DefinitionBody`定义的 OpenApi 内联定义。

有关 CORS 的更多信息，请参阅*《API Gateway 开发人员指南》*中的[为 HTTP API 配置 CORS](https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-cors.html)。

注意：如果 HttpApiCorsConfiguration 在 OpenAPI 和属性级别同时设置，则会将它们 AWS SAM 合并，且属性优先。

## 语法
<a name="sam-property-httpapi-httpapicorsconfiguration-syntax"></a>

要在 AWS Serverless Application Model (AWS SAM) 模板中声明此实体，请使用以下语法。

### YAML
<a name="sam-property-httpapi-httpapicorsconfiguration-syntax.yaml"></a>

```
  [AllowCredentials](#sam-httpapi-httpapicorsconfiguration-allowcredentials): Boolean
  [AllowHeaders](#sam-httpapi-httpapicorsconfiguration-allowheaders): List
  [AllowMethods](#sam-httpapi-httpapicorsconfiguration-allowmethods): List
  [AllowOrigins](#sam-httpapi-httpapicorsconfiguration-alloworigins): List
  [ExposeHeaders](#sam-httpapi-httpapicorsconfiguration-exposeheaders): List
  [MaxAge](#sam-httpapi-httpapicorsconfiguration-maxage): Integer
```

## Properties
<a name="sam-property-httpapi-httpapicorsconfiguration-properties"></a>

 `AllowCredentials`   <a name="sam-httpapi-httpapicorsconfiguration-allowcredentials"></a>
指定是否在 CORS 请求中包含凭证。  
*类型*：布尔值  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `AllowHeaders`   <a name="sam-httpapi-httpapicorsconfiguration-allowheaders"></a>
表示允许的标头集合。  
*类型*：列表  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `AllowMethods`   <a name="sam-httpapi-httpapicorsconfiguration-allowmethods"></a>
表示允许的 HTTP 方法集合。  
*类型*：列表  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `AllowOrigins`   <a name="sam-httpapi-httpapicorsconfiguration-alloworigins"></a>
表示允许的源集合。  
*类型*：列表  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `ExposeHeaders`   <a name="sam-httpapi-httpapicorsconfiguration-exposeheaders"></a>
表示公开的标头集合。  
*类型*：列表  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `MaxAge`   <a name="sam-httpapi-httpapicorsconfiguration-maxage"></a>
浏览器应缓存预检请求结果的秒数。  
*类型*：整数  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

## 示例
<a name="sam-property-httpapi-httpapicorsconfiguration--examples"></a>

### HttpApiCorsConfiguration
<a name="sam-property-httpapi-httpapicorsconfiguration--examples--httpapicorsconfiguration"></a>

HTTP API Cors 配置示例。

#### YAML
<a name="sam-property-httpapi-httpapicorsconfiguration--examples--httpapicorsconfiguration--yaml"></a>

```
CorsConfiguration:
  AllowOrigins:
    - "https://example.com"
  AllowHeaders:
    - x-apigateway-header
  AllowMethods:
    - GET
  MaxAge: 600
  AllowCredentials: true
```