Amazon EC2 Basics
Introduction
Amazon Elastic Compute Cloud (EC2) is a web service that provides resizable compute capacity in the cloud. It allows users to run applications on virtual machines (instances) and offers scalability, flexibility, and security.
Key Concepts
- **Instances**: Virtual servers for running applications.
- **Amazon Machine Images (AMIs)**: Pre-configured templates for launching instances.
- **Instance Types**: Different configurations of CPU, memory, and storage for various workloads.
- **Security Groups**: Virtual firewalls to control inbound and outbound traffic to instances.
Creating an EC2 Instance
Follow these steps to create an EC2 instance:
flowchart TD
A[Start] --> B[Log in to AWS Management Console]
B --> C[Navigate to EC2 Dashboard]
C --> D[Click on Launch Instance]
D --> E[Choose an AMI]
E --> F[Select Instance Type]
F --> G[Configure Instance Details]
G --> H[Add Storage]
H --> I[Configure Security Group]
I --> J[Review and Launch]
J --> K[Launch Instance]
K --> L[Instance Running]
Code Example: Launching an EC2 Instance via CLI
aws ec2 run-instances --image-id ami-0abcdef1234567890 --count 1 --instance-type t2.micro --key-name MyKeyPair
This command launches a single EC2 instance using a specified AMI and instance type.
Best Practices
- Use IAM roles for improved security.
- Regularly back up data using AMIs and snapshots.
- Monitor resources with Amazon CloudWatch.
- Optimize instance types based on workload requirements.
FAQ
What is an EC2 instance?
An EC2 instance is a virtual server in Amazon's Elastic Compute Cloud (EC2) for running applications.
How are EC2 instances billed?
EC2 instances are billed based on usage, including the instance type, the duration it's running, and data transfer.
Can I stop and start my EC2 instance?
Yes, you can stop and start your EC2 instance, but be aware of potential data loss on ephemeral storage.