-
Notifications
You must be signed in to change notification settings - Fork 967
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New serverless pattern - CloudFront to APIGW with alternative origin for large uploads #2684
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @interludic2000 requesting a few minor edits and also found 2 test cases that don't seem to pass. Can you please review?
 | ||
|
||
|
||
## Testing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move the CDK setup steps to the Deployment instructions section.
@@ -0,0 +1,130 @@ | |||
# Amazon Cloudfront to APIGW routing to alternative origin for large payloads |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# Amazon Cloudfront to APIGW routing to alternative origin for large payloads | |
# Route large API payloads to alternate origin | |
@@ -0,0 +1,130 @@ | |||
# Amazon Cloudfront to APIGW routing to alternative origin for large payloads | |||
API Gateway has a [payload limit of 10mb](https://docs.aws.amazon.com/apigateway/latest/developerguide/limits.html#http-api-quotas) which cannot be increaed. This pattern shows how to use Lambda@Edge to route client POST request to an alternative origin based on payload size of the POST request or URL. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
API Gateway has a [payload limit of 10mb](https://docs.aws.amazon.com/apigateway/latest/developerguide/limits.html#http-api-quotas) which cannot be increaed. This pattern shows how to use Lambda@Edge to route client POST request to an alternative origin based on payload size of the POST request or URL. | |
Amazon API Gateway has a [payload limit of 10mb](https://docs.aws.amazon.com/apigateway/latest/developerguide/limits.html#http-api-quotas). This pattern shows how to use Lambda@Edge to route client POST request to an alternative origin based on payload size of the POST request. | |
``` | ||
|
||
## How it works | ||
A Cloudfront distribution is created with 2 origins: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A Cloudfront distribution is created with 2 origins: | |
An Cloudfront distribution is created with 2 origins: | |
A Cloudfront distribution is created with 2 origins: | |
An Amazon CloudFront distribution is created with 2 origins: | |
|
||
## How it works | ||
A Cloudfront distribution is created with 2 origins: | ||
* Default Origin - API Gateway with a Lambda Integration that returns stub responses based on HTTP request method. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* Default Origin - API Gateway with a Lambda Integration that returns stub responses based on HTTP request method. | |
* Default Origin - API Gateway with an AWS Lambda Integration returning a stub responses based on HTTP request method. | |
## How it works | ||
A Cloudfront distribution is created with 2 origins: | ||
* Default Origin - API Gateway with a Lambda Integration that returns stub responses based on HTTP request method. | ||
* Custom Origin - A mock HTTP endpoint which sends a response with information from the request. We are using echo.free.beeceptor.com but you can substitue this with other endpoint URLs. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* Custom Origin - A mock HTTP endpoint which sends a response with information from the request. We are using echo.free.beeceptor.com but you can substitue this with other endpoint URLs. | |
* Custom Origin - A mock HTTP endpoint which sends a response with information from the request. We are using echo.free.beeceptor.com but you can use any other endpoint. | |
#### Test 3: | ||
A POST request that CloudFront will route to a custom origin as the payload size is larger than `MAX_FILE_SIZE` defined in `lambda.mjs`. | ||
|
||
`curl https://<CloudFront distribution URL> -i -X POST -F 'data=@largeFile.example` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test fails with the {"message": "POST request processed by API Gateway!"}
response.
|
||
|
||
#### Test 4: | ||
A POST request to a specific URL that CloudFront will route to a custom origin based on the Behaviour defined in `app.py`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test fails with {"message":"Missing Authentication Token"}
|
||
1. Delete the stack | ||
``` | ||
cdk destroy |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
deleting the stack ends with the following error for the Lambda function:
Please see our documentation for Deleting Lambda@Edge Functions and Replicas.
Issue #, if available:
Description of changes:
API Gateway has a payload limit of 10mb which cannot be increased. This pattern shows how to use Lambda@Edge to route POST request to an alternative origin based on payload size of the POST request or URL.
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.