Skip to content

Instantly share code, notes, and snippets.

@GREsau
Last active March 6, 2021 19:29
Show Gist options
  • Save GREsau/444c7d4d0bb9e8c82dd1a585931028bd to your computer and use it in GitHub Desktop.
Save GREsau/444c7d4d0bb9e8c82dd1a585931028bd to your computer and use it in GitHub Desktop.

Summary

  • The requestContext.path property always contains the original "real" path, including any configured base path and/or API stage. In other words, if the request had come from a web browser, then the requestContext.path would be the full URL path in the user's address bar.
  • The top-level path property is identical to requestContext.path when the request is made to a custom domain, but when the request is made to the execute-api URL, path differs in that it does not contain the API stage.

Default (execute-api) API Gateway URL, stage specified in path

https://abcdef1234.execute-api.eu-west-1.amazonaws.com/default/foo/bar/

{
  "resource": "/{proxy+}",
  "path": "/foo/bar/",
  "headers": {
    "Host": "abcdef1234.execute-api.eu-west-1.amazonaws.com"
  },
  "pathParameters": {
    "proxy": "foo/bar"
  },
  "requestContext": {
    "resourcePath": "/{proxy+}",
    "path": "/default/foo/bar/",
    "stage": "default"
  }
}

Custom Domain, always using "default" Stage

https://example.com/foo/bar/

{
  "resource": "/{proxy+}",
  "path": "/foo/bar/",
  "headers": {
    "Host": "example.com"
  },
  "pathParameters": {
    "proxy": "foo/bar"
  },
  "requestContext": {
    "resourcePath": "/{proxy+}",
    "path": "/foo/bar/",
    "stage": "default"
  }
}

Custom Domain with static Base Path "echo", always using "default" Stage

https://example.com/echo/foo/bar/

{
  "resource": "/{proxy+}",
  "path": "/echo/foo/bar/",
  "headers": {
    "Host": "example.com"
  },
  "pathParameters": {
    "proxy": "foo/bar"
  },
  "requestContext": {
    "resourcePath": "/{proxy+}",
    "path": "/echo/foo/bar/",
    "stage": "default"
  }
}

Custom Domain, stage specified in path

https://example.com/default/foo/bar/

{
  "resource": "/{proxy+}",
  "path": "/default/foo/bar/",
  "headers": {
    "Host": "example.com"
  },
  "pathParameters": {
    "proxy": "foo/bar"
  },
  "requestContext": {
    "resourcePath": "/{proxy+}",
    "path": "/default/foo/bar/",
    "stage": "default"
  }
}

Custom Domain with static Base Path set to "echo", stage specified in path

https://example.com/echo/default/foo/bar/

{
  "resource": "/{proxy+}",
  "path": "/echo/default/foo/bar/",
  "headers": {
    "Host": "example.com"
  },
  "pathParameters": {
    "proxy": "foo/bar"
  },
  "requestContext": {
    "resourcePath": "/{proxy+}",
    "path": "/echo/default/foo/bar/",
    "stage": "default"
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment