Last active
June 21, 2018 22:37
-
-
Save mneedham/0246221849ccf3646727d6b80977d85f to your computer and use it in GitHub Desktop.
Spin up a Neo4j AWS AMI with APOC installed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const uuidv4 = require('uuid/v4'); | |
const AWS = require("aws-sdk"); | |
console.log("Creating a Neo4j server"); | |
let uuid = uuidv4(); | |
let serverParams = {}; | |
serverParams.keyName = `neo4j-ami-keypair-${uuid}`; | |
serverParams.groupName = `neo4j-ami-graph-security-${uuid}`; | |
let regionParams = { 'region': 'us-east-1' } | |
var ec2 = new AWS.EC2(regionParams); | |
ec2.createKeyPair({ KeyName: serverParams.keyName }).promise().then(data => { | |
console.log("Key pair created. Save this to a file - you'll need to use it if you want to ssh into the Neo4j server"); | |
console.log(data['KeyMaterial']); | |
return ec2.createSecurityGroup({ Description: "Neo4j AMI Security Group", GroupName: serverParams.groupName }).promise() | |
}).then(data => { | |
console.log("Created Group Id:" + data.GroupId); | |
serverParams["groupId"] = data.GroupId; | |
var ports = [22, 7474, 7473, 7687]; | |
return Promise.all(ports.map(function (port) { | |
let params = { | |
GroupId: data.GroupId, | |
IpProtocol: "tcp", | |
FromPort: port, | |
ToPort: port, | |
CidrIp: "0.0.0.0/0" | |
}; | |
return ec2.authorizeSecurityGroupIngress(params).promise(); | |
})); | |
}).then(data => { | |
console.log("Opened Neo4j ports"); | |
let params = { | |
ImageId: "ami-f03c4fe6", | |
MinCount: 1, | |
MaxCount: 1, | |
InstanceType: "m3.medium", | |
KeyName: serverParams.keyName, | |
SecurityGroupIds: [serverParams.groupId], | |
UserData: new Buffer(`#!/bin/bash \n | |
curl -L https://github.com/neo4j-contrib/neo4j-apoc-procedures/releases/download/3.2.0.3/apoc-3.2.0.3-all.jar -O \n | |
sudo cp apoc-3.2.0.3-all.jar /var/lib/neo4j/plugins/ \n`).toString('base64') | |
}; | |
return ec2.runInstances(params).promise(); | |
}).then(data => { | |
let ourInstance = data.Instances[0]; | |
console.log("Instance Id: " + ourInstance.InstanceId); | |
serverParams.instanceId = ourInstance.InstanceId; | |
let params = { | |
InstanceIds: [ourInstance.InstanceId] | |
}; | |
return ec2.waitFor("instanceRunning", params).promise(); | |
}).then(data => { | |
let reservations = data.Reservations; | |
let instances = reservations[0].Instances; | |
serverParams.publicDnsName = instances[0].PublicDnsName; | |
console.log("Your Neo4j server is now ready!"); | |
console.log("You'll need to login to the server and change the default password:") | |
console.log(`https://${serverParams.publicDnsName}:7473 or http://${serverParams.publicDnsName}:7474`) | |
console.log(`User:neo4j, Password:${serverParams.instanceId}`) | |
}).catch(err => console.log(err, err.stack)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
npm install uuid | |
npm install aws-sdk |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment