# Get the FQDN:
# Get the public IP of an instance using:
curl http://169.254.169.254/latest/meta-data/public-ipv4 && echo
# Get the instance host name
curl http://169.254.169.254/latest/meta-data/public-hostname && echo
yum install postfix -y
# Stop sendmail (installed on Amazon Linux by default)
# Switch MTA from sendmail to postfix
# MTA: message transfer agent or mail transfer agent.
alternatives --set mta /usr/sbin/sendmail.postfix
pip install awscli --upgrade --user
# Verify that the AWS CLI installed correctly.
# Set up IAM information. IAM: Identity and Access Management.
# 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: http://docs.aws.amazon.com/general/latest/gr/rande.html
# Describe instances
aws ec2 describe-instances
# --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
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
# 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.
# 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.
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
Elastic IP addresses are assigned to an account from the pool of addresses for a given region. As such, an Elastic IP address cannot be migrated between regions.
SSH public keys are only stored per region; AWS does not copy or synchronize the configured customer SSH keys between regions.
Copy your instance into another availability zone via right click on the AMI. And you don't need necessarily to stop the instance.
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.
# 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:
sudo service ntpd start
sudo chkconfig ntpd on
sudo chkconfig --list ntpd
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 "127.0.0.1" (loopback) as server IP, which is wrong, and actually "0.0.0.0" (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.