Generating Unique References
Here, you'll generate unique references in the application code to satisfy the technical requirement of storage systems.
We'll cover the following...
Before you start working on the second function, there’s an important technical aspect of working with S3 that you need to consider, which will also come into play frequently when using other storage systems. S3 isn’t really an atomic database; it’s eventually consistent. That means it’s not safe to check whether a file name exists and, if not, then upload something there. You need some way of creating unique references to avoid naming conflicts. A typical solution for this would be to use some kind of unique ID generator, but then you have a problem with traceability. It’s not easy to correlate logs and traces with outputs.
Each Lambda request has a unique request ID, which is automatically printed into the logs. You can read it from the second argument of the Lambda function, using context.awsRequestId
. This is a great candidate for unique file names or message ...