Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IdentityPool Creation with CloudFormation

I'm attempting to follow along with a tutorial located at http://serverless-stack.com/chapters/create-a-cognito-identity-pool.html for identity pool creation and document the creation by using cloudformation so that I can easily undo everything when I am done. However, I am having trouble finding any examples that show how to effectively do this using the template syntax. What I currently have is the following

ScratchUserPool:
      Type: AWS::Cognito::UserPool
      Properties:
        UserPoolName: notes-user-pool

ScratchUserPoolClient:
  Type: AWS::Cognito::UserPoolClient
  Properties:
    ClientName: notes-client
    ExplicitAuthFlows: [ADMIN_NO_SRP_AUTH]
    UserPoolId:
      Ref: ScratchUserPool

ScratchIdentityPool:
  Type: AWS::Cognito::IdentityPool
  Properties:
    IdentityPoolName: ScratchIdentityPool
    AllowUnauthenticatedIdentities: false
    CognitoIdentityProviders:
      - ClientId:
          Ref: ScratchUserPoolClient
        ProviderName:
          Ref: ScratchUserPool

The deployment step is failing when it attempts to create the ScratchIdentityPool. I get an error stating that:

An error occurred while provisioning your stack: ScratchIdentityPool - Invalid Cognito Identity Provider (Service: AmazonCognitoIdentity; Status Code: 400; Error Code: InvalidParameterException; Request ID: bc058020-663b-11e7-9f2a-XXXXXXXXXX)

Am I not referencing the Client or Provider name correctly?

like image 872
user985030 Avatar asked Jul 11 '17 13:07

user985030


1 Answers

Almost immediately after I posted my question, I think I was able to answer it. The problem with my identity pool is that I needed to reference the provider name in the following way:

ScratchIdentityPool:
  Type: AWS::Cognito::IdentityPool
  Properties:
    IdentityPoolName: ScratchIdentityPool
    AllowUnauthenticatedIdentities: false
    CognitoIdentityProviders:
      - ClientId:
          Ref: ScratchUserPoolClient
        ProviderName:
          Fn::GetAtt: [ScratchUserPool, ProviderName]

I needed to use the special amazon function Fn::GetAtt in order for this to work.

like image 175
user985030 Avatar answered Nov 07 '22 14:11

user985030