View a markdown version of this page

WebSocketApiAuth - AWS Serverless Application Model

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

WebSocketApiAuth

設定授權以控制對 Amazon 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 授權方

下列範例會設定 WebSocket API 的 Lambda 授權方。

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

IAM 授權

下列範例會設定 WebSocket API 的 IAM 授權。

Auth: AuthType: AWS_IAM