I have an appsync lambda resolver which will query a postgresql database. Appsync requests are authorized using API keys for unauthorized users and cognito user pools for authorized users. I would like to retrieve identification data from cognito within my lambda resolver when an authenticated user makes a request, but I can't figure out how to do so. To begin, here is my setup for appsync and the lambda resolver:
this.api = new appsync.GraphqlApi(this, "API-NAME", {
name: "API-NAME",
schema: appsync.Schema.fromAsset("graphql/schema.graphql"),
authorizationConfig: {
defaultAuthorization: {
authorizationType: appsync.AuthorizationType.API_KEY,
apiKeyConfig: {
expires: cdk.Expiration.after(cdk.Duration.days(365)),
},
},
additionalAuthorizationModes: [
{
authorizationType: appsync.AuthorizationType.USER_POOL,
userPoolConfig: {
userPool: props.userPool,
},
},
],
},
});
const lambdaDs = this.api.addLambdaDataSource(
"lambdaDatasource",
props.LambdaConnectingGraphqlToDatabase
);
lambdaDs.createResolver({
typeName: "Query",
fieldName: "listUsers",
});
// etc. etc.
Within my lambda resolver, context.identity is undefined even when an authenticated user makes a request. I have tried using a request mapping template within the lambdaDs.createResolver(), but I couldn't figure out how to make this work, or if this is the correct method.
How do I see the authentication data within my lambda resolver? Thank you.