oliver
10/02/2021, 11:27 AMMichaelHindley
10/02/2021, 4:04 PMsever_lambda.js
contains all the typescript code. I use type-grapql and the type-graphql-prisma plugin. I package this with esbuild by requiring all the generated prisma files in the entrypoint.
Then I have this deploy.sh
script:
#!/usr/bin/env bash
rm -rf build
ts-node build.ts
mkdirp -p ./build/node_modules/
cp -r ./node_modules/.prisma ./build/node_modules/
rm ./build/node_modules/.prisma/client/libquery_engine-darwin.dylib.node
cd aws && AWS_PROFILE=profile npx cdk deploy
MichaelHindley
10/02/2021, 4:06 PMMichaelHindley
10/02/2021, 4:06 PMbuild.ts
file:
import { build } from 'esbuild'
import { esbuildDecorators } from '@anatine/esbuild-decorators'
async function myBuilder(
tsconfig?: string,
entryPoints?: string[],
outfile?: string,
cwd: string = process.cwd()
) {
const buildResult = await build({
platform: 'node',
target: 'node14',
bundle: true,
plugins: [
esbuildDecorators({
tsconfig,
cwd,
}),
],
tsconfig,
entryPoints: ['server_lambda.ts'],
outfile: './build/server_lambda.js',
external: [
// This is likely to be your friend...
],
})
console.log(buildResult)
}
myBuilder().then(() => {
console.log('done')
})
MichaelHindley
10/02/2021, 4:09 PMserver_lambda.ts
file is just a apollo-server-lambda
compatible entrypoint that also inits the prisma-client and imports all the resolvers and other dependencies so that esbuild can package it cleanly.MichaelHindley
10/02/2021, 4:11 PMimport * as cdk from '@aws-cdk/core'
import * as path from 'path'
import * as lambda from '@aws-cdk/aws-lambda'
import * as apiGateway from '@aws-cdk/aws-apigatewayv2'
import { LambdaProxyIntegration } from '@aws-cdk/aws-apigatewayv2-integrations'
export class HttpApiStack extends cdk.Stack {
constructor(scope: <http://cdk.App|cdk.App>, id: string, props?: cdk.StackProps) {
super(scope, id, props)
const handler = new lambda.Function(this, 'api', {
runtime: lambda.Runtime.NODEJS_14_X,
code: lambda.Code.fromAsset(path.join(__dirname, '../../build')),
handler: 'server_lambda.graphqlHandler',
timeout: cdk.Duration.seconds(10),
memorySize: 512,
environment: {
DATABASE_URL: 'connection string for prisma here',
},
})
const apiIntegration = new LambdaProxyIntegration({
handler
})
const httpApi = new apiGateway.HttpApi(this, 'apigateway')
httpApi.addRoutes({
path: '/{proxy+}',
integration: apiIntegration,
})
}
}
MichaelHindley
10/02/2021, 4:12 PMMichaelHindley
10/02/2021, 4:13 PMMichaelHindley
10/02/2021, 4:16 PMprisma.schema
you need to add this:
binaryTargets = ["native", "rhel-openssl-1.0.x"]
under your generator
configMichaelHindley
10/02/2021, 4:17 PMChris Tsongas
10/03/2021, 9:01 PM