View a markdown version of this page

LambdaAuthorizer - AWS Serverless Application Model

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

LambdaAuthorizer

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

如需詳細資訊和範例,請參閱APIs》中的使用 HTTP API 的授權 AWS Lambda 方。

語法

若要在 AWS Serverless Application Model (AWS SAM) 範本中宣告此實體,請使用下列語法。

Properties

AuthorizerPayloadFormatVersion

指定傳送至 HTTP API Lambda 授權方的承載格式。HTTP API Lambda 授權方的必要項目。

這會在 OpenAPI 定義的 authorizerPayloadFormatVersion區段x-amazon-apigateway-authorizer中傳遞至 的 securitySchemes區段。

有效值:1.0 或 2.0

類型:字串

必要:是

CloudFormation 相容性:此屬性對 是唯一的 AWS SAM ,並且沒有 CloudFormation 同等屬性。

EnableFunctionDefaultPermissions

根據預設,不會授予 HTTP API 資源叫用 Lambda 授權方的許可。將此屬性指定為 true,以在 HTTP API 資源和 Lambda 授權方之間自動建立許可。

類型:布林值

必要:否

預設值:false

CloudFormation 相容性:此屬性對 是唯一的 AWS SAM ,並且沒有同等 CloudFormation 屬性。

EnableSimpleResponses

指定 Lambda 授權方是否以簡單格式傳回回應。根據預設,Lambda 授權方必須傳回 AWS Identity and Access Management (IAM) 政策。如果啟用,Lambda 授權方會傳回布林值,而不是 IAM 政策。

這會在 OpenAPI 定義的 enableSimpleResponses區段x-amazon-apigateway-authorizer中傳遞至 的 securitySchemes區段。

類型:布林值

必要:否

CloudFormation 相容性:此屬性對 是唯一的 AWS SAM ,並且沒有 CloudFormation 同等的。

FunctionArn

提供 API 授權的 Lambda 函數的 Amazon Resource Name (ARN)。

這會在 OpenAPI 定義的 authorizerUri區段x-amazon-apigateway-authorizer中傳遞至 的 securitySchemes區段。

類型:字串

必要:是

CloudFormation 相容性:此屬性對 是唯一的 AWS SAM ,並且沒有 CloudFormation 同等的。

FunctionInvokeRole

IAM 角色的 ARN,具有 API Gateway 叫用授權方函數所需的登入資料。如果函數的資源型政策未授予 API Gateway lambda:InvokeFunction許可,請指定此參數。

這會在 OpenAPI 定義的 authorizerCredentials區段x-amazon-apigateway-authorizer中傳遞至 的 securitySchemes區段。

如需詳細資訊,請參閱《 API Gateway 開發人員指南》中的建立 Lambda 授權方。

類型:字串

必要:否

CloudFormation 相容性:此屬性對 是唯一的 AWS SAM ,並且沒有 CloudFormation 同等的。

Identity

在 授權方的傳入請求IdentitySource中指定 。

這會在 OpenAPI 定義的 identitySource區段x-amazon-apigateway-authorizer中傳遞至 的 securitySchemes區段。

類型:LambdaAuthorizationIdentity

必要:否

CloudFormation 相容性:此屬性對 是唯一的 AWS SAM ,並且沒有 CloudFormation 同等的。

範例

LambdaAuthorizer

LambdaAuthorizer 範例

YAML

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