Konstantin Vlasenko

An engineer is someone who can make for a dollar what any fool could make for two. – Alan Kay

Tag Archives: ubuntu

How to relaunch CloudInit script

sudo rm /var/lib/cloud/sem/*
sudo /etc/init.d/cloud-init start

Ubuntu: Attach EBS Volume & Mount it to a directory

Assume you have installed AWS Command Line Interface and you instance is started with appropriate AWS IAM Role (so you don’t need explicitly provide credentials).
—-

#!/bin/bash
# 1. Make a directory to serve as a mount point
mkdir -p /data
chown `id -u` /data
# 2. Attach EBS volume to the instance
export AWS_DEFAULT_REGION=us-east-1
VolumeId=$(aws ec2 describe-volumes --filters Name='tag:Name',Values='My Back-End' | python -c 'import json,sys;obj=json.load(sys.stdin);print obj["Volumes"][0]["VolumeId"]')
InstanceId=$(wget -q -O - http://169.254.169.254/latest/meta-data/instance-id)
aws ec2 attach-volume --volume-id $VolumeId --instance-id $InstanceId --device /dev/xvdf
ls /dev/xvdf
# 3. Wait till volume attached to the instance
while [ $? -ne 0 ]; do
sleep 5
ls /dev/xvdf
done
# 4. Mount the volume
mount -a /dev/xvdf /data

—-
BTW: Why do I need this? I want to use AWS EC2 Spot Instance for my PostgreSQL. So I had to come up with solution to persist data when my instance is terminated. I decided to go with AWS EBS volume.

UPDATE: PosrgreSQL available as AWS RDS. So you don’t need to use solution above in case of PostgreSQL.

Connecting to Official Ubuntu Images for EC2

  • Read first
  • To connect to an instance of an official Ubuntu image for EC2, you need to ssh to it as “ubuntu” instead of as “root”.

    • Hmm…what next to do?:)

Follow

Get every new post delivered to your Inbox.