Created
October 19, 2020 19:02
-
-
Save RichardSilveira/3a3c164b3255ed5fda688551a135be55 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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