Check if data already exists, and make second network call accordingly.
This is similar to what you currently do when serving data from the server in case it doesn't already exist. Again, we make 2 requests here, however, this time we try to serve data synchronously from the server in the case it doesn't exist.
So, in the first hit, we check if the content had ever been generated previously, in which case, we get a successful URL, or error message. When successful, the next hit goes to S3.
If the data doesn't exist on S3, we make a fresh request (to a different POST URL), on getting which, the server computes data, serves it, while adding an asynchronous task to push it to S3.
if exists on S3, return URL
client --------> server --------------------------------> s3
client --------> server ---------> generate content -------> serve it
|
|---> add SQS task to push to S3