Generating Unique References
Understand how to generate unique and traceable file references in AWS Lambda when working with S3 storage. Learn to use the Lambda request ID to avoid naming conflicts and ensure consistency, and handle AWS SDK calls properly to manage asynchronous operations within Lambda functions.
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 ...