Search code examples
amazon-web-servicesauthenticationaws-sdkapi-designamazon-cognito

Amazon Cognito: user search as functionality in an App


I have read through the available AWS Cognito docs, but I am not sure if I understand how to best implement a "user search" feature: I want users to be able to search for each other and look at each other's user profiles.

Two specific requirements:

  • Users are only able to search a subset of all users, given by a custom type.
  • Users are able to search by a custom geo hash attribute

How to best approach this? I suppose I need a proxy API service as e.g. searching by custom attributes is not supported by AWS Cognito. But there are many questions:

  • What AWS Api and authentication method should my proxy API use to connect to the AWS Cognito service?
  • should the proxy API just try to use the sync feature of Cognito to maintain all users? Unnecessary risk?
  • are the Cognito APIs SSL enabled by default so that the proxy API can connect safely?
  • Should I use a proxy API at all?

Solution

  • Cognito doesn't expose the attributes each user has publicly, so I'm not sure that approach will work directly. To achieve this end with what Cognito supports already, you would have to mirror the attributes stored against a user elsewhere, either by building your own hooks into update calls from the client or via Lambda. Potentially a bit cleaner is to only store those custom attributes that you need searched elsewhere and leveraging what Cognito supports whenever possible.

    Update with more specific details, per request:

    A rough outline that comes to mind:

    1) Client side, once update attributes is called you build in a new hook that will update some remote data store (Elastisearch, Dynamo...etc.).

    2) This data store should probably be backed by API gateway, using the Cognito access token as an authentication mechanism around it.

    3) Another API to query this data store could be built in to API gateway as well, using the same authentication mechanism.

    4) Queries would then go to this API and could be wrapped into whatever language or capabilities the storage has.

    With this, it also allows you to build custom logic on who has access to what.