Skip to content

EC2

Created: 2016-02-17 11:24:12 -0800 Modified: 2019-09-25 10:34:11 -0700

Cost/hrTypeSavings
$0.0116On-demand0%
$0.0086 hours reserved usage of spot instance31%
$0.0061 hour of reserved usage of spot instance48%
$0.0035No reserved usage (i.e. you can be terminated at any time)70%
  • If you’re looking to get the absolute most out of your CPU, then ClearLinux could be a good choice since it’s optimized for Intel hardware (reference).
  • ”Instance store” - this is ephemeral storage that is saved to the physical disk attached to the VM. It is only available on the higher tier instances.
  • There’s are nice pricing/cost sites here (preferred) and here.
  • Burstable CPUs (e.g. with t2.micro instances) are explained in a human-understandable way here, with the official docs noting how you can exceed your max credits here.
    • Information on max credits earnable here.
    • t2.micro instances start with 30 credits available at launch, meaning you can run at 100% CPU for 30 minutes (reference). I believe that you’ll accrue another 3 credits during that time, so it’s actually 33 minutes of 100% CPU usage.
    • Credits can be burned by fractional amounts, i.e. using 100 ms of 100% CPU does not mean you spend an entire credit for that minute.
    • At any time (i.e. whether your instance is off or running), you can change the “unlimited” aspect of your instance (via Actions → Instance Settings → Change T2/T3 Unlimited) so that you just end up paying for CPU credits rather than being limited to 10% CPU usage when you run out. (reference)
  • To quickly run a Docker image on an EC2 instance, check out this note.
  • Run basic instructions from the AWS console.
  • Note: Amazon Linux is kind of a generic Linux that has a package manager and some developer defaults: Python, Java, etc.
    • The image is 8 GB (so you can’t provision any less than that) and ~1.2 GB of that is used by default.
  • I set up my VM such that it was accessible by the whole world, but you can only log in through SSH.
  • I believe you should be able to just connect using this command
    • ssh -i “C:Usersagd13 _000DownloadsFirstkeypair.pem” ec2-user@ec2-52-36-149-173.us-west-2.compute.amazonaws.com
      • NOTE: the “ec2-user@” portion is very important! I believe this is needed instead of “admin” when you’re using Amazon’s flavor of Linux. If you’re using something like Debian, just use “admin”. If you’re not sure, use “root” and it will probably tell you to use “admin”.
  • If the above SSH command doesn’t work, then you should do this:
    • Convert the .pem file into a key format that PuTTY can use (.ppk): PuTTYGen —> Conversions —> Import key —> Save private key.
    • Then, in PuTTY, I connected as ec2-user@<endpoint from AWS console> and specified my private key in Connection — >SSH —> Auth —> Browse.
    • Alternatively, you could add the PPK to Pageant and then use ssh_butler (a CMD I wrote to start ssh-pageant).
  • If SSH still doesn’t work (because of a timeout), you should read this page
    • When I had screwed this up before, the solution ended up being that I needed to create an Internet Gateway and then modify my existing Route Table had a route for 0.0.0.0/0 that pointed to the IG.
  • Transferring files: read this.
  • ”yum” is the package manager. To install the mysql client, I typed this:
    • sudo yum install mysql
    • To install NodeJS, look at this note

Elastic IPs are useful if you want to be able to have the same IP address point to any arbitrary running instance that you own. This way, you don’t need to wait for DNS to catch up.

Also, note that you don’t have to use elastic IPs for development; they’re mostly for production. You can use instance IPs (which I believe are temporary and could be reassigned at any time?): AWS console —> VPC —> Subnets —> right-click your subnet —> Modify Auto-Assign Public IP —> Enable them. Instance IPs are totally free.

You are charged for elastic IPs when you use too many or when you have unused IP addresses. To manage them, go to the EC2 console —> Network & Security —> Elastic IPs. You will need to allocate an IP and then associate the IP with a running instance. When you’re done with the IP, you need to release it.

  • To figure out metadata about an instance, you can access an internal AWS config service from that particular VM (not from another VM):
  • You can store up to 16 KB of user data using the metadata service (reference).
    • At the time you call runInstances, pass a base-64-encoded UserData string. If this is an object, you need to serialize it (so JSON.stringify makes the most sense for the JavaScript).
    • When you want to fetch the data, retrieve it via /latest/user-data