When you parse the HTML to save the images to S3, you can also save the original URL and the new URL to an entity. You could then iterate these entities and use the replaceAll string function to look for the original URL in the HTML and replace any instances of it with the new URL.
I hope this helps. Good luck!