-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Store RemoteAuth ZIP files inside dataPath #3375
base: main
Are you sure you want to change the base?
Conversation
@vedantmgoyal9 Storing session or authentication-related data in the /tmp ephemeral storage of AWS Lambda is not recommended. Since the data in /tmp is specific to an instance of a Lambda execution environment, it is not guaranteed to persist across multiple invocations. This could lead to inconsistencies or loss of critical data. A more reliable approach is to leverage AWS S3 for storing such data. S3 provides persistent, scalable, and secure storage, making it an excellent choice for managing session or authentication-related information. You can explore an example implementation using S3 for authentication here: Remote Auth Strategy Using S3. |
Yes, I know that. I store sessions in Firebase Storage, but when "restoring" the session, the library writes to current working directory which is read-only. I have patched it to use /tmp while downloading and decompressing the ZIP file so it does not fail. |
src/authStrategies/RemoteAuth.js
Outdated
@@ -104,7 +105,7 @@ class RemoteAuth extends BaseAuthStrategy { | |||
if (pathExists) { | |||
await this.compressSession(); | |||
await this.store.save({session: this.sessionName}); | |||
await fs.promises.unlink(`${this.sessionName}.zip`); | |||
await fs.promises.unlink(isRunningInAwsLambda() ? `/tmp/${this.sessionName}.zip` : `${this.sessionName}.zip`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not just include one 'remoteSessionPath' that works like dataPath
?
The function 'isRunningInAwsLambda' wont go to production, convert it to an option or make the remoteSessionZipPath to fix your problems
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tuyuribr I think I have solved the issue without adding another option. It would store ZIP files inside the dataPath
instead of the current working directory.
const client = new Client({
authStrategy: new RemoteAuth({
store: ... , // store
// use /tmp, and since ZIP files will be stored inside dataPath, it resolves the issue
dataPath: '/tmp/wwebjs_auth',
backupSyncIntervalMs: 120000,
}),
... // other config
});
/tmp
when running inside AWS Lambda
hello @tuyuribr, any updates? |
PR Details
Fixes read-only filesystem error on AWS Lambda.
Description
When deploying on AWS Lambda, the filesystem is read-only, with
/tmp
only being writable. This causes error while using LocalAuth or RemoteAuth strategy. This PR fixes it by detecting the runtime environment is AWS Lambda, and use/tmp/wwebjs_auth
and/tmp/wwebjs_cache
directories, instead of./.wwebjs_auth
and./.wwebjs_cache
.Although, we could partially fix the issue by using the below config, there is no way to tell the library, a custom path for where to store ZIP files when using
RemoteAuth
strategy.Another possible way to fix this issue is to create RemoteAuth ZIP files inside
wwebjs_auth
directory itself, instead of current working directory. This could be a better way to handle this issue instead of adding environment-specific workarounds to the library itself.Related Issue(s)
N/A
Motivation and Context
Enables to run whatsapp-web.js on AWS Lambda with zero-config.
How Has This Been Tested
Tested manually.
Environment
Types of changes
Checklist