Reputation: 4474
I have a graphql Api and added a lambda function to resolve a mutation.
type Mutation {
addTeamMember(email: String!, teamId:ID!): String @function(name: "add-team-member-${env}")
}
From the lambda I want to retrieve the authenticated user that sent the request to perform additional validations, ¿How to retrieve it from the request information?
strong text
Upvotes: 2
Views: 703
Reputation: 730
To access event.identity
in lambda resolver, we need to configure the request mapping template as below.
{
"version": "2017-02-28",
"operation": "Invoke",
"payload": {
"args": $utils.toJson($context.args),
"identity": $utils.toJson($context.identity)
}
}
Note: The identity field isn't populated if you use API_KEY authorization.
References: https://docs.aws.amazon.com/appsync/latest/devguide/resolver-context-reference.html
Upvotes: 0
Reputation: 4474
I printed the contents of the first lambda parameter and found it:
Access it with:
event.identity.username
Upvotes: 4