Reputation: 84
What is the best way to trigger a PHP script on all running Fargate tasks for an ECS service? I need to trigger this from another PHP script on one of the ECS tasks. The reason I need to do this is that I have NGINX FastCGI Cache on these individual ECS tasks and need to purge the cache for all tasks when an admin makes an update in the CMS.
My NGINX configuration has a /purge/[path] endpoint that will purge the cache using fastcgi_cache_purge, and I do currently have a somewhat working hacky solution that looks something like this:
The above works but is not optimal.
Here are some other solutions that come to mind, but I can't find much information online on how to implement:
Is there an easier/better solution for this? If using any of the above implementations, can someone put me in the right direction on how to implement this using PHP?
Thanks!
Upvotes: 1
Views: 879
Reputation: 200476
This honestly seems like a duplicate of your previous question, but I'll answer:
- Would it be possible perhaps to change the fastcgi_cache_path to a shared file system like AWS EFS, or does that hurt performance not being tmpfs? I see that there's tmpfs support for ECS, but once mounted, would it be shared across the multiple ECS tasks or individually per ECS task?
EFS wouldn't be a good option for this because EFS is SLOW. It would kill any performance benefit of having a cache.
A tmpfs on Fargate will not be shared among instances.
- Using AWS SNS/SQS (write one PHP script that subscribes and another one that publishes an event)
SNS could work, as discussed in your previous question. SQS would not work at all, since an SQS message is only delivered to one consumer, and you want it to be delivered to all instances.
- Use Redis pub/sub similar to above (also not sure exactly how to implement and how to start a long-running subscriber when ECS tasks start)
Yes this would work, as discussed in your previous question. But of course would require a lot of custom coding.
- Use ECS Exec and AWS PHP SDK (almost have a working solution that fetches all ECS tasks and loops them through, and executes an "ECS Exec" command, but "--non-interactive" is not available yet, so it doesn't work. Only "--interactive" mode works currently)
This should work. Why do you state that --non-interactive
is not available yet? If you just leave off the --interactive
parameter, then the command is executed non-interactively.
Upvotes: 1