Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Not able to send aws $context variable data in header - http proxy

I am using aws api gateway to send a http proxy to my server - if the user is authenticated, and need to send the user's username to my server for identification purpose.

if I use the $context variable in body mapping ($context.authorizer.claims['cognito:username']) then I get the value as required but if i try to use the same in header section then I dont get it. I even try a static header key/value and it works

Here's a snapshot to explain. enter image description here

Please let me know - how do i get the required data in the header section

Note: TO TEST THE FUNCTIONALITY - I HAVE CREATED A NEW ENDPOINT AND SENDING ALL THE REQUEST TO A LAMBDA and NOT TO MY SERVER FOR NOW. I tried sending it to my server as well - but both endpoint fails to get the username in header section

like image 469
Abdeali Chandanwala Avatar asked Dec 17 '25 18:12

Abdeali Chandanwala


1 Answers

At last - Got it solved

In the header section - there seems to be some issue with ['cognito:username'] - array syntax - that's why it didn't used to work

It worked with context.authorizer.claims.cognito:username (no single quotes)

and in Body mapping - you still need to use $context.authorizer.claims['cognito:username']

the above header section syntax doesnt work on Body mapping

In Header we need to context.authorizer.claims.cognito:username

In Body MApping we need $context.authorizer.claims['cognito:username']

like image 110
Abdeali Chandanwala Avatar answered Dec 20 '25 19:12

Abdeali Chandanwala