Skip to content

Create an EC2 instance in a public or private subnet

Marc Grossouvre edited this page Oct 11, 2019 · 12 revisions

An EC2 instance is a virtual server in the Elastic Compute Cloud. Creating an EC2 Instance means choosing some hardware and some OS to run on it. For hardware, we choose among presed configurations called Instance Types. For OS, we choose among predefined images called AMI for Amazon Machine Image. An EC2 instance has to be in a subnet.

Choose an image

Amazon Linux 2 AMI (HVM), SSD Volume Type. It is based on a Amazon specific linux distribution. simple instance type : t2.micro

Configure instance details page.

This is where we choose the instance location in the VPC.

  • Network : choose relevant VPC
  • Subnet : choose relevant subnet
  • Auto-assign Public IP :
    • in a public subnet : when enabled, you get a public IP which may differ at each instance reboot, when disabled, you don't have any public IP for this instance but you can manually assign one later on.
    • in a private subnet : disable
  • Network interface : allows using a reserved IP for a web server for example
  • Advanced details, User data : paste here a script tha will be executed at creation time

Configure security group:

  • give it a name
  • keep ssh port open from any source
  • open "All ICMP - IPv4" from any source so that machine can be pinged
  • open HTTP, HTTPs or any required stuff

Path:

  • -> EC2 Dashboard
  • -> Launch Instance
  • -> choose an AMI -> Select
  • -> choose an instance type -> Next: Configure instance details
  • -> set parameters -> Next : Add Storage
  • -> choose hard drive capacity -> Next : Add tag
  • -> set a Name tag -> Next : Configure Security Group
  • -> set parameters -> Review and Launch
  • -> Launch
  • -> Choose a pair
  • -> Launch Instances
  • -> View Instances

Check

Check at once that a public IP has been assigned if required.

Warning about charges

Charges will start running at once.

  • charges for running EC2 instance : stops when stopping (shutting down) instance
  • charges for hard disk (Elastic Block Store EBS) usage : stops when terminating (deleting) instance
  • charges for elastic IP reservation : free if in usage, expensive once corresponding instance is deleted. Don't forget to delete it when you don't need it anymore.