I'm running a web app inside a container and currently, all of my static files are included within the image itself. I'm looking to modify this setup so that certain static files are fetched from an AWS S3 bucket while the application is running. Specifically, I'm curious about two things:
1) Is it feasible to use a cron job that runs on startup and checks for updates every 30 seconds to retrieve the files?
2) What's the best way to securely provide AWS credentials to my containers?
2 Answers
Fetching files from AWS is definitely possible! Using a cron job at startup to fetch files and then checking for updates every 30 seconds could work, but be cautious about how often you hit the S3 bucket to avoid unnecessary costs or limits. Another approach could be using a background service in your app that handles this fetching instead.
Instead of using a cron job, you might want to create a protected endpoint in your app that fetches the files when called. You could set this up to trigger on app health checks, like a "/fetchFiles" call on your healthcheck endpoint. That way, you get updates only when needed without constant polling.
That's a good point! Just ensure you're handling the possible race conditions when multiple fetches happen.