The Ec2 is not handling the memory of the salve, it start and stop node, you can assign memory passing the parameter for the creation of the agent. You can set the memory size in the JVM options (something like -Xmx4000m). Why do you need 4G of memory for the agent ?