2017-06-12 13 views

答えて

0

現在、既存のユーザープールをのCognitoからエクスポートすることはできません。ただし、AWS CloudFormationに新しいユーザープールを作成し、AWS::Cognito::UserPoolリソースタイプを使用してCloudformation自体からこれらのプールを管理することができます。

3

エクスポートすることはできません。プロセスを自動化するには、以下の6つのリソースが必要です。あなたは3つの出力を必要とする

  1. Cognito認証の役割
  2. Cognito非認証の役割
  3. ユーザープール
  4. ユーザープールクライアント
  5. アイデンティティプール
  6. アイデンティティプール役割アタッチメント

あなたのコードで使用する必要があります。これらを作成するコードは次のとおりです。

AWSTemplateFormatVersion: 2010-09-09 
Parameters: 
    envParameter: 
    Type: String 
    Default: dev 
    AllowedValues: [ dev, test, qa, prod ] 
    Description: Suffix to be added for names. 
Resources: 
    myApiUserPool: 
    Type: "AWS::Cognito::UserPool" 
    Properties: 
     UserPoolName: !Sub myApiUserPool${envParameter} 
    myApiUserPoolClient: 
    Type: "AWS::Cognito::UserPoolClient" 
    Properties: 
     ClientName: !Sub myApiUserPoolClient${envParameter}, 
     GenerateSecret: False 
     RefreshTokenValidity: 30 
     UserPoolId: !Ref myApiUserPool 
    myApiIdentityPool: 
    Type: "AWS::Cognito::IdentityPool" 
    Properties: 
     IdentityPoolName: !Sub myApiIdentityPool${envParameter} 
     AllowUnauthenticatedIdentities: False 
     CognitoIdentityProviders: 
     - ClientId: !Ref myApiUserPoolClient 
      ProviderName: !GetAtt myApiUserPool.ProviderName 
    cognitoUnauthRole: 
    Type: 'AWS::IAM::Role' 
    Properties: 
     RoleName: !Sub Cognito_${myApiIdentityPool.Name}_Unauth_Role 
     AssumeRolePolicyDocument: 
     Version: 2012-10-17 
     Statement: 
      - Effect: Allow 
      Principal: 
       Federated: cognito-identity.amazonaws.com 
      Action: [ 'sts:AssumeRole' ] 
     Policies: 
     - PolicyName: cognitounauth 
      PolicyDocument: 
      Version: '2012-10-17' 
      Statement: 
       - Effect: Allow 
       Action: 
       - mobileanalytics:PutEvents 
       - cognito-sync:* 
       Resource: 
       - "*" 
    cognitoAuthRole: 
    Type: 'AWS::IAM::Role' 
    Properties: 
     RoleName: !Sub Cognito_${myApiIdentityPool.Name}_Auth_Role 
     AssumeRolePolicyDocument: 
     Version: 2012-10-17 
     Statement: 
      - Effect: Allow 
      Principal: 
       Federated: cognito-identity.amazonaws.com 
      Action: [ 'sts:AssumeRole' ] 
     Policies: 
     - PolicyName: cognitoauth 
      PolicyDocument: 
      Version: '2012-10-17' 
      Statement: 
       - Effect: Allow 
       Action: 
       - mobileanalytics:PutEvents 
       - cognito-sync:* 
       - execute-api:* 
       Resource: 
       - "*" 
    myApiIdentityPoolRoleAttachment: 
    DependsOn: [ myApiIdentityPool, cognitoUnauthRole, cognitoAuthRole ] 
    Type: "AWS::Cognito::IdentityPoolRoleAttachment" 
    Properties: 
     IdentityPoolId: !Ref myApiIdentityPool 
     Roles: 
     authenticated: !GetAtt cognitoAuthRole.Arn 
     unauthenticated: !GetAtt cognitoUnauthRole.Arn 
Outputs: 
userPool: 
    Description: "User pool ID" 
    Value: !Ref myApiUserPool 
identityPool: 
    Description: "Identity pool ID" 
    Value: !Ref myApiIdentityPool 
ClientId: 
    Description: "Client id for the user pool appclient" 
    Value: !Ref myApiUserPoolClient 
関連する問題