Error: couldn't connect to server connection attempt failed: SocketException: Error connecting to caused by :: No connection could be made because the target machine actively refused it

Hello everyone! First I want to say that I’m new to this developer forum, so sorry if I seem a bit clueless.

I have an aws ubuntu ec2 instance which I have installed mongodb community edition using this guide. I have also made a user and set a password for them following parts from this guide as well. However, when I try to connect via the compass or from the command line on my local machine I am greeted with Error: couldn't connect to server connection attempt failed: SocketException: Error connecting to caused by :: No connection could be made because the target machine actively refused it.

The command I use looks like mongo --username myname --password --authenticationDatabase admin --host ipaddr --port 27017 after which I enter my password

When I connect via the compass I try mongodb://myname:password@ipaddr:27017

I also have run the sudo mongod --bind_ip_all command and added my ip address to the security group on aws

I honestly don’t know what to do now. Any help would be appreciated.