Goals This guide explains how to deploy Neo4j on Amazon’s EC2 platform. Prerequisites You should know how to run and operate Neo4j locally. Knowledge of remote drivers to access Neo4j from your application helps you connect to your cloud-hosted database.… Read more →

Goals
This guide explains how to deploy Neo4j on Amazon’s EC2 platform.
Prerequisites
You should know how to run and operate Neo4j locally. Knowledge of remote drivers to access Neo4j from your application helps you connect to your cloud-hosted database.

Before continuing with the guide make sure you’ve installed the AWS Command Line Interface.

Create EC2 key pair

Run the following command to create an EC2 key pair for connecting to the instance via SSH:

export KEY_NAME="Neo4j-AWSMarketplace-Key"
aws ec2 create-key-pair --key-name $KEY_NAME --query 'KeyMaterial' --output text > $KEY_NAME.pem

If you have an existing key you’d like to use instead, set KEY_NAME to the name of that key pair and don’t run the 2nd command.

Create security group

Run the following command to create a new security group:

export GROUP="neo4j-sg"
aws ec2 create-security-group --group-name $GROUP --description "Neo4j security group"

Next let’s open Neo4j’s HTTP, HTTPS, and Bolt ports so we can access the server from our application. We’ll also open the SSH port so we can remotely access the instance.

for port in 22 7474 7473 7687; do
  aws ec2 authorize-security-group-ingress --group-name $GROUP --protocol tcp --port $port --cidr 0.0.0.0/0
done

If you have an existing group that you’d like to use instead, set GROUP to the name of that group and ignore the rest of the commands.

Start the instance

We’re now ready to start up a Neo4j instance. We’ll use the image-id for us-east-1 but there are corresponding image ids for other regions.

aws ec2 run-instances --image-id ami-f03c4fe6 --count 1 --instance-type m3.medium --key-name $KEY_NAME --security-groups $GROUP --query "Instances[*].InstanceId"

You’ll notice that the Public DNS Name section of the response was empty. This only gets populated when the instance is created.

We can run the following command to find out what it is:

aws ec2 describe-instances --instance-ids [InstanceId] --query ""Reservations[*].Instances[*].PublicDnsName

Now let’s navigate to http://[PublicDnsName]:7474 and login with the credentials neo4j / [InstanceId]. We’ll be asked to update the password the first time we login.

How do I SSH into the instance?

You can run the following command to SSH into the instance:

ssh -i $KEY_NAME.pem ubuntu@[PublicDnsName]

You might get an error about the permissions on the pem file so don’t forget to make sure it isn’t accessible by any other users.

chmod 600 $KEY_NAME.pem

How do I find the image-id for other regions?

If we’re in a different region than us-east-1 we can run the following command to find out the image-id for that region.

aws ec2 describe-images --filters "Name=product-code,Values=3yl6wt8a1ty4izxxfer68wkie" "Name=product-code.type,Values=marketplace" --query "Images[*].ImageId" --region [Region]

Terminating the instance

Once we’ve finished using the instance we can run the following command to terminate it:

aws ec2 terminate-instances --instance-ids [InstanceId]