Is there any way to prevent a failure of container run because of the lack of allocated resources in AWS Fargate? Is there any way to auto-scale the container if the allocated memory not enough? Many thanks in advance!
No. What you are asking about is called vertical scaling. The only service in AWS currently that can automatically scale vertically like that is Aurora Serverless. Most services in AWS only offer horizontal scaling.
Fargate requires you to specify CPU and Memory settings at the time of deployment and the individual containers will never be assigned more resources than that, until you change the setting and redeploy.