From 138ba34f874ecb07d630d026977edd4d16a3ee59 Mon Sep 17 00:00:00 2001 From: Krishan Thisera Date: Thu, 19 Oct 2023 16:56:34 +1030 Subject: [PATCH 1/3] DO-1545: Prerender Fargate Readme update --- packages/prerender-fargate/README.md | 131 +++++++++++++++++++++++---- 1 file changed, 113 insertions(+), 18 deletions(-) diff --git a/packages/prerender-fargate/README.md b/packages/prerender-fargate/README.md index 97c9cae6..421def93 100644 --- a/packages/prerender-fargate/README.md +++ b/packages/prerender-fargate/README.md @@ -1,18 +1,113 @@ -# Prerender in Fargate - -A construct to host [Prerender](https://github.com/prerender/prerender) in Fargate. - -## Props - -- `prerenderName`: Name of the Prerender service -- `domainName`: Domain name for Prerender -- `vpcId`: VPC to host Prerender in -- `bucketName`: Optional S3 bucket name -- `expirationDays`: Optional days until items expire in bucket (default to 7 days) -- `tokenList`: List of tokens to accept as authentication -- `certificateArn`: Certificate arn to match the domain -- `desiredInstanceCount`: Number of Prerender instances to run (default 1) -- `maxInstanceCount`: Maximum number of Prerender instances to run (default 2) -- `instanceCPU`: CPU to allocate to each instance (default 512) -- `instanceMemory`: Amount of memory to allocate to each instance (default 1024) -- `enableRedirectCache`: Cache 301 and 302 responses, too (default false) +# PrerenderFargate Construct + +The PrerenderFargate construct sets up an AWS Fargate service to run a [Prerender] service in an ECS Fargate cluster. + +The Prerender server listens for an HTTP request, takes the URL, and loads it in Headless Chrome, waits for the page to finish loading, and then returns your content to the requesting client. + +## AWS Resources Created/Configured by this Construct + +- **S3 Bucket:** For storing prerendered web pages. +- **Fargate Service:** For running the Prerender service. +- **ECR Asset:** For managing the Docker image of the Prerender service. +- **VPC & VPC Endpoints:** For network configuration and enabling direct access to S3. +- **Recache API:** (optional) To trigger recaching of URLs. + +## Usage and PrerenderFargateOptions + +To use the PrerenderFargate construct, you can instantiate it with suitable PrerenderFargateOptions and place it within a CDK stack. The PrerenderOptions parameter allows the developer to customize various aspects of the Prerender service. + +### `prerenderName` (string) + +- The name of the Prerender service. + +### `domainName` (string) + +- The domain name to prerender. + +### `vpcId` (string, optional) + +- The ID of the VPC to deploy the Fargate service in. + +### `bucketName` (string, optional) + +- The name of the S3 bucket to store prerendered pages in. + +### `expirationDays` (number, optional) + +- The number of days to keep prerendered pages in the S3 bucket before expiring them. + +### `tokenList` (Array of strings, deprecated) + +- A list of tokens to use for authentication with the Prerender service. (This parameter is deprecated and will be removed in a future release. Please use the `tokenUrlAssociation` parameter instead. If `tokenUrlAssociation` is provided, `tokenList` will be ignored.) + +### `certificateArn` (string) + +- The ARN of the SSL certificate to use for HTTPS connections. + +### `desiredInstanceCount` (number, optional) + +- The desired number of Fargate instances to run. + +### `maxInstanceCount` (number, optional) + +- The maximum number of Fargate instances to run. + +### `instanceCPU` (number, optional) + +- The amount of CPU to allocate to each Fargate instance. + +### `instanceMemory` (number, optional) + +- The amount of memory to allocate to each Fargate instance. + +### `enableRedirectCache` (string, optional) + +- Whether to enable caching of HTTP redirects. + +### `enableS3Endpoint` (boolean, optional) + +- Whether to enable the S3 endpoint for the VPC. + +### `tokenUrlAssociation` (PrerenderTokenUrlAssociationOptions, optional) + +- Configuration for associating tokens with specific domain URLs. During the recaching process, these tokens will be used to validate the request. + +## Example + +Here's an example of how to use the PrerenderFargate construct in a TypeScript CDK application: + +```typescript +import { Stack, StackProps } from "aws-cdk-lib"; +import { Construct } from "constructs"; +import { PrerenderFargate, PrerenderFargateOptions } from "@aligent/cdk-prerender-fargate"; + + +export class RagPrerenderStackStack extends Stack { + constructor(scope: Construct, id: string, props: StackProps) { + super(scope, id, props); + + new PrerenderFargate(this, "PrerenderService", { + prerenderName: "myPrerender", + bucketName: "myPrerenderBucket", + expirationDays: 7, + vpcId: "vpc-xxxxxxxx", + desiredInstanceCount: 1, + instanceCPU: 512, + instanceMemory: 1024, + domainName: "prerender.mydomain.com", + certificateArn: + "arn:aws:acm:region:account:certificate/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", + enableRedirectCache: "false", + maxInstanceCount: 2, + enableS3Endpoint: true, + tokenUrlAssociation: { + token1: ["https://example.com", "https://acme.example.com"], + token2: ["https://example1.com", "https:acme.example1.com"], + }, + ssmPathPrefix: "/prerender/recache/tokens", + }); + } +} +``` + +[Prerender]:https://github.com/prerender/prerender From 4f9cba58c9f3cd1a6aeb73cfc810f5b7f65cc3b7 Mon Sep 17 00:00:00 2001 From: Krishan Thisera Date: Thu, 9 Nov 2023 15:04:11 +1030 Subject: [PATCH 2/3] DO-1545: document the default values --- .../prerender-fargate/lib/prerender-fargate-options.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/packages/prerender-fargate/lib/prerender-fargate-options.ts b/packages/prerender-fargate/lib/prerender-fargate-options.ts index 90a81950..8b01991b 100644 --- a/packages/prerender-fargate/lib/prerender-fargate-options.ts +++ b/packages/prerender-fargate/lib/prerender-fargate-options.ts @@ -14,6 +14,7 @@ export interface PrerenderFargateOptions { domainName: string; /** * The ID of the VPC to deploy the Fargate service in. + * @default - The default VPC will be used */ vpcId?: string; /** @@ -22,6 +23,7 @@ export interface PrerenderFargateOptions { bucketName?: string; /** * The number of days to keep prerendered pages in the S3 bucket before expiring them. + * @default - 10 days */ expirationDays?: number; /** @@ -37,30 +39,37 @@ export interface PrerenderFargateOptions { certificateArn: string; /** * The minimum number of Fargate instances to run. + * @default - 1 */ minInstanceCount?: number; /** * The desired number of Fargate instances to run. + * @default - 1 */ desiredInstanceCount?: number; /** * The maximum number of Fargate instances to run. + * @default - 1 */ maxInstanceCount?: number; /** * The amount of CPU to allocate to each Fargate instance. + * @default - 0.5 vCPU */ instanceCPU?: number; /** * The amount of memory to allocate to each Fargate instance. + * @default - 512MB */ instanceMemory?: number; /** * Whether to enable caching of HTTP redirects. + * @default - false */ enableRedirectCache?: string; /** * Whether to enable the S3 endpoint for the VPC. + * @default - false */ enableS3Endpoint?: boolean; /** @@ -91,6 +100,7 @@ export interface PrerenderFargateOptions { /** * Prerender Fargate Re-caching options * This allows to alter the re-caching behavior. The default configuration should be sufficient. + * @default - { maxConcurrentExecutions: 1 } */ prerenderFargateRecachingOptions?: PrerenderFargateRecachingOptions; } From 281a152be6f3f925ed4fed1efa52b38cf098b0fe Mon Sep 17 00:00:00 2001 From: Krishan Thisera Date: Thu, 9 Nov 2023 15:05:52 +1030 Subject: [PATCH 3/3] DO-1545: update the readme and add the Acknowledgments section --- packages/prerender-fargate/README.md | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/packages/prerender-fargate/README.md b/packages/prerender-fargate/README.md index 421def93..12be5ef2 100644 --- a/packages/prerender-fargate/README.md +++ b/packages/prerender-fargate/README.md @@ -52,6 +52,10 @@ To use the PrerenderFargate construct, you can instantiate it with suitable Prer - The maximum number of Fargate instances to run. +### `minInstanceCount` (number, optional) + +- The minimum number of Fargate instances to run. + ### `instanceCPU` (number, optional) - The amount of CPU to allocate to each Fargate instance. @@ -66,12 +70,20 @@ To use the PrerenderFargate construct, you can instantiate it with suitable Prer ### `enableS3Endpoint` (boolean, optional) -- Whether to enable the S3 endpoint for the VPC. +- Whether to enable the [VPC endpoint](https://docs.aws.amazon.com/vpc/latest/privatelink/create-interface-endpoint.html) for S3. ### `tokenUrlAssociation` (PrerenderTokenUrlAssociationOptions, optional) - Configuration for associating tokens with specific domain URLs. During the recaching process, these tokens will be used to validate the request. +### `prerenderFargateScalingOptions` (PrerenderFargateScalingOptions, optional) + +- This allows to alter the scaling behavior. The default configuration should be sufficient for most of the cases. + +### `prerenderFargateRecachingOptions` (PrerenderFargateRecachingOptions, optional) + +- This allows to alter the re-caching behavior. The default configuration should be sufficient. + ## Example Here's an example of how to use the PrerenderFargate construct in a TypeScript CDK application: @@ -105,9 +117,23 @@ export class RagPrerenderStackStack extends Stack { token2: ["https://example1.com", "https:acme.example1.com"], }, ssmPathPrefix: "/prerender/recache/tokens", + prerenderFargateRecachingOptions: { + maxConcurrentExecutions: 1, + }, + prerenderFargateScalingOptions: { + healthCheckGracePeriod: 20, + healthCheckInterval: 30, + unhealthyThresholdCount: 3, + scaleInCooldown: 120, + scaleOutCooldown: 60, + }, }); } } ``` +## Acknowledgements + +- [prerender.io](https://prerender.io/) - The Prerender service. + [Prerender]:https://github.com/prerender/prerender