cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Creating users through EC2 User Data in Neo4j Causal Cluster

In Neo4j Causal Clustering implementation using 3 EC2 instances, we tried to create a new user in the Neo4j Database, through the User Data of one of the EC2 instances. The command used to create the user was - echo "CALL dbms.security.createUser('username', 'password', true);" | cypher-shell -a bolt://localhost:7687 -u neo4j -p neo4j -d system.

The EC2 instance got created successfully but the user was not created in the database. When checked the logs of EC2 User Data, the error message for the createUser command was - Unable to connect to localhost:7687, ensure the database is running and that there is a working network connection to it.

The EC2 Security Group is also configured to allow connections.
If we try the same command in the Terminal after connecting to EC2 instance through SSH, the command works correctly and the user also gets created.

What could be the reason for the above error? How can we create a new user in Neo4j through EC2 User Data?

6 REPLIES 6

Hi @awarrier,

from the connection string its seems you are connecting to FOLLOWER. So instead of bolt:// can you use bolt+routing://:7678, because this is cluster aware connection, so even if the instance is FOLLOWER, it will be automatically routed to LEADER.

From Neo4j 4.2 onwards, bolt+routing://7678 is replaced by neo4j://

Give it a try and let me or the community know if you are still facing issues, we will debug..

Hi @dominicvivek06. Thank You for responding to the query.
We tried running both neo4://localhost:7687 and neo4j://:7687 with both the port numbers 7687 and 7678. But still it is showing the same error - Unable to connect to localhost:7687, ensure the database is running and that there is a working network connection to it.
Even after removing localhost and changing port to 7678, it is showing Unable to connect to localhost:7687.

Hi @awarrier, where are you trying to connect from ? Inside the EC2 instances or from a browser outside ? Because, I see you are using the localhost.

Also try
curl 127.0.0.1:7474 and check the output.
Replace 127.0.0.1 with your ip address.

Hi @dominicvivek06.

We are trying to run the command inside EC2 instance. The above command works when we run them inside EC2 instance after doing SSH into the instance. But when we implement EC2 instance using Cloudformation Template and pass the same command through the UserData parameter of EC2, the command doesn't work. It shows the above mentioned error.

can you change the "echo" script to a bash script invoking the cypher-shell from a S3 bucket or so. Whenever I run a command on multiple EC2 instances I always get the current EC2 instance IP address and associate it as a parameter.

curl http://checkip.amazonaws.com

the above command gives the current EC2 instances public IP address.

@awarrier check your network interface address; the EC2 VMs don't have Neo4j listening on "localhost" (the loopback device) they listen on the external network interface (whatever your machine's IP address is). If instead of connecting to localhost you connect to the IP address of the VM, it should work.