I am trying to use code from the document `Adding ...
# help
p
I am trying to use code from the document
Adding Lambda authorizatino
(link) While developing locally
sst start
I am returning following data from the authorizer lambda.
Copy code
{
  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)
Copy code
{
  lambda: { booleanKey: 'true', numberKey: '123', stringKey: 'stringval' }
}
Am I missing something, here?
o
Can’t be of much help, but my authorizor response looks like this:
Copy code
{
    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 V2
m
When using APIGWV2 with response format 2.0 the response can be a simple type type or an iam policy. A simple response does not contain
principalId
. You can configure it like:
Copy code
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