View a markdown version of this page

WebSocketApiAuth - AWS Serverless Application Model

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

WebSocketApiAuth

配置授权以控制对您的亚马逊 API Gateway WebSocket API 的访问。

有关配置访问权限的更多信息 WebSocket APIs,请参阅《API Gateway 开发者指南》 WebSocket APIs中的控制访问权限

语法

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

YAML

AuthArn: String AuthType: String IdentitySource: List InvokeRole: String Name: String

Properties

AuthArn

用于授权的 Lambda 函数的 ARN。何时AuthType为必填项CUSTOM

类型:字符串

必需:条件

CloudFormation 兼容性:此属性是独有的 AWS SAM ,没有 CloudFormation 等效属性。

AuthType

授权的类型。有效值为 NONEAWS_IAMCUSTOM

  • NONE-没有授权

  • AWS_IAM-IAM 授权

  • CUSTOM-Lambda 授权者

类型:字符串

是否必需:是

CloudFormation 兼容性:此属性是独有的 AWS SAM ,没有 CloudFormation 等效属性。

IdentitySource

为其请求授权的身份源。例如 route.request.header.Authorization

类型:列表

必需:否

CloudFormation 兼容性:此属性直接传递给AWS::ApiGatewayV2::Authorizer资源的IdentitySource属性。

InvokeRole

API Gateway 在调用授权方函数时扮演的 IAM 角色的 ARN。如果未指定,则 AWS SAM 自动创建基于资源的权限,允许 API Gateway 调用授权方函数。

类型:字符串

必需:否

CloudFormation 兼容性:此属性直接传递给AWS::ApiGatewayV2::Authorizer资源的AuthorizerCredentialsArn属性。

Name

授权方的名称。

类型:字符串

必需:否

CloudFormation 兼容性:此属性直接传递给AWS::ApiGatewayV2::Authorizer资源的Name属性。

示例

Lambda 授权器

以下示例为 API 配置了 Lambda 授权方。 WebSocket

Auth: AuthType: CUSTOM AuthArn: !GetAtt AuthorizerFunction.Arn IdentitySource: - route.request.header.Authorization

IAM 授权

以下示例为 WebSocket API 配置 IAM 授权。

Auth: AuthType: AWS_IAM