

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

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