Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Make Api Gateway custom domain work (with basepath)#32

Merged
sloev merged 7 commits intosloev:mastersloev/python-lambdarest:masterfrom
svdgraaf:feature/make-custom-endpoints-workCopy head branch name to clipboard
Apr 12, 2018
Merged

Make Api Gateway custom domain work (with basepath)#32
sloev merged 7 commits intosloev:mastersloev/python-lambdarest:masterfrom
svdgraaf:feature/make-custom-endpoints-workCopy head branch name to clipboard

Conversation

@svdgraaf
Copy link
Contributor

@svdgraaf svdgraaf commented Apr 6, 2018

When APIGW is setup with a custom domain. The path to the call will include the basepath (if setup). To fix this, we need to check for the resource path which will contain the actual path without the basepath.

This fixes #31

@sloev
Copy link
Owner

sloev commented Apr 9, 2018

when tests are green i can code review it, thanks again for contribution @svdgraaf !

@sloev
Copy link
Owner

sloev commented Apr 9, 2018

after reading up on it, i am not convinced that the resource behaves as mentioned. can you @svdgraaf supply me with a request json output (aws to lambda request object) from both cases, with / without custom domain.

@svdgraaf
Copy link
Contributor Author

svdgraaf commented Apr 9, 2018

Hmmm, let me check and get those for you

@svdgraaf
Copy link
Contributor Author

svdgraaf commented Apr 9, 2018

Without custom domain (see the Host header):

{
	"resource": "/contexts",
	"path": "/contexts/",
	"httpMethod": "GET",
	"headers": {
		"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
		"Accept-Encoding": "gzip, deflate, br",
		"Accept-Language": "en-US,en;q=0.9,nl;q=0.8",
		"cache-control": "max-age=0",
		"CloudFront-Forwarded-Proto": "https",
		"CloudFront-Is-Desktop-Viewer": "true",
		"CloudFront-Is-Mobile-Viewer": "false",
		"CloudFront-Is-SmartTV-Viewer": "false",
		"CloudFront-Is-Tablet-Viewer": "false",
		"CloudFront-Viewer-Country": "NL",
		"Host": "dil4b1[snip].execute-api.eu-west-1.amazonaws.com",
		"upgrade-insecure-requests": "1",
		"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36",
		"Via": "2.0 605e6ba1f1cba02856e68eba7a887943.cloudfront.net (CloudFront)",
		"X-Amz-Cf-Id": "1Q-QBcjKNCXV5GdnzU3z8MI8CSAeX4A0y1Un9CzryWD2fCaH1BAB1Q==",
		"X-Amzn-Trace-Id": "Root=1-5acb33b1-8e557582fb9e8fe9ecd61c7f",
		"X-Forwarded-For": "85.119.108.158, 54.240.1 [TRUNCATED]

With custom domain:
The endpoint is: https://api.tsentlz[snip].com/v2/contexts/

{
	"resource": "/contexts",
	"path": "/v2/contexts",
	"httpMethod": "GET",
	"headers": {
		"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
		"Accept-Encoding": "gzip, deflate, br",
		"Accept-Language": "en-US,en;q=0.9,nl;q=0.8",
		"cache-control": "max-age=0",
		"CloudFront-Forwarded-Proto": "https",
		"CloudFront-Is-Desktop-Viewer": "true",
		"CloudFront-Is-Mobile-Viewer": "false",
		"CloudFront-Is-SmartTV-Viewer": "false",
		"CloudFront-Is-Tablet-Viewer": "false",
		"CloudFront-Viewer-Country": "NL",
		"Host": "api.tsentlz[snip].com",
		"upgrade-insecure-requests": "1",
		"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36",
		"Via": "2.0 e7ce333c56f455a0dae7f1f5ea5d6086.cloudfront.net (CloudFront)",
		"X-Amz-Cf-Id": "xbc76lD0RKn6DADJ6mLHaWAu8xbGFdycyF-9xRMcui17n0WJtDsBPQ==",
		"X-Amzn-Trace-Id": "Root=1-5acb33b0-4d288d542c2d8ee06ad2f014",
		"X-Forwarded-For": "85.119.108.158, 54.182.239.98",
		"X-Forwarded-Port" [TRUNCATED]

@svdgraaf
Copy link
Contributor Author

svdgraaf commented Apr 9, 2018

Do you have any links where you read about the resource not being correct to use? Because then we need to figure something else out to make this compatible

@sloev
Copy link
Owner

sloev commented Apr 9, 2018

from what you have shown it looks like it should more be:
if not resource == path:
....path=resource

but then why not always resource instead of path?

@sloev
Copy link
Owner

sloev commented Apr 9, 2018

i think what i meant with resource being weird is
"resource": "/{proxy+}",
from
http://www.1strategy.com/blog/2017/06/06/how-to-use-amazon-api-gateway-proxy/

the example shows that you can use some kind of path params in the resource field

@svdgraaf
Copy link
Contributor Author

svdgraaf commented Apr 9, 2018

Yeah, I think we can just default to the resource key. I'll check how that behaves when it is setup with {proxy+}, I think we can make that just default to the catchall, and forward the whole uri as path.

@svdgraaf
Copy link
Contributor Author

Ok, figured it out, and changed things accordingly. As discussed it now uses the resource key. I'm not sure if we want to fallback to path as well, but that's easy to add.

The {proxy+} is now also supported, if that is given in the event, the path parameter "proxy" contains the actual value for that part of the path. So I just replace that with the actual value, and the routing works.

I changed the readme to use resource instead of path, but as suggested above here, perhaps we want to have a fallback to path as well, if so, let me know and I'll add it. The readme can than just have path, which might look more natural for a first introduction.

@sloev
Copy link
Owner

sloev commented Apr 11, 2018

great work @svdgraaf !
some questions:

  1. have you tested it with APIGW? i don't currently have access.
  2. can you bump the version, both in init and setup.py and write the history

(3) i think a fallback is unnecessary, the switch from path to resource should work and not convolute the code with fallbacks.

@svdgraaf
Copy link
Contributor Author

I'm currently testing it with apigw, found a bug, working on it :)

…aaf/python-lambdarest into feature/make-custom-endpoints-work
@svdgraaf
Copy link
Contributor Author

Ok, the bug was my bad :D pebkac. You can test the apigw integration here:

https://api.tsentlzwoot.com/v2/foobar/asdfsdf/asdfsdf/asdfasdf/asdfasdf/

/foobar is setup as /foobar/<path:path>, and it outputs everything it got from the {proxy+} field.

@sloev sloev merged commit 6933090 into sloev:master Apr 12, 2018
sloev pushed a commit that referenced this pull request Apr 12, 2018
* if resource is set in request, use that instead of path

* Added support for the {proxy+} endpoint. Default to "resource" event key

* Cleanup, and added check for start of / in path.

* bump version

* bump version write history

* Fixed bad * path
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Issue with custom domain

2 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.