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

DO-1545: Prerender Fargate Readme update #1119

Merged
merged 5 commits into from
Nov 10, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
131 changes: 113 additions & 18 deletions packages/prerender-fargate/README.md
Original file line number Diff line number Diff line change
@@ -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.
TheOrangePuff marked this conversation as resolved.
Show resolved Hide resolved

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

Choose a reason for hiding this comment

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

A link to the AWS docs here would be good


### `tokenUrlAssociation` (PrerenderTokenUrlAssociationOptions, optional)

- Configuration for associating tokens with specific domain URLs. During the recaching process, these tokens will be used to validate the request.
TheOrangePuff marked this conversation as resolved.
Show resolved Hide resolved

## 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