import path from "path" ; import fs from "fs-extra" ; import * as lambda from "@aws-cdk/aws-lambda" ; import * as sst from "@serverless-stack/resources" ; export default function ( app ) { new Stack ( app ) ; } class Stack extends sst . Stack { constructor ( scope ) { super ( scope , "Stack" ) ; if ( ! scope . local ) { const layerPath = ".sst/layers/prisma" ; fs . removeSync ( layerPath , { force : true , recursive : true } ) ; fs . mkdirSync ( layerPath , { recursive : true } ) ; const toCopy = [ "node_modules/.prisma" , "node_modules/@prisma/client" , "node_modules/prisma/build" , ] ; for ( const file of toCopy ) { fs . copySync ( file , path . join ( layerPath , "nodejs" , file ) , { filter : ( src ) => ! src . endsWith ( "so.node" ) || src . includes ( "rhel" ) , } ) ; } const prismaLayer = new lambda . LayerVersion ( this , "PrismaLayer" , { code : lambda . Code . fromAsset ( path . resolve ( layerPath ) ) , } ) ; this . addDefaultFunctionLayers ( [ prismaLayer ] ) ; } const api = new sst . Api ( this , "Api" , { defaultFunctionProps : { environment : { DATABASE_URL : scope . local ? "mysql://root@localhost:3306/test" : "mysql://production-url" , } , bundle : { externalModules : scope . local ? [ ] : [ "@prisma/client" , ".prisma" ] , } , } , routes : { "GET /post" : "src/index.handler" , } , } ) ; this . addOutputs ( { api : api . url , } ) ; } }