

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

# LambdaAuthorizer
<a name="sam-property-httpapi-lambdaauthorizer"></a>

配置 Lambda 授权机构，使用函数控制对您的 Amazon API Gateway HTTP API 的访问。 AWS Lambda 

有关更多信息和示例，请参阅《*API Gateway 开发者指南》 APIs*[中的 “使用 HTTP 的 AWS Lambda 授权方](https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-lambda-authorizer.html)”。

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

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

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

```
  [AuthorizerPayloadFormatVersion](#sam-httpapi-lambdaauthorizer-authorizerpayloadformatversion): String
  EnableFunctionDefaultPermissions: Boolean
  [EnableSimpleResponses](#sam-httpapi-lambdaauthorizer-enablesimpleresponses): Boolean
  [FunctionArn](#sam-httpapi-lambdaauthorizer-functionarn): String
  [FunctionInvokeRole](#sam-httpapi-lambdaauthorizer-functioninvokerole): String
  [Identity](#sam-httpapi-lambdaauthorizer-identity): LambdaAuthorizationIdentity
```

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

 `AuthorizerPayloadFormatVersion`   <a name="sam-httpapi-lambdaauthorizer-authorizerpayloadformatversion"></a>
指定发送到 HTTP API Lambda 授权方的负载的格式。对于 HTTP API Lambda 授权方必须指定。  
这会传递到 OpenAPI 定义的 `securitySchemes` 部分中 `x-amazon-apigateway-authorizer` 的 `authorizerPayloadFormatVersion` 部分。  
*有效值*：`1.0` 或 `2.0`  
*类型*：字符串  
*是否必需*：是  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `EnableFunctionDefaultPermissions`   <a name="sam-httpapi-lambdaauthorizer-enablefunctiondefaultpermissions"></a>
默认情况下，未授予 HTTP API 资源调用 Lambda 授权方的权限。将此属性指定为 `true` 以自动在您的 HTTP API 资源和 Lambda 授权方之间创建权限。  
*类型*：布尔值  
*必需*：否  
*默认值*：`false`  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `EnableSimpleResponses`   <a name="sam-httpapi-lambdaauthorizer-enablesimpleresponses"></a>
指定 Lambda 授权方是否以简单格式返回响应。默认情况下，Lambda 授权机构必须返回 AWS Identity and Access Management (IAM) 策略。如果启用，Lambda 授权方可以返回布尔值，而不是 IAM 策略。  
这会传递到 OpenAPI 定义的 `securitySchemes` 部分中 `x-amazon-apigateway-authorizer` 的 `enableSimpleResponses` 部分。  
*类型*：布尔值  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `FunctionArn`   <a name="sam-httpapi-lambdaauthorizer-functionarn"></a>
为 API 提供授权的 Lambda 函数的 Amazon 资源名称（ARN）。  
这会传递到 OpenAPI 定义的 `securitySchemes` 部分中 `x-amazon-apigateway-authorizer` 的 `authorizerUri` 部分。  
*类型*：字符串  
*是否必需*：是  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `FunctionInvokeRole`   <a name="sam-httpapi-lambdaauthorizer-functioninvokerole"></a>
具有 API Gateway 调用授权方函数所需凭证的 IAM 角色的 ARN。如果函数的基于资源的策略未授予 API Gateway `lambda:InvokeFunction` 权限，请指定此参数。  
这会传递到 OpenAPI 定义的 `securitySchemes` 部分中 `x-amazon-apigateway-authorizer` 的 `authorizerCredentials` 部分。  
有关更多信息，请参阅*《API Gateway 开发人员指南》*中的[创建 Lambda 授权方](https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-lambda-authorizer.html#http-api-lambda-authorizer.example-create)。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `Identity`   <a name="sam-httpapi-lambdaauthorizer-identity"></a>
在授权方传入请求中指定 `IdentitySource`。  
这会传递到 OpenAPI 定义的 `securitySchemes` 部分中 `x-amazon-apigateway-authorizer` 的 `identitySource` 部分。  
*类型*：[LambdaAuthorizationIdentity](sam-property-httpapi-lambdaauthorizationidentity.md)  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

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

### LambdaAuthorizer
<a name="sam-property-httpapi-lambdaauthorizer--examples--lambdaauthorizer"></a>

LambdaAuthorizer 示例

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

```
Auth:
  Authorizers:
    MyLambdaAuthorizer:
      AuthorizerPayloadFormatVersion: 2.0
      FunctionArn:
        Fn::GetAtt:
          - MyAuthFunction
          - Arn
      FunctionInvokeRole:
        Fn::GetAtt:
          - LambdaAuthInvokeRole
          - Arn
      Identity:
        Headers:
          - Authorization
```

# LambdaAuthorizationIdentity
<a name="sam-property-httpapi-lambdaauthorizationidentity"></a>

Use 属性可用于在 Lambda 授权方的传入请求 IdentitySource 中指定。有关身份源的更多信息，请参阅*《API Gateway 开发人员指南》*中的[身份源](https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-lambda-authorizer.html#http-api-lambda-authorizer.identity-sources)。

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

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

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

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

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

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

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

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

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

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

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

### LambdaRequestIdentity
<a name="sam-property-httpapi-lambdaauthorizationidentity--examples--lambdarequestidentity"></a>

Lambda 请求身份示例

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

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