Skip to content
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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

interludic2000
Copy link

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.

Copy link
Contributor

@ellisms ellisms left a 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?

![diagram](diagram.png)


## Testing
Copy link
Contributor

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# 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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
A Cloudfront distribution is created with 2 origins:
An Cloudfront distribution is created with 2 origins:
Suggested change
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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* 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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* 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`
Copy link
Contributor

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`.
Copy link
Contributor

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
Copy link
Contributor

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.

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.

3 participants