All notes



# Get the FQDN:
hostname --fqdn

# Get the public IP of an instance using:
curl && echo

# Get the instance host name
curl && echo


Cybart: how to install and configure postfix on Amazon EC2.

sudo su
yum install postfix -y
# Stop sendmail (installed on Amazon Linux by default)
/etc/init.d/sendmail stop
/etc/init.d/postfix start

# Switch MTA from sendmail to postfix
# MTA: message transfer agent or mail transfer agent.
alternatives --set mta /usr/sbin/sendmail.postfix



ec2 awscli ec2.

pip install awscli --upgrade --user
# Verify that the AWS CLI installed correctly.
aws --version

# Set up IAM information. IAM: Identity and Access Management.
aws configure
# The settings are saved under: ~/.aws/credentials or at C:\Users\USERNAME\.aws\credentials.

#---------- Describe regions
# For example: singapore.
aws ec2 describe-regions --region ap-southeast-1
# For a complete list of regions:

#---------- instances

# Describe instances
aws ec2 describe-instances

# Start/Stop
# --dry-run | --no-dry-ru
aws ec2 start-instances --instance-ids i-1234567890abcdef0
aws ec2 stop-instances --instance-ids i-1234567890abcdef0
# wcfNote: you also need to remove EBS storage to save money after stopping the instances.

aws ec2 run-instances --image-id ami-1a2b3c4d --count 1 --instance-type c3.large --key-name MyKeyPair --security-groups MySecurityGroup

aws ec2 terminate-instances --instance-ids i-1234567890abcdef0
# When you terminate an instance, any attached EBS volumes with the _DeleteOnTermination_ block device mapping parameter set to true are automatically deleted.

aws ec2 describe-instance-status --instance-id i-1234567890abcdef0

aws ec2 describe-instance-attribute --instance-id i-1234567890abcdef0 --attribute instanceType
aws ec2 describe-instance-attribute --instance-id i-1234567890abcdef0 --attribute disableApiTermination
aws ec2 describe-instance-attribute --instance-id i-1234567890abcdef0 --attribute blockDeviceMapping

# Report your experience with the instance. Amazon EC2 collects this information to improve the accuracy of status checks.
aws ec2 report-instance-status --instances i-1234567890abcdef0 --status impaired --reason-codes unresponsive

#---------- Volumes

aws ec2 create-volume --size 80 --region us-east-1 --availability-zone us-east-1a --volume-type gp2

# The volume must be in the available state (not attached to an instance).
aws ec2 delete-volume --volume-id vol-049df61146c4d7901

aws ec2 describe-volumes
aws ec2 describe-volumes-modifications

aws ec2 modify-volume-attribute --volume-id vol-1234567890abcdef0 --auto-enable-io

#---------- Images

# Creates an Amazon EBS-backed AMI from an Amazon EBS-backed instance that is either running or stopped.
aws ec2 create-image --instance-id i-1234567890abcdef0 --name "My server" --description "An AMI for my server"
# -no-reboot parameter: the instance is not rebooted before the image is created.
aws ec2 create-image --instance-id i-0b09a25c58929de26 --name "My server" --no-reboot

# For Amazon EBS-backed instances, create-image creates and registers the AMI in a single request, so you don't have to register the AMI yourself.

#---------- Snapshots

# Creates a snapshot of an EBS volume and stores it in Amazon S3. You can use snapshots for backups, to make copies of EBS volumes, and to save data before shutting down an instance.
aws ec2 create-snapshot --volume-id vol-1234567890abcdef0 --description "This is my root volume snapshot."

aws ec2 describe-snapshots


For bash, use the built-in command complete. Put complete -C '/usr/local/bin/aws_completer' aws to ~/.bashrc.


What is charged

Key pairs, security groups

serverFault: pricing of key pairs and security groups.

Key Pairs and Security Groups, those items are more like "metadata." (The same logic applies to Placement Groups.)


stackOverflow: cost of storing AMI.

You are only charged for the storage of the bits that make up your AMI, there are no charges for creating an AMI.

EBS-backed AMIs are made up of snapshots of the EBS volumes that form the AMI. You will pay storage fees for those snapshots according to the rates listed here. Your EBS volumes are not "duplicated" until the instance is launched, at which point a volume is created from the stored snapshots and you'll pay regular EBS volume fees and EBS snapshot billing.
S3-backed AMIs have their information stored in S3 and you will pay storage fees for the data being stored in S3 according to the S3 pricing, whether the instance is running or not.

Migration between regions


Ref. Copy your instance into another availability zone via right click on the AMI. And you don't need necessarily to stop the instance.

Amzn Linux

Install packages

Docker docker basics.

sudo yum install -y docker
sudo service docker start

# Add the ec2-user to the docker group so you can execute Docker commands without using sudo.
sudo usermod -a -G docker ec2-user
# Log out and log back in again to pick up the new docker group permissions.
# Verify that the ec2-user can run Docker commands without sudo.
docker info

Set timezone set time.

ls /usr/share/zoneinfo
# Then update the /etc/sysconfig/clock file with the new time zone.

sudo ln -sf /usr/share/zoneinfo/America/Los_Angeles /etc/localtime

# See a list of peers known to the NTP server:
ntpq -p
sudo service ntpd start
sudo chkconfig ntpd on
# Verify
sudo chkconfig --list ntpd


Amazon Simple Queue Service (SQS)


Draw architect diagram

cloudCraft: Create smart AWS diagrams.

Open ports in Security Groups not working?

Question: After I opened port 80 and shadowsocks port (both tcp and udp) in the associated Security Group, I found I either could not telnet my AWS on port 80 nor the shadowsocks server port.

This ref gave me a good hint. The reason why I couldn't telnet on port 80 was because I hadn't started apache yet. The reason why I couldn't telnet on my shadowsocks port was because in my config file I specified "" (loopback) as server IP, which is wrong, and actually "" (all ip) should be set instead.

No makeinfo in aws?

When compiling emacs on aws, yum found no candidate for makeinfo which is needed by emacs to generate info. This page told me that actually texinfo is another name for makeinfo. And yes, yum can find texinfo.