1
votes

We are using AWS API Gateway custom authorize lambda function call to authorize the user call. Its returns policy (if authored) or else returns 401.Its working good. But we are visioning that custom authorize lambda function call should return a new header attribute(flag- true/false) , along with policy . So that we can use that header attribute in ECS API call for distinguish API logic for authored call & Non Authored API.

Can you please advice is this possible to set header parameter , if we make a call to lambda in Custom Authorizes level.

Thanks -

1

1 Answers

1
votes

Custom authorizers return policies back to API Gateway. This policy is accessible in the body mapping template under context.authorizer.propertyname. For example if you wanted to pass the principalId returned from the authorizer as a header, your body mapping template would look like this:

{"principalId" : "$context.authorizer.principalId"}

If you want to pass a property not normally included in the policy, you can just add it within the custom Lambda authorizer. The policy is just a JSON object.

Example in Node.js, if you have created a policy object named aPolicy and want to add a new property called 'new' with the value of 'true', you would add the following lines.

aPolicy.context = {};
aPolicy.context.new = 'true';

Then in your body mapping template in the API Gateway add

{"new" : "$context.authorizer.new"}

Now API Gateway will pass the API request with the header 'new' with the value set in the custom authorizer to your backend.