Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating AWS Cognito User Pool from serverless.yml

I am trying to use an AWS Cognito User Pool for user authentication, but I can't seem to figure out how to create one from the serverless.yml file. I know that to create other resources you do something like:

resources:
  Resources:
    Table:
      Type: "AWS::DynamoDB::Table"  # Change this to "AWS::Cognito::UserPool"?
      DeletionPolicy: Retain
      Properties:                   # Change the properties here, but to what?
        AttributeDefinitions:
          -
            AttributeName: id
            AttributeType: S
        KeySchema:
          -
            AttributeName: id
            KeyType: HASH
        ProvisionedThroughput:
          ReadCapacityUnits: 1
          WriteCapacityUnits: 1
        TableName: arn:aws:dynamodb:us-west-1:*:table/tablename

I am assuming that I just need to change the type to "AWS:Cognito::UserPool" and change the properties. However, I have no idea what to change it to.

like image 569
akrantz01 Avatar asked Nov 07 '22 18:11

akrantz01


2 Answers

For those looking for a basic example, see the answer by @ionut. All of the configuration for the AWS::Cognito::UserPool can be found here. As for the AWS::Cognito::UserPoolClient, it can be found here.

like image 76
akrantz01 Avatar answered Nov 12 '22 10:11

akrantz01


It's very simple and straight forward.

All you need to do is create a few resources and then export them in from your template file.

What I do usually is first create a resource file( for eg, Cognito-user-pool.yml) and the add the necessary resource and export declaration there. After that I shall be calling the resource from my serverless.yml file ( ${ file(./cognito-user-pool.yml)}

Inside your user pool resource declaration, you would need to add definitions for

  1. CognitoUserPool
  2. App client
  3. Identity Pool
  4. Necessary Role attachment declaration
  5. Define the role with necessary policies.
  6. Export the first three resources : In case if you want to connect the Cognitoo user pool with your front end ( probably using AWS-amplify)
  7. deploy the stack

In this blog post I have explained the steps in detail and also have added a YouTube video for explaining each steps.

Blog Link : https://www.codegigs.app/how-to-cognito-user-pool-using-serverless/ Video Link : https://youtu.be/bv_imx8gfLU

like image 30
Saptarshi Misra Avatar answered Nov 12 '22 10:11

Saptarshi Misra