Skip to content

Commit

Permalink
feat: provide aws proxy handler
Browse files Browse the repository at this point in the history
  • Loading branch information
tom-fletcher committed Dec 13, 2022
1 parent 65a42ec commit 9dcf280
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 14 deletions.
23 changes: 9 additions & 14 deletions docs/running-in-lambda.md
Expand Up @@ -67,25 +67,20 @@ created. Click on **Create function**.

### Handler code

The Lambda handler will need the packages `@fastify/aws-lambda` and
`turborepo-remote-cache` installed. Your `index.js` handler code should look
like this:
Create a new package for your Lambda handler, and add `turborepo-remote-cache`
as a dependency. Your `index.js` handler code should look like this:

```js
import awsLambdaFastify from '@fastify/aws-lambda';
import { createApp } from 'turborepo-remote-cache/build/app';

const app = createApp({
trustProxy: true,
});
export { handler } from 'turborepo-remote-cache/build/aws-lambda';
```

const proxy = awsLambdaFastify(app, { enforceBase64: (_) => true });
*Note - You will need to bundle dependencies and upload the handler code. How
you choose to do this is outside the scope of this guide, but one method to
consider is using `esbuild`:*

export const handler = proxy;
```

*Note - how you choose to bundle dependencies and upload the handler code are
outside the scope of this document.*
esbuild src/index.js --bundle --platform=node --outfile=build/index.js
```

### Configuration

Expand Down
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -32,6 +32,7 @@
},
"dependencies": {
"@commitlint/lint": "^17.2.0",
"@fastify/aws-lambda": "^3.1.3",
"@google-cloud/storage": "6.4.1",
"@hapi/boom": "9.1.4",
"@sinclair/typebox": "0.23.1",
Expand Down
6 changes: 6 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions src/aws-lambda.ts
@@ -0,0 +1,9 @@
import awsLambdaFastify from '@fastify/aws-lambda'
import { createApp } from './app'

const app = createApp({
trustProxy: true,
})

// eslint-disable-next-line @typescript-eslint/no-unused-vars
export const handler = awsLambdaFastify(app, { enforceBase64: _ => true })

0 comments on commit 9dcf280

Please sign in to comment.