'Getting user ID in lambda function (go 1.x) from AWS API Gateway
I updated the API (rest) via the amplify CLI to add a path and function (go 1.x), and within the function, I was able to retrieve the user ID via the following:
event.RequestContext.Identity.CognitoAuthenticationProvider
and this worked just fine.
I repeated the same steps above, however, when trying to retrieve the user id (sub) from the same as above, nothing is being retrieved. I'm not sure why, I've checked API gateway, and the settings seem to be the same, but maybe I'm missing something?
Any idea how to get the user id/sub in the function?
further info:
When accessing the "invoke URL" for the former function, an error message shows:
{"message":"Missing Authentication Token"}
However, this is not the case when accessing the invoke URL for the latter function. The latter function is not expecting an authentication token, how can that be changed?
EDIT: as requested, the JSON response for event.RequestContext:
{
"accountId": "000000000000",
"resourceId": "00aaaa",
"stage": "dev",
"domainName": "a00aaaaa00.execute-api.eu-west-2.amazonaws.com",
"domainPrefix": "a00aaaaa00",
"requestId": "000aa0a0-000a-0000-0000-aa0000a00aaa",
"protocol": "HTTP/1.1",
"identity": {
"cognitoIdentityPoolId": "",
"accountId": "",
"cognitoIdentityId": "",
"caller": "",
"apiKey": "",
"apiKeyId": "",
"accessKey": "",
"sourceIp": "00.000.000.000",
"cognitoAuthenticationType": "",
"cognitoAuthenticationProvider": "",
"userArn": "",
"userAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.54 Safari/537.36",
"user": ""
},
"resourcePath": "/xxxxpath",
"path": "/dev/xxxxpath",
"authorizer": null,
"httpMethod": "POST",
"requestTime": "14/May/2022:23:09:05 +0000",
"requestTimeEpoch": 1652569745072,
"apiId": "a00aaaaa00"
}
Thanks
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
