Pavan Kumar
11/16/2021, 7:11 AMAdding Lambda authorizatino
(link)
While developing locally sst start
I am returning following data from the authorizer lambda.
{
principalId: 'abc',
policyDocument: { Version: '2012-10-17', Statement: [ [Object] ] },
context: { stringKey: 'stringval', numberKey: 123, booleanKey: true }
}
Event object in api handler should contain principalId in event.requestContext.authorizer.principalId
field. But, the `event.requestContext.authorizer`` object looks like following. (Missing principalId)
{
lambda: { booleanKey: 'true', numberKey: '123', stringKey: 'stringval' }
}
Am I missing something, here?Omi Chowdhury
11/16/2021, 1:34 PM{
principalId: verified.sub,
policyDocument: getPolicyDocument('Allow', params.methodArn),
context,
}
So I think you can probably rule out the syntax being wrong. I assume if the policy doc was invalid, then nothing would work.
And I access the principalId
at the same key and it works for me
The only difference I can think of is that I am using ApiGatewayV1 not V2Mike McCall
11/16/2021, 2:00 PMprincipalId
. You can configure it like:
const defaultAuthorizer = new HttpLambdaAuthorizer({
responseTypes: [HttpLambdaResponseType. SIMPLE,HttpLambdaResponseType.IAM],
resultsCacheTtl: cdk.Duration.seconds(60),
....
})
https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-lambda-authorizer.html