diff --git a/docs/running-in-lambda.md b/docs/running-in-lambda.md index 97bfc2fc..9be7d33b 100644 --- a/docs/running-in-lambda.md +++ b/docs/running-in-lambda.md @@ -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 diff --git a/package.json b/package.json index 6ebce524..e28f96f8 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index bd581466..d827f150 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -6,6 +6,7 @@ specifiers: '@commitlint/lint': ^17.2.0 '@commitlint/prompt': ^17.1.2 '@cspotcode/source-map-support': ^0.7.0 + '@fastify/aws-lambda': ^3.1.3 '@google-cloud/storage': 6.4.1 '@hapi/boom': 9.1.4 '@semantic-release/changelog': ^6.0.1 @@ -60,6 +61,7 @@ specifiers: 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 @@ -540,6 +542,10 @@ packages: ajv: 6.12.6 dev: false + /@fastify/aws-lambda/3.1.3: + resolution: {integrity: sha512-5bE17UqQlzja83XIOEvE0pNoDidbfNVu7R+DGus2uFECIg1m0o77XnRCEd9pzuP7ZOQmiRLrQdcET9ki+hSaVw==} + dev: false + /@google-cloud/paginator/3.0.7: resolution: {integrity: sha512-jJNutk0arIQhmpUUQJPJErsojqo834KcyB6X7a1mxuic8i1tKXxde8E69IZxNZawRIlZdIK2QY4WALvlK5MzYQ==} engines: {node: '>=10'} diff --git a/src/aws-lambda.ts b/src/aws-lambda.ts new file mode 100644 index 00000000..35aff84e --- /dev/null +++ b/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 })