Reputation: 23
I have used AWS IAM Authentication in my API to authorize each request. Now I want the User Name of the authenticated request of the users. For example, one user makes a request to my API and he is already authorized(IAM Entry) then I want the user name or API key of that user. Have any idea?
Upvotes: 0
Views: 205
Reputation: 8603
I just did a test for you. The lambda received the following event.
{
...
"body": null,
"resource": "/",
"requestContext": {
"identity": {
"userArn": "arn:aws:iam::561819318197:user/testadmin",
"cognitoAuthenticationType": null,
"principalOrgId": null,
"accessKey": "AKIAABTYKO625OKJWL65",
"caller": "AIDAYFTYKO62TO35WYOWZ",
"userAgent": "PostmanRuntime/7.6.0",
"user": "AIDAYFTCDO62TO35WYOWZ",
"cognitoIdentityPoolId": null,
"cognitoIdentityId": null,
"cognitoAuthenticationProvider": null,
"sourceIp": "[user ip]",
"accountId": "123456789012"
},
"accountId": "123456789012"
}
...
}
I think you can use the event.requestContext.user
.
Hope you find this helpful.
Upvotes: 3