Elastic agents are failing to connect with elastic apm server

I am running on the AWS beanstalk EC2 instance, it is directly running on the host.