API Gateway custom domain with base path missing from request

0

I have created a custom domain in API Gateway and assigned it to a lambda proxy with a base path so that the root URI looks like "https://myapp.mycompany.com/mybasepath/". However, when inspecting the request object inside the lambda, I can't find any clue of "mybasepath" (Host is "myapp.mycompany.com" and path is "/"). How can I find out the original URI the API was called with?

preguntada hace 2 años1467 visualizaciones
6 Respuestas
0

According to the documentation the domain name and path should be part of the requestContext object.

{
  "resource": "/my/path",
  "path": "/my/path",
  "httpMethod": "GET",
  "headers": {
    "header1": "value1",
  },
  ...
  },
  "requestContext": {
    "accountId": "123456789012",
    "domainName": "id.execute-api.us-east-1.amazonaws.com",
    "path": "/my/path",
    ...
  }, 
  ...
}

Could you post the complete event object that gets passed to your Lambda function?

profile pictureAWS
EXPERTO
respondido hace 2 años
AWS
EXPERTO
Hernito
revisado hace 2 años
0

The root of the API definition for a deployed stage will be /. If you want to define paths within your API definition you will need to create new resources for each path, then add your methods under each.

So a new resource "Foo" will have a defintion for methods POST. Then the API URI would be "https://myapp.mycompany.com/mybasepath/Foo" which when you look in the Lambda function will show "path: 'Foo'"

AWS
respondido hace 2 años
0

Regarding to the host you should look at the Origin or Referer headers. Regarding to the the path resource you can look at the resourcePath attribute inside RequestContext object.

This is an example of RequestContext from one of our lambdas:

[accountId=0000000000, additionalProperties={}, apiId=s4f16syio4, httpMethod=POST, identity=Identity [accountId=null, additionalProperties={}, apiKey=null, caller=null, cognitoAuthenticationProvider=null, cognitoAuthenticationType=null, cognitoIdentityId=null, cognitoIdentityPoolId=null, sourceIp=X..X.X.X, user=null, userAgent=Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.55 Safari/537.36, userArn=null], requestId=52d92640-9966-4671-a19d-20f018551d65, resourceId=6t3yjm, resourcePath=/graphql, stage=beta, path=/profile/graphql, authorizer=Authorizer{claims={sub=0d2c9c55-1602-4a46-81a6-ea32398bfcb8, email_verified=true, iss=https://cognito-idp.us-east-1.amazonaws.com/us-east-HHHHHHHH, cognito:username=email@host.com, origin_jti=6c269796-0004-4079-b41b-015f78eaafad, aud=3p0v8km6ogo63s59q8gnv5iaet, event_id=61fc1dbf-d02d-4fb6-b062-3795dd832f78, token_use=id, auth_time=1638208343, exp=Mon Nov 29 18:52:23 UTC 2021, iat=Mon Nov 29 17:52:23 UTC 2021, jti=32205f39-91d6-44c4-8e60-87507a7eba01, email=email@host.com}}]

The attribute path is providing the base path plus the resource path.

Hope this may help.

jgg
respondido hace 2 años
0

Thank you all for your help. First, I forgot to mention that my Lambda is based on .net Core 3.1. But even after deeper digging for the context data I could not find any clue of the base path. Only after switching from HTTP-API back to REST-API, PathBase finally shows '/mybasepath'.

respondido hace 2 años
0

I too having same issue and wondering if anyone has found a way to include the base path into the request coming to "lambda custom authorizer" ? I see the person asked question moved to REST API to solve this problem but in my case i would like to stick to HTTP API

respondido hace 2 años
0

Same issue for http api. I need the basePath in the custom lambda authorizer so I know which api the client is trying to access so I can lookup the permissions.

respondido hace 8 meses

No has iniciado sesión. Iniciar sesión para publicar una respuesta.

Una buena respuesta responde claramente a la pregunta, proporciona comentarios constructivos y fomenta el crecimiento profesional en la persona que hace la pregunta.

Pautas para responder preguntas