Skip to content

Commit

Permalink
fix(cdk-site-distribution): cloudfront functions rate limit
Browse files Browse the repository at this point in the history
  • Loading branch information
thijsdaniels committed Jul 5, 2024
1 parent 1674686 commit 1c02632
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/tender-zebras-perform.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@codedazur/cdk-site-distribution": patch
---

The CloudFront functions are created in series to reduce the chances of hitting the service rate limit.
16 changes: 14 additions & 2 deletions packages/cdk-site-distribution/src/constructs/SiteDistribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,21 @@ export class SiteDistribution extends Construct {
}

protected createFunctions() {
const viewerRequest = this.createViewerRequestFunction();
const viewerResponse = this.createViewerResponseFunction();

/**
* Although the response function doesn't actually depend on the request
* function, we define a dependency to avoid a service rate limit that may
* occur when both are created simultaneously.
*/
if (viewerRequest && viewerResponse) {
viewerResponse.node.addDependency(viewerRequest);
}

return {
viewerRequest: this.createViewerRequestFunction(),
viewerResponse: this.createViewerResponseFunction(),
viewerRequest,
viewerResponse,
};
}

Expand Down
3 changes: 3 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "@codedazur/tsconfig/base.json"
}

0 comments on commit 1c02632

Please sign in to comment.