HttpApiFunctionAuth - AWS Serverless Application Model

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

HttpApiFunctionAuth

在事件層級設定授權。

為特定的 API + 路徑 + 方法配置身份驗證

語法

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

YAML

AuthorizationScopes: List Authorizer: String

屬性

AuthorizationScopes

要套用至此 API、路徑和方法的授權範圍。

此處列出的範圍將覆蓋由(DefaultAuthorizer如果存在)套用的任何範圍。

類型:清單

必要:否

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

Authorizer

Authorizer於特定功能。若要使用 IAM 授權AWS_IAM,請在範本的Globals區段EnableIamAuthorizer中指定並指定 true for。

如果您已在 API 上指定了全局授權者,並希望公開特定功能,請Authorizer將設置為NONE覆蓋。

類型:字串

必要:否

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

範例

功能身份驗證

在功能級別指定授權

YAML

Auth: Authorizer: OpenIdAuth AuthorizationScopes: - scope1 - scope2

IAM 授權

在事件層級指定 IAM 授權。若要在事件層級使用AWS_IAM授權,您還必須EnableIamAuthorizer在範本的Globals區段中指定 true for。如需詳細資訊,請參閱 模板的全局部分 AWS SAM

YAML

Globals: HttpApi: Auth: EnableIamAuthorizer: true Resources: HttpApiFunctionWithIamAuth: Type: AWS::Serverless::Function Properties: Events: ApiEvent: Type: HttpApi Properties: Path: /iam-auth Method: GET Auth: Authorizer: AWS_IAM Handler: index.handler InlineCode: | def handler(event, context): return {'body': 'HttpApiFunctionWithIamAuth', 'statusCode': 200} Runtime: python3.9