Skip to content
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

User data isn't completely flushed to disk when backupUsers resolves #39

Open
mbarneyjr opened this issue Sep 2, 2021 · 1 comment
Open

Comments

@mbarneyjr
Copy link

Within my backup process, I'm calling the backupUsers process and expect that the file is complete when the promise returned from that function resolves, however the data I can immediately pull from disk is not complete (the stream has not finished writing all of the data to the file).

I see here (src/index.ts#L61) that there is no promise wrapping the callback pattern used for the stream, so there's no way to wrap this function call to ensure that the stream has finished writing all of the data to disk.

The following example:

const cbr = require('cognito-backup-restore');
const aws = require('aws-sdk');
const fs = require('fs');
const userPoolId = 'us-east-1_abc123';
const cognitoIsp = new aws.CognitoIdentityServiceProvider();
cbr.backupUsers(cognitoIsp, userPoolId, '/tmp').then(() => {
  JSON.parse(fs.readFileSync(`/tmp/${userPoolId}.json`).toString())
});

will yield the error:

(node:13604) UnhandledPromiseRejectionWarning: SyntaxError: Unexpected end of JSON input

Because the final bracket (]) has not been written to disk

@jfstephe
Copy link

jfstephe commented Mar 25, 2022

I'm seeing this too. From what I see it only exports the first record. @rahulpsd18 Any chance of a fix? Happy to do a PR....

This probably means that anyone that's using this in a lambda to export their users to S3 isn't:
a) doing it right
b) checking their backups are able to be restored

jfstephe added a commit to jfstephe/cognito-backup-restore that referenced this issue Mar 25, 2022
jfstephe added a commit to jfstephe/cognito-backup-restore that referenced this issue Mar 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants