Skip to content

Instantly share code, notes, and snippets.

@edcote edcote/
Last active Dec 26, 2017

What would you like to do?

Amazon EC2

AWS Free Tier

750 hours per month of t2.micro instance usage. Need to use this carefully. Make sure to stop instances to avoid payment. A stopped instance will "loose" its IP address. You can pay for elastic IP addresses to fix this.


  • Reserved instances

    Provides significant discount compared to on-demand instance pricing.

  • Scheduled instances

    Capacity is reserved ahead of time.

  • Spot instances

    Specify maximum price you are willing to pay per hour of instance. You must be prepared for interruptions. EC2 can interrupt your instance when spot pricing rises above your bid. You cannot start and start an Amazon EBS-backed instance if it is a Spot instance. You can only reboot or terminate the instance.

  • Instance lifecycle

    Amazon charges a full instance hour each time you transition an instance from stopped to running. Rebooting doesn't start a new billing hour. Stopping the instance may erase instance store volumes and disassociate IP addresses.

  • Storage for root device

    All AMIs are either backed by Amazon EBS or backed by instance store. EBS is fast, instance (S3) is slow. Instance store-backed cannot be stopped.

  • Configuring instances

    Use yum update and other package manager commands to keep instance current.

Configure and Launch Instances

See here for detailed information.

  1. Install AWS CLI using pip: pip install awscli --user, configure using aws configure

  2. Create security group, key pair, and role for EC2 instance

  3. Launch and connect to the instance

    AMI (Amazon Machine Image) ID needed for this step. Use the LaunchInstanceWizard to find the correct ID.

    Red Hat Enterprise Linux version 7.3 (HVM), EBS General Purpose (SSD) Volume Type: ami-e69ebc86

    Use run-instances command to run the instance:

     $ aws ec2 run-instances --image-id ami-29ebb519 --security-group-ids sg-b018ced5 --count 1 --instance-type t2.micro --key-name devenv-key --query 'Instances[0].InstanceId'

    Obtain public IP address using describe-instances:

     $ aws ec2 describe-instances --instance-ids i-ec3e1e2k --query 'Reservations[0].Instances[0].PublicIpAddress'

    Connect to instance using ssh and your private key:

     $ ssh -i devenv-key.pem ubuntu@

Remote Management of EC2 Instances

See here for detailed information.

  1. Create IAM policy for your user account, use IAM console.

  2. Install the SSM Agent

    mkdir /tmp/ssm curl -o /tmp/ssm/amazon-ssm-agent.rpm sudo yum install -y /tmp/ssm/amazon-ssm-agent.rpm sudo systemctl status amazon-ssm-agent sudo systemctl start amazon-ssm-agent sudo systemctl status amazon-ssm-agent

  3. Send command using AWS CLI

Make sure AWS CLI is installed and configured.

aws configure  # input required information
aws ssm send-command --document-name "AWS-RunShellScript" --comment "listing services" --instance-ids "Instance-ID" --parameters commands="service --status-all" --region us-west-2 --output text

To view output of previous command:

aws ssm list-command-invocations --command-id "command ID" --details

EC2 and NFS

See this tutorial for details.

TODO: Look for information specific to RHEL7.

  1. Create separate security group called NFS Services. See above tutorial for specific ports.
  2. Install NFS service
  3. Update /etc/exports
  4. Reload NFS service
  5. Connect to NFS service, mount volumes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.