

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

# ApiAuth
<a name="sam-property-api-apiauth"></a>

配置授权，以控制对 API Gateway API 的访问。

有关使用配置访问权限的更多信息和示例， AWS SAM 请参阅[使用您的 AWS SAM 模板控制 API 访问权限](serverless-controlling-access-to-apis.md)。

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

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

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

```
  AddApiKeyRequiredToCorsPreflight: Boolean
  [AddDefaultAuthorizerToCorsPreflight](#sam-api-apiauth-adddefaultauthorizertocorspreflight): Boolean
  [ApiKeyRequired](#sam-api-apiauth-apikeyrequired): Boolean
  [Authorizers](#sam-api-apiauth-authorizers): CognitoAuthorizer | LambdaTokenAuthorizer | LambdaRequestAuthorizer | AWS_IAM
  [DefaultAuthorizer](#sam-api-apiauth-defaultauthorizer): String
  [InvokeRole](#sam-api-apiauth-invokerole): String
  [ResourcePolicy](#sam-api-apiauth-resourcepolicy): ResourcePolicyStatement
  [UsagePlan](#sam-api-apiauth-usageplan): ApiUsagePlan
```

**注意**  
该 `Authorizers` 属性包含 `AWS_IAM`，但无需为 `AWS_IAM` 进行额外配置。有关示例，请参阅[AWS IAM](#sam-property-api-apiauth--examples--aws_iam)。

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

 `AddApiKeyRequiredToCorsPreflight`   <a name="sam-api-apiauth-addapikeyrequiredtocorspreflight"></a>
如果设置了 `ApiKeyRequired` 和 `Cors` 属性，则设置 `AddApiKeyRequiredToCorsPreflight` 会导致 API 密钥被添加到 `Options` 属性中。  
*类型*：布尔值  
*必需*：否  
*默认值*：`True`  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `AddDefaultAuthorizerToCorsPreflight`   <a name="sam-api-apiauth-adddefaultauthorizertocorspreflight"></a>
如果设置了 `DefaultAuthorizer` 和 `Cors` 属性，则设置 `AddDefaultAuthorizerToCorsPreflight` 会导致默认授权方被添加到 OpenAPI 部分的 `Options` 属性中。  
*类型*：布尔值  
*必需*：否  
*默认值*：True  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `ApiKeyRequired`   <a name="sam-api-apiauth-apikeyrequired"></a>
如果设置为 true，则所有 API 事件都需要 API 密钥。有关 API 密钥的更多信息，请参阅*《API Gateway 开发人员指南》*中的[使用 API 密钥创建和使用使用计划](https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-api-usage-plans.html)。  
*类型*：布尔值  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `Authorizers`   <a name="sam-api-apiauth-authorizers"></a>
用于控制对 API Gateway API 的访问的授权方。  
有关更多信息，请参阅 [使用您的 AWS SAM 模板控制 API 访问权限](serverless-controlling-access-to-apis.md)。  
*类型*:[CognitoAuthorizer](sam-property-api-cognitoauthorizer.md)\$1 [LambdaTokenAuthorizer](sam-property-api-lambdatokenauthorizer.md)\$1 [LambdaRequestAuthorizer](sam-property-api-lambdarequestauthorizer.md)\$1 AWS\$1IAM  
*必需*：否  
*默认值*：无  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。  
*其他说明*：SAM 在 Api 的 OpenApi 定义中添加了授权方。

 `DefaultAuthorizer`   <a name="sam-api-apiauth-defaultauthorizer"></a>
为 API Gateway API 指定默认授权方，默认情况下，该授权方将用于授权 API 调用。  
如果将与此 API EventSource 关联的函数的 Api 配置为使用 IAM 权限，则必须将此属性设置为`AWS_IAM`，否则将导致错误。
*类型*：字符串  
*必需*：否  
*默认值*：无  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `InvokeRole`   <a name="sam-api-apiauth-invokerole"></a>
将所有资源和方法的集成凭证设置为此值。  
`CALLER_CREDENTIALS` 映射到 `arn:aws:iam:::<user>/`，后者使用调用者凭证来调用端点。  
*有效值*: `CALLER_CREDENTIALS`, `NONE`, `IAMRoleArn`   
*类型*：字符串  
*必需*：否  
*默认值*：`CALLER_CREDENTIALS`  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `ResourcePolicy`   <a name="sam-api-apiauth-resourcepolicy"></a>
为 API 中的所有方法和路径配置资源策略。  
*类型*：[ResourcePolicyStatement](sam-property-api-resourcepolicystatement.md)  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。  
*附加说明*：也可以使用 [ApiFunctionAuth](sam-property-function-apifunctionauth.md) 在各个 `AWS::Serverless::Function` 中定义此设置。这是 with 所必需 APIs 的`EndpointConfiguration: PRIVATE`。

 `UsagePlan`   <a name="sam-api-apiauth-usageplan"></a>
配置与此 API 关联的使用计划。有关使用计划的更多信息，请参阅*《API Gateway 开发人员指南》*中的[使用 API 密钥创建和使用使用计划](https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-api-usage-plans.html)。  
设置此 AWS SAM 属性后，此属性会额外生成三个 CloudFormation 资源：a [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)、a 和[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)。有关此场景的更多信息，请参阅[UsagePlan 属性已指定](sam-specification-generated-resources-api.md#sam-specification-generated-resources-api-usage-plan)。有关生成的 CloudFormation 资源的一般信息，请参阅[生成的 CloudFormation 资源用于 AWS SAM](sam-specification-generated-resources.md)。  
*类型*：[ApiUsagePlan](sam-property-api-apiusageplan.md)  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

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

### CognitoAuth
<a name="sam-property-api-apiauth--examples--cognitoauth"></a>

Cognito 身份验证示例

#### YAML
<a name="sam-property-api-apiauth--examples--cognitoauth--yaml"></a>

```
Auth:
  Authorizers:
    MyCognitoAuth:
     UserPoolArn:
       Fn::GetAtt:
         - MyUserPool
         - Arn
     AuthType: "COGNITO_USER_POOLS"
  DefaultAuthorizer: MyCognitoAuth
  InvokeRole: CALLER_CREDENTIALS
  AddDefaultAuthorizerToCorsPreflight: false
  ApiKeyRequired: false
  ResourcePolicy:
    CustomStatements: [{
      "Effect": "Allow",
      "Principal": "*",
      "Action": "execute-api:Invoke",
      "Resource": "execute-api:/Prod/GET/pets",
      "Condition": {
          "IpAddress": {
              "aws:SourceIp": "1.2.3.4"
          }
        }
    }]
    IpRangeDenylist:
      - "10.20.30.40"
```

### AWS IAM
<a name="sam-property-api-apiauth--examples--aws_iam"></a>

AWS IAM 示例

#### YAML
<a name="sam-property-api-apiauth--examples--cognitoauth--yaml"></a>

```
Auth:
  Authorizers: AWS_IAM
```

# 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
```

# CognitoAuthorizer
<a name="sam-property-api-cognitoauthorizer"></a>

定义 Amazon Cognito 用户群体授权方。

有关更多信息以及示例，请参阅 [使用您的 AWS SAM 模板控制 API 访问权限](serverless-controlling-access-to-apis.md)。

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

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

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

```
  [AuthorizationScopes](#sam-api-cognitoauthorizer-authorizationscopes): List
  [Identity](#sam-api-cognitoauthorizer-identity): CognitoAuthorizationIdentity
  [UserPoolArn](#sam-api-cognitoauthorizer-userpoolarn): String
```

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

 `AuthorizationScopes`   <a name="sam-api-cognitoauthorizer-authorizationscopes"></a>
此授权方的授权范围列表。  
*类型*：列表  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `Identity`   <a name="sam-api-cognitoauthorizer-identity"></a>
此属性可用于在授权方传入请求中指定 `IdentitySource`。  
*类型*：[CognitoAuthorizationIdentity](sam-property-api-cognitoauthorizationidentity.md)  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `UserPoolArn`   <a name="sam-api-cognitoauthorizer-userpoolarn"></a>
可以指用户 pool/specify 一个你想向其添加这个 cognito 授权者的用户池 arn  
*类型*：字符串  
*是否必需*：是  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

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

### CognitoAuth
<a name="sam-property-api-cognitoauthorizer--examples--cognitoauth"></a>

Cognito 身份验证示例

#### YAML
<a name="sam-property-api-cognitoauthorizer--examples--cognitoauth--yaml"></a>

```
Auth:
  Authorizers:
    MyCognitoAuth:
      AuthorizationScopes:
        - scope1
        - scope2
      UserPoolArn:
        Fn::GetAtt:
          - MyCognitoUserPool
          - Arn
      Identity:
        Header: MyAuthorizationHeader
        ValidationExpression: myauthvalidationexpression
```

# CognitoAuthorizationIdentity
<a name="sam-property-api-cognitoauthorizationidentity"></a>

此属性可用于在授权方的传入请求 IdentitySource 中指定。有关更多信息， IdentitySource 请参阅 A [ApiGateway uthorizer OpenApi 扩展](https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-swagger-extensions-authorizer.html)。

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

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

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

```
  [Header](#sam-api-cognitoauthorizationidentity-header): String
  [ReauthorizeEvery](#sam-api-cognitoauthorizationidentity-reauthorizeevery): Integer
  [ValidationExpression](#sam-api-cognitoauthorizationidentity-validationexpression): String
```

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

 `Header`   <a name="sam-api-cognitoauthorizationidentity-header"></a>
在 OpenApi 定义中为 “授权” 指定标题名称。  
*类型*：字符串  
*必需*：否  
*默认值*：Authorization  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `ReauthorizeEvery`   <a name="sam-api-cognitoauthorizationidentity-reauthorizeevery"></a>
 time-to-live(TTL) 周期，以秒为单位，用于指定 API Gateway 缓存授权方结果的时长。如果您指定一个大于 0 的值，API Gateway 将缓存授权方响应。默认情况下，API Gateway 将此属性设为 300。最大值为 3600 秒（1 小时）。  
*类型*：整数  
*必需*：否  
*默认值*：300  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `ValidationExpression`   <a name="sam-api-cognitoauthorizationidentity-validationexpression"></a>
指定验证传入身份的验证表达式  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

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

### CognitoAuthIdentity
<a name="sam-property-api-cognitoauthorizationidentity--examples--cognitoauthidentity"></a>

#### YAML
<a name="sam-property-api-cognitoauthorizationidentity--examples--cognitoauthidentity--yaml"></a>

```
Identity:
  Header: MyCustomAuthHeader
  ValidationExpression: Bearer.*
  ReauthorizeEvery: 30
```

# LambdaRequestAuthorizer
<a name="sam-property-api-lambdarequestauthorizer"></a>

配置 Lambda 授权方以通过 Lambda 函数控制对 API 的访问。

有关更多信息以及示例，请参阅 [使用您的 AWS SAM 模板控制 API 访问权限](serverless-controlling-access-to-apis.md)。

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

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

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

```
DisableFunctionDefaultPermissions: Boolean
[FunctionArn](#sam-api-lambdarequestauthorizer-functionarn): String
[FunctionInvokeRole](#sam-api-lambdarequestauthorizer-functioninvokerole): String
[FunctionPayloadType](#sam-api-lambdarequestauthorizer-functionpayloadtype): String
[Identity](#sam-api-lambdarequestauthorizer-identity): LambdaRequestAuthorizationIdentity
```

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

 `DisableFunctionDefaultPermissions`   <a name="sam-api-lambdarequestauthorizer-disablefunctiondefaultpermissions"></a>
指定`true`以 AWS SAM 防止自动创建`AWS::Lambda::Permissions`资源以在您的`AWS::Serverless::Api`资源和授权者 Lambda 函数之间配置权限。  
*默认值*：`false`  
*类型*：布尔值  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `FunctionArn`   <a name="sam-api-lambdarequestauthorizer-functionarn"></a>
指定 Lambda 函数的函数 ARN，该函数为 API 提供授权。  
AWS SAM 当为指定`AWS::Lambda::Permissions`资源时`FunctionArn`，将自动创建资源`AWS::Serverless::Api`。该 `AWS::Lambda::Permissions` 资源在您的 API 和授权方 Lambda 函数之间配置权限。
*类型*：字符串  
*是否必需*：是  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `FunctionInvokeRole`   <a name="sam-api-lambdarequestauthorizer-functioninvokerole"></a>
将授权者凭证添加到 Lambda 授权方的 OpenApi 定义中。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `FunctionPayloadType`   <a name="sam-api-lambdarequestauthorizer-functionpayloadtype"></a>
此属性可用于定义 API 的 Lambda 授权方的类型。  
*有效值*：`TOKEN` 或 `REQUEST`  
*类型*：字符串  
*必需*：否  
*默认值*：`TOKEN`  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `Identity`   <a name="sam-api-lambdarequestauthorizer-identity"></a>
此属性可用于在授权方传入请求中指定 `IdentitySource`。仅当属性 `FunctionPayloadType` 为 `REQUEST` 时，该属性是必需属性。  
*类型*：[LambdaRequestAuthorizationIdentity](sam-property-api-lambdarequestauthorizationidentity.md)  
*必需*：条件  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

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

### LambdaRequestAuth
<a name="sam-property-api-lambdarequestauthorizer--examples--lambdarequestauth"></a>

#### YAML
<a name="sam-property-api-lambdarequestauthorizer--examples--lambdarequestauth--yaml"></a>

```
Authorizers:
  MyLambdaRequestAuth:
    FunctionPayloadType: REQUEST
    FunctionArn:
      Fn::GetAtt:
        - MyAuthFunction
        - Arn
    FunctionInvokeRole:
      Fn::GetAtt:
        - LambdaAuthInvokeRole
        - Arn
    Identity:
      Headers:
        - Authorization1
```

# LambdaRequestAuthorizationIdentity
<a name="sam-property-api-lambdarequestauthorizationidentity"></a>

此属性可用于在授权方的传入请求 IdentitySource 中指定。有关更多信息， IdentitySource 请参阅 A [ApiGateway uthorizer OpenApi 扩展](https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-swagger-extensions-authorizer.html)。

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

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

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

```
  [Context](#sam-api-lambdarequestauthorizationidentity-context): List
  [Headers](#sam-api-lambdarequestauthorizationidentity-headers): List
  [QueryStrings](#sam-api-lambdarequestauthorizationidentity-querystrings): List
  [ReauthorizeEvery](#sam-api-lambdarequestauthorizationidentity-reauthorizeevery): Integer
  [StageVariables](#sam-api-lambdarequestauthorizationidentity-stagevariables): List
```

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

 `Context`   <a name="sam-api-lambdarequestauthorizationidentity-context"></a>
将给定的上下文字符串转换为格式 `context.contextString` 的映射表达式。  
*类型*：列表  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `Headers`   <a name="sam-api-lambdarequestauthorizationidentity-headers"></a>
将标头转换为格式 `method.request.header.name` 的映射表达式的逗号分隔字符串。  
*类型*：列表  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `QueryStrings`   <a name="sam-api-lambdarequestauthorizationidentity-querystrings"></a>
将给定的查询字符串转换为格式 `method.request.querystring.queryString` 的映射表达式的逗号分隔字符串。  
*类型*：列表  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `ReauthorizeEvery`   <a name="sam-api-lambdarequestauthorizationidentity-reauthorizeevery"></a>
 time-to-live(TTL) 周期，以秒为单位，用于指定 API Gateway 缓存授权方结果的时长。如果您指定一个大于 0 的值，API Gateway 将缓存授权方响应。默认情况下，API Gateway 将此属性设为 300。最大值为 3600 秒（1 小时）。  
*类型*：整数  
*必需*：否  
*默认值*：300  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `StageVariables`   <a name="sam-api-lambdarequestauthorizationidentity-stagevariables"></a>
将给定的阶段变量转换为格式 `stageVariables.stageVariable` 的映射表达式的逗号分隔字符串。  
*类型*：列表  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

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

### LambdaRequestIdentity
<a name="sam-property-api-lambdarequestauthorizationidentity--examples--lambdarequestidentity"></a>

#### YAML
<a name="sam-property-api-lambdarequestauthorizationidentity--examples--lambdarequestidentity--yaml"></a>

```
Identity:
  QueryStrings:
    - auth
  Headers:
    - Authorization
  StageVariables:
    - VARIABLE
  Context:
    - authcontext
  ReauthorizeEvery: 100
```

# LambdaTokenAuthorizer
<a name="sam-property-api-lambdatokenauthorizer"></a>

配置 Lambda 授权方以通过 Lambda 函数控制对 API 的访问。

有关更多信息以及示例，请参阅 [使用您的 AWS SAM 模板控制 API 访问权限](serverless-controlling-access-to-apis.md)。

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

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

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

```
DisableFunctionDefaultPermissions: Boolean
[FunctionArn](#sam-api-lambdatokenauthorizer-functionarn): String
[FunctionInvokeRole](#sam-api-lambdatokenauthorizer-functioninvokerole): String
[FunctionPayloadType](#sam-api-lambdatokenauthorizer-functionpayloadtype): String
[Identity](#sam-api-lambdatokenauthorizer-identity): LambdaTokenAuthorizationIdentity
```

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

 `DisableFunctionDefaultPermissions`   <a name="sam-api-lambdatokenauthorizer-disablefunctiondefaultpermissions"></a>
指定`true`以 AWS SAM 防止自动创建`AWS::Lambda::Permissions`资源以在您的`AWS::Serverless::Api`资源和授权者 Lambda 函数之间配置权限。  
*默认值*：`false`  
*类型*：布尔值  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `FunctionArn`   <a name="sam-api-lambdatokenauthorizer-functionarn"></a>
指定 Lambda 函数的函数 ARN，该函数为 API 提供授权。  
AWS SAM 当为指定`AWS::Lambda::Permissions`资源时`FunctionArn`，将自动创建资源`AWS::Serverless::Api`。该 `AWS::Lambda::Permissions` 资源在您的 API 和授权方 Lambda 函数之间配置权限。
*类型*：字符串  
*是否必需*：是  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `FunctionInvokeRole`   <a name="sam-api-lambdatokenauthorizer-functioninvokerole"></a>
将授权者凭证添加到 Lambda 授权方的 OpenApi 定义中。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `FunctionPayloadType`   <a name="sam-api-lambdatokenauthorizer-functionpayloadtype"></a>
此属性可用于定义 Api 的 Lambda 授权方的类型。  
*有效值*：`TOKEN` 或 `REQUEST`  
*类型*：字符串  
*必需*：否  
*默认值*：`TOKEN`  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `Identity`   <a name="sam-api-lambdatokenauthorizer-identity"></a>
此属性可用于在授权方传入请求中指定 `IdentitySource`。仅当属性 `FunctionPayloadType` 为 `REQUEST` 时，该属性是必需属性。  
*类型*：[LambdaTokenAuthorizationIdentity](sam-property-api-lambdatokenauthorizationidentity.md)  
*必需*：条件  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

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

### LambdaTokenAuth
<a name="sam-property-api-lambdatokenauthorizer--examples--lambdatokenauth"></a>

#### YAML
<a name="sam-property-api-lambdatokenauthorizer--examples--lambdatokenauth--yaml"></a>

```
Authorizers:
  MyLambdaTokenAuth:
    FunctionArn:
      Fn::GetAtt:
        - MyAuthFunction
        - Arn
    Identity:
      Header: MyCustomAuthHeader # OPTIONAL; Default: 'Authorization'
      ValidationExpression: mycustomauthexpression # OPTIONAL
      ReauthorizeEvery: 20 # OPTIONAL; Service Default: 300
```

### BasicLambdaTokenAuth
<a name="sam-property-api-lambdatokenauthorizer--examples--basiclambdatokenauth"></a>

#### YAML
<a name="sam-property-api-lambdatokenauthorizer--examples--basiclambdatokenauth--yaml"></a>

```
Authorizers:
  MyLambdaTokenAuth:
    FunctionArn:
      Fn::GetAtt:
        - MyAuthFunction
        - Arn
```

# LambdaTokenAuthorizationIdentity
<a name="sam-property-api-lambdatokenauthorizationidentity"></a>

此属性可用于在授权方的传入请求 IdentitySource 中指定。有关更多信息， IdentitySource 请参阅[ApiGateway 授权器 OpenApi 扩展](https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-swagger-extensions-authorizer.html)。

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

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

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

```
  [Header](#sam-api-lambdatokenauthorizationidentity-header): String
  [ReauthorizeEvery](#sam-api-lambdatokenauthorizationidentity-reauthorizeevery): Integer
  [ValidationExpression](#sam-api-lambdatokenauthorizationidentity-validationexpression): String
```

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

 `Header`   <a name="sam-api-lambdatokenauthorizationidentity-header"></a>
在 OpenApi 定义中为授权指定标题名称。  
*类型*：字符串  
*必需*：否  
*默认值*：Authorization  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `ReauthorizeEvery`   <a name="sam-api-lambdatokenauthorizationidentity-reauthorizeevery"></a>
 time-to-live(TTL) 周期，以秒为单位，用于指定 API Gateway 缓存授权方结果的时长。如果您指定一个大于 0 的值，API Gateway 将缓存授权方响应。默认情况下，API Gateway 将此属性设为 300。最大值为 3600 秒（1 小时）。  
*类型*：整数  
*必需*：否  
*默认值*：300  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `ValidationExpression`   <a name="sam-api-lambdatokenauthorizationidentity-validationexpression"></a>
指定验证传入身份的验证表达式。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

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

### LambdaTokenIdentity
<a name="sam-property-api-lambdatokenauthorizationidentity--examples--lambdatokenidentity"></a>

#### YAML
<a name="sam-property-api-lambdatokenauthorizationidentity--examples--lambdatokenidentity--yaml"></a>

```
Identity:
  Header: MyCustomAuthHeader
  ValidationExpression: Bearer.*
  ReauthorizeEvery: 30
```

# ResourcePolicyStatement
<a name="sam-property-api-resourcepolicystatement"></a>

为 API 的所有方法和路径配置资源策略。有关资源策略的更多信息，请参阅*《API Gateway 开发人员指南》*中的[使用 API Gateway 资源策略控制 API 的访问权限](https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-resource-policies.html)。

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

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

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

```
  [AwsAccountBlacklist](#sam-api-resourcepolicystatement-awsaccountblacklist): List
  [AwsAccountWhitelist](#sam-api-resourcepolicystatement-awsaccountwhitelist): List
  [CustomStatements](#sam-api-resourcepolicystatement-customstatements): List
  [IntrinsicVpcBlacklist](#sam-api-resourcepolicystatement-intrinsicvpcblacklist): List
  [IntrinsicVpcWhitelist](#sam-api-resourcepolicystatement-intrinsicvpcwhitelist): List
  [IntrinsicVpceBlacklist](#sam-api-resourcepolicystatement-intrinsicvpceblacklist): List
  [IntrinsicVpceWhitelist](#sam-api-resourcepolicystatement-intrinsicvpcewhitelist): List
  [IpRangeBlacklist](#sam-api-resourcepolicystatement-iprangeblacklist): List
  [IpRangeWhitelist](#sam-api-resourcepolicystatement-iprangewhitelist): List
  [SourceVpcBlacklist](#sam-api-resourcepolicystatement-sourcevpcblacklist): List
  [SourceVpcWhitelist](#sam-api-resourcepolicystatement-sourcevpcwhitelist): List
```

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

 `AwsAccountBlacklist`   <a name="sam-api-resourcepolicystatement-awsaccountblacklist"></a>
要封锁的 AWS 账户。  
*类型*：字符串列表  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `AwsAccountWhitelist`   <a name="sam-api-resourcepolicystatement-awsaccountwhitelist"></a>
要允许的 AWS 账户。有关此属性的使用示例，请参阅本页底部的“示例”部分。  
*类型*：字符串列表  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `CustomStatements`   <a name="sam-api-resourcepolicystatement-customstatements"></a>
适用于此 API 的自定义资源策略语句列表。有关此属性的使用示例，请参阅本页底部的“示例”部分。  
*类型*：列表  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `IntrinsicVpcBlacklist`   <a name="sam-api-resourcepolicystatement-intrinsicvpcblacklist"></a>
要屏蔽的虚拟私有云列表 (VPCs)，其中每个 VPC 都指定为引用，例如[动态引用](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/dynamic-references.html)或`Ref`[内部函数](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-ref.html)。有关此属性的使用示例，请参阅本页底部的“示例”部分。  
*类型*：列表  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `IntrinsicVpcWhitelist`   <a name="sam-api-resourcepolicystatement-intrinsicvpcwhitelist"></a>
 VPCs 要允许的列表，其中每个 VPC 都指定为引用，例如[动态引用](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/dynamic-references.html)或`Ref`[内部函数](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-ref.html)。  
*类型*：列表  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `IntrinsicVpceBlacklist`   <a name="sam-api-resourcepolicystatement-intrinsicvpceblacklist"></a>
要阻止的 VPC 端点列表，其中每个 VPC 端点都指定为引用，例如[动态引用](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/dynamic-references.html)或`Ref`[内置函数](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-ref.html)。  
*类型*：列表  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `IntrinsicVpceWhitelist`   <a name="sam-api-resourcepolicystatement-intrinsicvpcewhitelist"></a>
要允许的 VPC 端点列表，其中每个 VPC 端点都指定为引用，例如[动态引用](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/dynamic-references.html)或`Ref`[内置函数](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-ref.html)。有关此属性的使用示例，请参阅本页底部的“示例”部分。  
*类型*：列表  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `IpRangeBlacklist`   <a name="sam-api-resourcepolicystatement-iprangeblacklist"></a>
要阻止的 IP 地址或地址范围。有关此属性的使用示例，请参阅本页底部的“示例”部分。  
*类型*：列表  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `IpRangeWhitelist`   <a name="sam-api-resourcepolicystatement-iprangewhitelist"></a>
要允许的 IP 地址或地址范围。  
*类型*：列表  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `SourceVpcBlacklist`   <a name="sam-api-resourcepolicystatement-sourcevpcblacklist"></a>
要阻止的源 VPC 或 VPC 端点。源 VPC 名称必须以 `"vpc-"` 开头，源 VPC 端点名称必须以 `"vpce-"` 开头。有关此属性的使用示例，请参阅本页底部的“示例”部分。  
*类型*：列表  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `SourceVpcWhitelist`   <a name="sam-api-resourcepolicystatement-sourcevpcwhitelist"></a>
要允许的源 VPC 或 VPC 端点。源 VPC 名称必须以 `"vpc-"` 开头，源 VPC 端点名称必须以 `"vpce-"` 开头。  
*类型*：列表  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

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

### 资源策略示例
<a name="sam-property-api-resourcepolicystatement--examples--resource-policy-example"></a>

以下示例屏蔽两个 IP 地址和一个源 VPC，并允许一个 AWS 账户。

#### YAML
<a name="sam-property-api-resourcepolicystatement--examples--resource-policy-example--yaml"></a>

```
Auth:
  ResourcePolicy:
    CustomStatements: [{
                         "Effect": "Allow",
                         "Principal": "*",
                         "Action": "execute-api:Invoke",
                         "Resource": "execute-api:/Prod/GET/pets",
                         "Condition": {
                           "IpAddress": {
                             "aws:SourceIp": "1.2.3.4"
                           }
                         }
                       }]
    IpRangeBlacklist:
      - "10.20.30.40"
      - "1.2.3.4"
    SourceVpcBlacklist:
      - "vpce-1a2b3c4d"
    AwsAccountWhitelist:
      - "111122223333"
    IntrinsicVpcBlacklist:
      - "{{resolve:ssm:SomeVPCReference:1}}" 
      - !Ref MyVPC
    IntrinsicVpceWhitelist:
      - "{{resolve:ssm:SomeVPCEReference:1}}" 
      - !Ref MyVPCE
```