

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

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

設定 Lambda 授權方，以使用 AWS Lambda 函數控制對 Amazon API Gateway HTTP API 的存取。

如需詳細資訊和範例，請參閱[APIs》中的使用 HTTP API 的授權 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 定義的 `authorizerPayloadFormatVersion`區段`x-amazon-apigateway-authorizer`中傳遞至 的 `securitySchemes`區段。  
*有效值*：`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 定義的 `enableSimpleResponses`區段`x-amazon-apigateway-authorizer`中傳遞至 的 `securitySchemes`區段。  
*類型*：布林值  
*必要*：否  
*CloudFormation 相容性*：此屬性對 是唯一的 AWS SAM ，並且沒有 CloudFormation 同等的。

 `FunctionArn`   <a name="sam-httpapi-lambdaauthorizer-functionarn"></a>
提供 API 授權的 Lambda 函數的 Amazon Resource Name (ARN)。  
這會在 OpenAPI 定義的 `authorizerUri`區段`x-amazon-apigateway-authorizer`中傳遞至 的 `securitySchemes`區段。  
*類型：*字串  
*必要*：是  
*CloudFormation 相容性*：此屬性對 是唯一的 AWS SAM ，並且沒有 CloudFormation 同等的。

 `FunctionInvokeRole`   <a name="sam-httpapi-lambdaauthorizer-functioninvokerole"></a>
IAM 角色的 ARN，具有 API Gateway 叫用授權方函數所需的登入資料。如果函數的資源型政策未授予 API Gateway `lambda:InvokeFunction`許可，請指定此參數。  
這會在 OpenAPI 定義的 `authorizerCredentials`區段`x-amazon-apigateway-authorizer`中傳遞至 的 `securitySchemes`區段。  
如需詳細資訊，請參閱《 *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 定義的 `identitySource`區段`x-amazon-apigateway-authorizer`中傳遞至 的 `securitySchemes`區段。  
*類型*：[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
```