Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save RichardSilveira/3a3c164b3255ed5fda688551a135be55 to your computer and use it in GitHub Desktop.
Save RichardSilveira/3a3c164b3255ed5fda688551a135be55 to your computer and use it in GitHub Desktop.
exports.mys3UpdaloadEventhandler = async (event, context) => {
console.log('event', event);
console.log('context', context);
const bucket = event.Records[0].s3.bucket.name;
console.log('bucket', bucket);
const key = decodeURIComponent(event.Records[0].s3.object.key.replace(/\+/g, ' '));
try {
const params = {
Bucket: bucket,
Key: key,
};
const s3ReadStream = s3.getObject(params).createReadStream();
console.log('s3Stream', s3ReadStream);
const readlineStream = readline.createInterface({ input: s3ReadStream, terminal: false });
const readlineStreamTask = new Promise((resolve, reject) => {
readlineStream.on('error', (err) => {
console.error(err);
reject();
});
readlineStream.on('line', (input) => console.log('line', input));
readlineStream.on('close', (data) => resolve());
});
await readlineStreamTask;
console.log('end of request');
} catch (error) {
console.log(error);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment