

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

# ApiUsagePlan
<a name="sam-property-api-apiusageplan"></a>

为 API Gateway API 配置使用计划。有关使用计划的更多信息，请参阅*《API Gateway 开发人员指南》*中的[使用 API 密钥创建和使用使用计划](https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-api-usage-plans.html)。

## 语法
<a name="sam-property-api-apiusageplan-syntax"></a>

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

### YAML
<a name="sam-property-api-apiusageplan-syntax.yaml"></a>

```
  [CreateUsagePlan](#sam-api-apiusageplan-createusageplan): String
  [Description](#sam-api-apiusageplan-description): String
  [Quota](#sam-api-apiusageplan-quota): [QuotaSettings](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-usageplan.html#cfn-apigateway-usageplan-quota)
  [Tags](#sam-api-apiusageplan-tags): List
  [Throttle](#sam-api-apiusageplan-throttle): [ThrottleSettings](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-usageplan.html#cfn-apigateway-usageplan-throttle)
  [UsagePlanName](#sam-api-apiusageplan-usageplanname): String
```

## Properties
<a name="sam-property-api-apiusageplan-properties"></a>

 `CreateUsagePlan`   <a name="sam-api-apiusageplan-createusageplan"></a>
确定如何配置此使用计划。有效值包括 `PER_API`、`SHARED` 和 `NONE`。  
`PER_API` 会创建特定于此 API 的 [https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-usageplan.html](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-usageplan.html)、[https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-apikey.html](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-apikey.html) 和 [https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-usageplankey.html](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-usageplankey.html) 资源。这些资源的逻辑 IDs 分别为`<api-logical-id>UsagePlan``<api-logical-id>ApiKey``<api-logical-id>UsagePlanKey`、和。  
`SHARED`创建[https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-usageplan.html](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-usageplan.html)、和[https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-usageplankey.html](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-usageplankey.html)资源，这些资源在同一 AWS SAM 模板`CreateUsagePlan: SHARED`中也包含的任何 API 之间共享。这些资源的逻辑 IDs 分别为`ServerlessUsagePlan``ServerlessApiKey``ServerlessUsagePlanKey`、和。如果您使用此选项，我们建议您仅在一个 API 资源中为此使用计划添加其他配置，以避免定义冲突和状态不确定性。  
`NONE` 禁止创建使用计划或将使用计划与此 API 关联。在 [模板的 “全局” 部分 AWS SAM](sam-specification-template-anatomy-globals.md) 中指定了 `SHARED` 或 `PER_API` 的情况下才需要这样做。  
*有效值*：`PER_API`、`SHARED` 和 `NONE`  
*类型*：字符串  
*是否必需*：是  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `Description`   <a name="sam-api-apiusageplan-description"></a>
使用计划的描述。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::ApiGateway::UsagePlan`资源的`[Description](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-usageplan.html#cfn-apigateway-usageplan-description)`属性。

 `Quota`   <a name="sam-api-apiusageplan-quota"></a>
配置用户可在指定时间间隔内发出的请求的数量。  
*类型*：[QuotaSettings](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-usageplan.html#cfn-apigateway-usageplan-quota)  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::ApiGateway::UsagePlan`资源的`[Quota](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-usageplan.html#cfn-apigateway-usageplan-quota)`属性。

 `Tags`   <a name="sam-api-apiusageplan-tags"></a>
与使用计划关联的任意标签（键值对）的数组。  
此属性使用[CloudFormation 标签类型](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-resource-tags.html)。  
*类型*：列表  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::ApiGateway::UsagePlan`资源的`[Tags](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-usageplan.html#cfn-apigateway-usageplan-tags)`属性。

 `Throttle`   <a name="sam-api-apiusageplan-throttle"></a>
配置整体请求速率（每秒平均请求数）和突发容量。  
*类型*：[ThrottleSettings](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-usageplan.html#cfn-apigateway-usageplan-throttle)  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::ApiGateway::UsagePlan`资源的`[Throttle](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-usageplan.html#cfn-apigateway-usageplan-throttle)`属性。

 `UsagePlanName`   <a name="sam-api-apiusageplan-usageplanname"></a>
使用计划的名称。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::ApiGateway::UsagePlan`资源的`[UsagePlanName](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-usageplan.html#cfn-apigateway-usageplan-usageplanname)`属性。

## 示例
<a name="sam-property-api-apiusageplan--examples"></a>

### UsagePlan
<a name="sam-property-api-apiusageplan--examples--usageplan"></a>

以下是使用计划示例。

#### YAML
<a name="sam-property-api-apiusageplan--examples--usageplan--yaml"></a>

```
Auth:
  UsagePlan:
    CreateUsagePlan: PER_API
    Description: Usage plan for this API
    Quota:
      Limit: 500
      Period: MONTH
    Throttle:
      BurstLimit: 100
      RateLimit: 50
    Tags:
      - Key: TagName
        Value: TagValue
```