Hey does anyone know what type I should be using f...
# help
n
Hey does anyone know what type I should be using for my API gateway events if i am using cognito identity pool auth like seen in the guide? So far have been using
APIGatewayProxyEventV2
from
@types/aws-lambda
fine, however have been trying to get the identity pool id like seen in the guide using
event.requestContext.authorizer.iam.cognitoIdentity.identityId
however the type seems to not think this field exists (it definitely does). My version is
"@types/aws-lambda": "^8.10.92",
so might be related to that, but figure someone might have some insight into correct version to use if so 🙏
d
There are now derivations of that event. I forget the exact names, but they are like
ApiGatewayProxyWithAuthorizerEventV2
.
n
Ok thanks guys, for any future travellers, my solution looked something like the following, not perfect and could be improved i imagine, but better than before 👌
Copy code
import { APIGatewayProxyEventV2WithRequestContext } from 'aws-lambda';

interface IAMContext {
    accessKey: string,
    accountId: string,
    callerId: string,
    cognitoIdentity: {
      amr: string[],
      identityId: string,
      identityPoolId: string
    },
    principalOrgId: string,
    userArn: string,
    userId: string
}

interface AuthorizerContext {
  accountId: string,
  apiId: string,
  authorizer: {
    iam: IAMContext
  }
}

type EndpointEvent = APIGatewayProxyEventV2WithRequestContext<AuthorizerContext>

export { EndpointEvent }
Where I use EndpointEvent as the type for my APIGateway endpoint events
d
Looks perfect to me.
actually, you can probably use this: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/369ecc516615fb782639bd4d707be43a01c90df4/types/aws-lambda/trigger/api-gateway-proxy.d.ts#L144
interface AuthorizerContext extends APIGatewayEventRequestContextV2 {
n
I did try that one, though found the properties didn't match up with what was being sent through when testing, i.e. doesn't have properties to get
authorizer.iam.cognitoIdentity.identityId
d
I meant to
extend
it, but not the end of the world.
n
Ahh gotcha aha, thanks for the advice with this one Derek, has been super helpful 🙏