Appearance
Electric is well documented here, but this note will help explain our use.
We host our sync engine on an EC2 instance with EBS volume. It runs inside of a docker container, which makes things considerably easier, but there are still quirks.
When the instance is created we run the userData and we will break it down
First we update cli tools, install docker, and then start docker:
bash
apt-get update -y
apt-get install -y docker.io
systemctl start dockerNext we have to determine what device is being used. The device names are not always the same for EBS volume, they are randomly assigned with some rules.
Once we find the volume attachment we can format it and move it to the proper location for electric.
bash
DEVICE=""
if lsblk | grep -q xvdf; then
DEVICE="/dev/xvdf"
elif lsblk | grep -q nvme1n1; then
DEVICE="/dev/nvme1n1"
else
echo "ERROR: Could not find attached EBS volume (xvdf or nvme1n1)"
exit 1
fi
if ! sudo blkid $DEVICE; then
sudo mkfs.ext4 $DEVICE
fi
sudo mkdir -p /persistent
sudo mount $DEVICE /persistentAfter that we run the docker instance.
bash
sudo docker pull ${ELECTRIC_IMAGE}
sudo docker run -d -p 80:${ELECTRIC_PORT} \
--name electric \
--restart=always \
-e DATABASE_URL="${connection.value}" \
-e ELECTRIC_SECRET="${secrets.ElectricSecret.value}" \
-e ELECTRIC_INSECURE="false" \
-v /persistent:/persistent \
${ELECTRIC_IMAGE}It is important to know that we have no automatic reboot script at this point.
In the event of debugging or reboot. You can us SSM
bash
aws ssm start-session --target i-****Once you get inside you can use sudo docker * to run any commands, logging, etc that you might need.