Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

268
Views
Amplify get owner user attributes from Cognito

Background: I'm using Amplify to create a type Item @model GraphQL datastore with an @auth allow owner which adds the owner as an CognitoID to the Item.

Question: This item is readable for guests and I would like to show the owner (or other related metadata such as a username/email) for this item.

e.g. Cognito.GetUserAttributes(2b10fb7e-4472-43c9-9bb9-54219b5027a3)

Is somthing like this possible? How is this supposed to be designed for this use case? Do I have to add a lambda that adds the user meta data to the item when it is created?

I would like this solution to be scalable.


The schema:

type Item
@model
@auth(rules: [
    { allow: owner},
    { allow: groups, groups: ["Admin"] },
    { allow: private, operations: [read] },
    { allow: public, operations: [read] }
])
{
    id: ID!
    title: String!
    description: String
}

From DynamoDB:

{
  "__typename": "Item",
  "_lastChangedAt": 1593707126605,
  "_version": 1,
  "createdAt": "2020-07-02T16:25:26.582Z",
  "description": "Description",
  "id": "0592fcd8-408e-406e-84bf-9f63eb43e147",
  "owner": "2b10fb7e-4472-43c9-9bb9-54219b5027a3",
  "title": "Item",
  "updatedAt": "2020-07-02T16:25:26.582Z"
}
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You can use a function resolver on a cognitoAttributes field. The lambda function can call admin-get-user in Cognito and return the attributes. The lambda function will receive the dynamo Item in the event.source property so you will have access to the owner id to make the call to Cognito.

type Item
@model
@auth(rules: [
    { allow: owner},
    { allow: groups, groups: ["Admin"] },
    { allow: private, operations: [read] },
    { allow: public, operations: [read] }
])
{
    id: ID!
    title: String!
    cognitoAttributes: [String]! @function('cognitoGetUserAttributes-${env})
    description: String
}
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!