Skip to content

Commit

Permalink
Added support for AWS Lambda response streaming
Browse files Browse the repository at this point in the history
  • Loading branch information
lukeshay committed Oct 10, 2023
1 parent a96a6c4 commit 942d062
Show file tree
Hide file tree
Showing 33 changed files with 1,302 additions and 1,127 deletions.
6 changes: 6 additions & 0 deletions .changeset/cool-plants-behave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@astro-aws/constructs": minor
"@astro-aws/adapter": minor
---

Added support for AWS Lambda response streaming
6 changes: 3 additions & 3 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"cSpell.words": ["astro"],
"cSpell.words": ["astro", "awslambda", "streamify"],
"files.associations": {
"*.mdx": "markdown"
},
"search.exclude": {
"**/.yarn": true,
"**/.pnp.*": true
"**/.pnp.*": true,
"**/.yarn": true
},
"typescript.enablePromptUseWorkspaceTsdk": true,
"typescript.tsdk": "node_modules/typescript/lib"
Expand Down
2 changes: 1 addition & 1 deletion apps/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
},
"dependencies": {
"@astrojs/starlight": "^0.11.0",
"astro": "^3.2.3",
"astro": "^3.2.4",
"sharp": "^0.32.6"
},
"devDependencies": {
Expand Down
1 change: 0 additions & 1 deletion apps/docs/src/content/docs/guides/01-getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ export class HelloCdkStack extends Stack {
super(scope, id, props)

new AstroAWSConstruct(this, "AstroAWSConstruct", {
output: "server",
websiteDir: "../my-astro-project",
})
}
Expand Down
96 changes: 96 additions & 0 deletions apps/docs/src/content/docs/reference/packages/adapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,102 @@ export default defineConfig({
})
```

### SSR Usage

1. Install the package.

```
# Using NPM
npm install -D @astro-aws/adapter
# Using Yarn
yarn add -D @astro-aws/adapter
# Using PNPM
pnpm add -D @astro-aws/adapter
# Using Bun
bun add -D @astro-aws/adapter
```

2. Add the following to your `astro.config.mjs` file.

```js
import { defineConfig } from "astro/config"
import astroAws from "@astro-aws/adapter"

export default defineConfig({
output: "server",
adapter: astroAws({
mode: "ssr",
}),
})
```

### SSR Stream Usage

1. Install the package.

```
# Using NPM
npm install -D @astro-aws/adapter
# Using Yarn
yarn add -D @astro-aws/adapter
# Using PNPM
pnpm add -D @astro-aws/adapter
# Using Bun
bun add -D @astro-aws/adapter
```

2. Add the following to your `astro.config.mjs` file.

```js
import { defineConfig } from "astro/config"
import astroAws from "@astro-aws/adapter"

export default defineConfig({
output: "server",
adapter: astroAws({
mode: "ssr-stream",
}),
})
```

### Edge Usage

1. Install the package.

```
# Using NPM
npm install -D @astro-aws/adapter
# Using Yarn
yarn add -D @astro-aws/adapter
# Using PNPM
pnpm add -D @astro-aws/adapter
# Using Bun
bun add -D @astro-aws/adapter
```

2. Add the following to your `astro.config.mjs` file.

```js
import { defineConfig } from "astro/config"
import astroAws from "@astro-aws/adapter"

export default defineConfig({
output: "server",
adapter: astroAws({
mode: "edge",
}),
})
```

## Example

See [the source code of this site](https://github.com/lukeshay/astro-aws/blob/main/apps/www/astro.config.ts)
Expand Down
82 changes: 1 addition & 81 deletions apps/docs/src/content/docs/reference/packages/constructs.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ description: "NPM package @astro-aws/constructs"

Constructs for deploying your [Astro](https://astro.build/) project that is built using [@astro-aws/adapter](https://www.npmjs.com/package/@astro-aws/adapter).

## SSR Usage
## Usage

1. Install this package and it's peer dependencies in your AWS CDK project.

Expand Down Expand Up @@ -38,85 +38,6 @@ export class MyAstroStack extends Stack {
super(scope, id, props)

new AstroAWS(this, "AstroAWS", {
output: "server",
websitePath: "..", // Replace with the path to your website code.
})
}
}
```

## SSR Edge Usage

1. Install this package and it's peer dependencies in your AWS CDK project.

```sh
# Using NPM
npm install @astro-aws/constructs constructs aws-cdk-lib

# Using Yarn
yarn add @astro-aws/constructs constructs aws-cdk-lib

# Using PNPM
pnpm add @astro-aws/constructs constructs aws-cdk-lib

# Using Bun
bun add @astro-aws/constructs constructs aws-cdk-lib
```

2. Add the construct to your CDK stack.

```ts
import { Stack } from "aws-cdk-lib/core"
import type { StackProps } from "aws-cdk-lib/core"
import { AstroAWS } from "@astro-aws/constructs"

export interface MyAstroStackProps extends StackProps {}

export class MyAstroStack extends Stack {
public constructor(scope: Construct, id: string, props: MyAstroStackProps) {
super(scope, id, props)

new AstroAWS(this, "AstroAWS", {
output: "edge",
websitePath: "..", // Replace with the path to your website code.
})
}
}
```

## Static Usage

1. Install this package and it's peer dependencies in your AWS CDK project.

```sh
# Using NPM
npm install @astro-aws/constructs constructs aws-cdk-lib

# Using Yarn
yarn add @astro-aws/constructs constructs aws-cdk-lib

# Using PNPM
pnpm add @astro-aws/constructs constructs aws-cdk-lib

# Using Bun
bun add @astro-aws/constructs constructs aws-cdk-lib
```

2. Add the construct to your CDK stack.

```ts
import { Stack } from "aws-cdk-lib/core"
import type { StackProps } from "aws-cdk-lib/core"
import { AstroAWS } from "@astro-aws/constructs"

export interface MyAstroStackProps extends StackProps {}

export class MyAstroStack extends Stack {
public constructor(scope: Construct, id: string, props: MyAstroStackProps) {
super(scope, id, props)

new AstroAWS(this, "AstroAWS", {
output: "static",
websitePath: "..", // Replace with the path to your website code.
})
}
Expand Down Expand Up @@ -144,7 +65,6 @@ export class MyAstroStack extends Stack {
memorySize: 1024,
},
},
output: "server",
websitePath: "..", // Replace with the path to your website code.
})

Expand Down
26 changes: 13 additions & 13 deletions apps/infra/cdk.json
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
{
"app": "node --enable-source-maps --es-module-specifier-resolution node dist/bin/infra.js",
"context": {
"@aws-cdk-containers/ecs-service-extensions:enableDefaultLogDriver": true,
"@aws-cdk/aws-apigateway:disableCloudWatchRole": true,
"@aws-cdk/aws-apigateway:usagePlanKeyOrderInsensitiveId": true,
"@aws-cdk/core:stackRelativeExports": true,
"@aws-cdk/aws-rds:lowercaseDbIdentifier": true,
"@aws-cdk/aws-lambda:recognizeVersionProps": true,
"@aws-cdk/aws-lambda:recognizeLayerVersion": true,
"@aws-cdk/aws-cloudfront:defaultSecurityPolicyTLSv1.2_2021": true,
"@aws-cdk-containers/ecs-service-extensions:enableDefaultLogDriver": true,
"@aws-cdk/aws-codepipeline:crossAccountKeyAliasStackSafeResourceName": true,
"@aws-cdk/aws-ec2:uniqueImdsv2TemplateName": true,
"@aws-cdk/core:checkSecretUsage": true,
"@aws-cdk/aws-iam:minimizePolicies": true,
"@aws-cdk/aws-ecs:arnFormatIncludesClusterName": true,
"@aws-cdk/core:validateSnapshotRemovalPolicy": true,
"@aws-cdk/aws-codepipeline:crossAccountKeyAliasStackSafeResourceName": true,
"@aws-cdk/aws-iam:minimizePolicies": true,
"@aws-cdk/aws-lambda:recognizeLayerVersion": true,
"@aws-cdk/aws-lambda:recognizeVersionProps": true,
"@aws-cdk/aws-rds:lowercaseDbIdentifier": true,
"@aws-cdk/aws-s3:createDefaultLoggingPolicy": true,
"@aws-cdk/aws-sns-subscriptions:restrictSqsDescryption": true,
"@aws-cdk/aws-apigateway:disableCloudWatchRole": true,
"@aws-cdk/core:checkSecretUsage": true,
"@aws-cdk/core:enablePartitionLiterals": true,
"@aws-cdk/core:target-partitions": ["aws", "aws-cn"]
"@aws-cdk/core:stackRelativeExports": true,
"@aws-cdk/core:target-partitions": ["aws", "aws-cn"],
"@aws-cdk/core:validateSnapshotRemovalPolicy": true
},
"watch": {
"include": ["**"],
"exclude": [
"README.md",
"cdk*.json",
Expand All @@ -32,6 +31,7 @@
"yarn.lock",
"node_modules",
"test"
]
],
"include": ["**"]
}
}
12 changes: 11 additions & 1 deletion apps/infra/src/lib/constants/environments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const Environments = {
PERSONAL: "PERSONAL",
PROD: "PROD",
SSR: "SSR",
STREAM: "STREAM",
} as const

type Environment = (typeof Environments)[keyof typeof Environments]
Expand All @@ -33,7 +34,7 @@ const ENVIRONMENT_PROPS: Record<Environment, AstroAWSStackProps> = {
[Environments.EDGE]: {
...base,
alias: "edge.dev",
edge: true,
distDir: "dist/edge",
env: {
...base.env,
region: "us-east-1",
Expand All @@ -56,10 +57,19 @@ const ENVIRONMENT_PROPS: Record<Environment, AstroAWSStackProps> = {
[Environments.SSR]: {
...base,
alias: "ssr.dev",
distDir: "dist/ssr",
environment: Environments.SSR,
hostedZoneName: "astro-aws.org",
package: "@astro-aws/examples-base",
},
[Environments.STREAM]: {
...base,
alias: "stream.dev",
distDir: "dist/ssr-stream",
environment: Environments.STREAM,
hostedZoneName: "astro-aws.org",
package: "@astro-aws/examples-base",
},
} as const

export { Environments, ENVIRONMENT_PROPS, type Environment }
Loading

0 comments on commit 942d062

Please sign in to comment.