Unable to successfully run chef-client on AWS instance Errno::ENOMEM eror

I wrote a cookbook which will run some recipe’s on the instance created on AWS. When it is running it is giving me the following error while adding a cron job to the instance.

Errno::ENOMEM
** -------------**
Cannot allocate memory - fork(2)

I have googled it and found that there are some memory issues and verified the memory with top command and it has enough memory but still I am facing the same problem. But, the same recipe is executing successfully some times.

I was wondering if someone could help me in resolving this issue.

Thanking you all in advance.

Errno::ENOMEM definitely means you’re out of RAM. It’s possible that memory is spiking for a very short time and you’re not seeing it in top.

Hi kallistec,

Thanks for your response. But the only service that I am running on that instance is chef-client it is failing at creating a cron job with chef resource.

How large of an AWS instance are you using, and does it work with a larger instance?

Notably the search() can use massive amounts of RAM if you are querying something like search(:node, '*:*').

From experience the default linux images also have no swap, so as soon as the system experiences memory pressure things fail.
A quick and easy fix may be to attach a small (1-2G) EBS volume for swap . I’ve used this in the past to make a micro instance do more than the tiny amount of memory would allow.

–Jp

Hi dreamnite,

Thanks for your response could you please share me a small snippet of code on attaching EBS voulmes. I am creating instances with chef provisioning AWS. I have tried attaching it but faced few problems. I would be a great help to me if you could share me the code.

Thank you.