AWS LAMBDA - Invalid `photon.() EROFS: read-only file system, chmod '/var/task/.../query-engine-rhel-openssl-1.0.x'
I am trying to use photon within my aws lambda functions. I am bundling the generated photon package within my node_modules. In my lambda code, I am initializing my Photon client using this function, in order to determine database during runtime:
import { Photon } from '@prisma/photon';
export const getPhoton = (prismaDbUrl: string): Photon =>
new Photon({
datasources: {
db: prismaDbUrl
}
});
However I receive an error when I try to query database using photon. Below is result of my lambda function
{
"errorType": "Error",
"errorMessage": "\nInvalid `photon.()` invocation in /var/task/node_modules/@prisma/photon/index.js:2159:44\n\n\n\nEROFS: read-only file system, chmod '/var/task/node_modules/@prisma/photon/runtime/query-engine-rhel-openssl-1.0.x'",
"trace": [
"Error: ",
"Invalid `photon.()` invocation in /var/task/node_modules/@prisma/photon/index.js:2159:44",
"",
"",
"",
"EROFS: read-only file system, chmod '/var/task/node_modules/@prisma/photon/runtime/query-engine-rhel-openssl-1.0.x'",
" at PhotonFetcher.<anonymous> (/var/task/node_modules/@prisma/photon/index.js:63:31)",
" at Generator.throw (<anonymous>)",
" at rejected (/var/task/node_modules/@prisma/photon/index.js:6:65)"
]
}
It is not possible to run chmod within aws lambda (except in /tmp). The real question however is: Why does photon need to run chmod in the first place?
I have inspected the generated photon package a bit, but I still cannot figure out, why does photon need to run chmod on the query engine, or how to solve this problem.
Prisma2 version:
2.0.0-preview019
Photon version:
2.0.0-preview019
Note: I am unable to upgrade to the newest version, since I am also using nexus-prisma plugin
Related issue: https://github.com/prisma/prisma2/issues/1170
Just to make sure can you please confirm that you are not deploying to lambda via zeit.co and it is a direct deployment.
Related issue: prisma/prisma2#1170
Just to make sure can you please confirm that you are not deploying to lambda via zeit.co and it is a direct deployment.
Yep direct deployment. I am using serverless framework to deploy
@simonobe Can you please share your serverless.yml file 🙏 ?
Related: https://github.com/prisma/prisma2/issues/1383
@simonobe Can you please share your serverless.yml file 🙏 ?
sorry did not see this comment before. I can share you some parts, but probably not all of it. Can you please tell me, which part of serverless config you would like to see? Moreover, I do not see how serverless.yml is of any relevance. I can tell you how we bundle our code, as that seems more relevant to me.
We are using webpack to bundle our code.
However each time we rebuild with webpack, we are also rebuilding node externals. That means that after webpack builds our package (but before we zip it), we reinitialize the photon package (without 'native' binary target, since this would only bloat the package - btw the package is over 100MB, can something be done to reduce that?).
In order to execute reinitialization of the photon package, we use our custom serverless plugin to hook into the process of package building.
Nevertheless, if we look at the error, it is clear to see where the problem is. AWS Lambda environment does not allow to execute chmod command, which alters /var/task directory, which is exactly what PhotonFetcher seems to be doing. Can you please help me understand, why does chmod needs to be executed in the first place?
EDIT: It is also worth mentioning, that we are doing the bundling on windows machines. Is it possible that the query-engine executable does not have sufficient permissions for linux, when I generate the package on windows? And then the PhotonFetcher tries to correct this during the runtime, but fails, since it is forbidden to use chmod in lambda?
Yeah, I asked for it because I wanted to know if there are any build steps as you have mentioned.
Now can you please share the generator section of your schema. I want to see what you have in your binaryTargets property, either it is specified or not
Yeah, I asked for it because I wanted to know if there are any build steps as you have mentioned.
Now can you please share the generator section of your schema. I want to see what you have in your binaryTargets property, either it is specified or not
this is the generator from schema I use
generator photon {
provider = "photonjs"
binaryTargets = [ "rhel-openssl-1.0.x"]
output = "build/serverless/service/node_modules/@prisma/photon"
}
@pantharshit00 were you able to go through the issue? generally speaking are there any people who are succesfuly using photon on AWS?
This is being caused by building locally with output on Windows, then uploading to run on a Linux environment: https://github.com/prisma/prisma-client-js/issues/476
Maybe we can close this in favour of #476 as we have identified the problem there.
cc @janpio
Done, and linked to this issue as "more information".