IAM 權限範例 - AWS Serverless Application Model

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

IAM 權限範例

您可以在 AWS SAM 範本中定義 IAM 許可來控制 API 的存取權限。要做到這一點,你使用的ApiAuth數據類型。

以下是 IAM 許可使用的 AWS SAM 範例範本:

AWSTemplateFormatVersion: '2010-09-09' Transform: AWS::Serverless-2016-10-31 Resources: MyApi: Type: AWS::Serverless::Api Properties: StageName: Prod Description: 'API with IAM authorization' Auth: DefaultAuthorizer: AWS_IAM #sets AWS_IAM auth for all methods in this API MyFunction: Type: AWS::Serverless::Function Properties: Handler: index.handler Runtime: python3.10 Events: GetRoot: Type: Api Properties: RestApiId: !Ref MyApi Path: / Method: get InlineCode: | def handler(event, context): return {'body': 'Hello World!', 'statusCode': 200}

如需 IAM 許可的詳細資訊,請參閱 API Gateway 開發人員指南中的控制叫用 API 的存取。