AWS
EC2
Cloud Computing
Startup Script
DevOps

How to fire EC2 instances and upload/run a startup script on each of them?

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

Introduction

Amazon Elastic Compute Cloud (EC2) is a web service that provides resizable compute capacity in the cloud. It enables users to quickly and effortlessly scale capacity as their computing requirements evolve. Today, we will focus on how to launch EC2 instances and run startup scripts on each instance to automate tasks.

Preparing to Launch EC2 Instances

Prerequisites

  1. AWS Account: You need an active AWS account to create and manage EC2 instances.
  2. AWS CLI: The AWS Command Line Interface (CLI) tool must be installed and configured on your machine.
  3. IAM Role: Ensure that the IAM user you’re using has necessary permissions, such as EC2FullAccess.
  4. Key Pair: A key pair will be required to SSH into your instance. You can create one from the EC2 Dashboard.

Installing AWS CLI

To manage EC2 instances using the CLI, install AWS CLI and configure it with your credentials:

  • Go to your AWS Management Console and select EC2.
  • Click on "Launch Instance" and follow the wizard to configure your instance. Select details like Amazon Machine Image (AMI), instance type, VPC settings, storage, etc.
  • Make sure to select an existing key pair or create a new one to access the instance securely.
  • Configure a security group to allow SSH access (port 22) from your IP address.
  • In the Advanced Details section, you can specify a startup script using the User Data field.
  • Make sure, ami-12345678 corresponds to a valid AMI ID.
  • Replace MyKeyPair, sg-123456, and subnet-123456 with your actual Key Pair name, security group ID, and subnet ID, respectively.

Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design