Amazon Cognito ユーザープールの例 - AWS Serverless Application Model

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

Amazon Cognito ユーザープールの例

API へのアクセスは、 AWS SAM テンプレート内で Amazon Cognito ユーザープールを定義することによって制御できます。これを実行するには、ApiAuth データ型を使用します。

ユーザープールの AWS SAM テンプレートセクションの例を次に示します。

Resources: MyApi: Type: AWS::Serverless::Api Properties: StageName: Prod Cors: "'*'" Auth: DefaultAuthorizer: MyCognitoAuthorizer Authorizers: MyCognitoAuthorizer: UserPoolArn: !GetAtt MyCognitoUserPool.Arn MyFunction: Type: AWS::Serverless::Function Properties: CodeUri: ./src Handler: lambda.handler Runtime: nodejs12.x Events: Root: Type: Api Properties: RestApiId: !Ref MyApi Path: / Method: GET MyCognitoUserPool: Type: AWS::Cognito::UserPool Properties: UserPoolName: !Ref CognitoUserPoolName Policies: PasswordPolicy: MinimumLength: 8 UsernameAttributes: - email Schema: - AttributeDataType: String Name: email Required: false MyCognitoUserPoolClient: Type: AWS::Cognito::UserPoolClient Properties: UserPoolId: !Ref MyCognitoUserPool ClientName: !Ref CognitoUserPoolClientName GenerateSecret: false

Amazon Cognito ユーザープールの詳細については、API Gateway デベロッパーガイドの「Amazon Cognito ユーザープールをオーソライザーとして使用して REST API へのアクセスを制御する」を参照してください