coolyfrost
coolyfrost

Reputation: 146

AWS Making a User Store based on Userpools

I am creating an Android and iOS app and a lot of network features that I'm implementing utilize AWS Amplify. I have an authentication system that sets up and verifies user info through AWS Cognito and AWS User Pools. However, I'm also trying to store more attributes for each user beyond just usernames, emails, phone numbers and passwords. I also want to store things such as scores, number of days logged in, etc. Some AWS services such as S3 appear to allow me to create a database with these attributes, but it appears that everyone can access them, and I need an extremely secure system where the only people who can access these user attributes are the user themselves and me as the admin.

What is the best way to implement this feature within AWS while integrating it with an Android/iOS app? Thank you

Upvotes: 1

Views: 64

Answers (1)

Jack Vial
Jack Vial

Reputation: 2474

I would recommend adding either a Rest API or GraphQL API to your Amplify backend. This will create a secure API that will use a JWT token generated by Cognito for authentication. Your data will be stored in DynamoDB tables that will be generated via the @model directive in your GraphQL schema.

Create a GraphQL API

Navigate into the root of a JavaScript, iOS, or Android project and run:

amplify add api

Select the following options:

Select GraphQL

  • When asked if you have a schema, say No
  • Select one of the default samples; you can change this later
  • Choose to edit the schema and it will open the new schema.graphql in your editor

A simple model for tracking user scores and days since last log in might look like:

type UserData @model {
  id: ID!
  cognitoUserId: String!
  score: Float!
  lastLoggedInAt: AWSDate!
}

More details on building an Amplify GraphQL API here https://docs.amplify.aws/cli/graphql-transformer/overview/

Create a REST API

Follow the wizard to create a new app. After finishing the wizard run:

amplify add api

Select the following options:

Please select from one of the below-mentioned services: REST

  • Provide a friendly name for your resource to be used as a label for this - category in the project: itemsApi
  • Provide a path (e.g., /book/{isbn}): /items

This will be the configuration for /items path in API Gateway:

/                        
 |_ /items               Main resource. Eg: /items
    ANY                    Includes methods: DELETE, GET, HEAD, OPTIONS, PATCH, POST, PUT
    OPTIONS                Allow pre-flight requests in CORS by browser
    |_ /{proxy+}         Proxy resource. Eg: /items/, /items/id, items/object/{id}
       ANY                  Includes methods: DELETE, GET, HEAD, OPTIONS, PATCH, POST, PUT
       OPTIONS              Allow pre-flight requests in CORS by browser

More on creating an Amplify REST API here

Upvotes: 1

Related Questions