AWS 基础
获取开始使用核心 AWS services: EC2, S3, RDS, and IAM for 构建 cloud applications.
你将学到
- 核心 AWS services and 什么它们做
- EC2 for 虚拟服务器, S3 for storage
- IAM for security and access control
- Using AWS CLI and console
概念讲解
核心服务
Amazon Web Services offers over 200 services, but a few are fundamental. EC2 (Elastic Compute Cloud) provides virtual servers you can configure and run. S3 (Simple Storage Service) is an object store for files, backups, and static websites. RDS (Relational Database Service) manages databases like PostgreSQL and MySQL. VPC (Virtual Private Cloud) isolates your resources in a private network. Lambda runs code without servers. These services form the building blocks of most AWS architectures.
EC2 Instances
An EC2 instance is a virtual server. You choose an instance type (size — like t3.micro for small workloads or m5.large for bigger ones), an AMI (Amazon Machine Image — the OS and software), and a region. You launch it, connect via SSH, and use it like any server. EC2 instances can be auto-scaled, load-balanced, and terminated when no longer needed. You pay per second while the instance is running.
S3 Storage
S3 stores objects (files) in buckets. Each object has a key (name) and metadata. S3 is infinitely scalable, highly durable (11 nines), and cheap. It is used for file uploads, static website hosting, data backups, and as a data lake. Objects can be public or private, and you can set lifecycle rules to automatically move old data to cheaper storage tiers or delete it.
IAM Security
IAM (Identity and Access Management) controls who can do what in your AWS account. Users, groups, and roles have policies attached that define permissions. The golden rule is least privilege — give only the permissions needed, nothing more. Never use the root account for everyday tasks. Use roles for EC2 instances and services instead of storing access keys on servers. Enable MFA on all accounts.
AWS Free Tier
AWS offers a free tier for new accounts — 750 hours of t2.micro EC2 per month, 5GB of S3 storage, and 1 million Lambda requests. This is perfect for learning and small projects. Be aware that the free tier expires after 12 months for some services, and exceeding limits incurs charges. Set up billing alerts immediately after creating an account. The free tier makes AWS accessible for experimentation, but always clean up resources you no longer need to avoid surprise charges on your bill.
示例代码
# Create an S3 bucket and upload a file
aws s3 mb s3://my-app-bucket-12345
aws s3 cp ./dist/index.html s3://my-app-bucket-12345/
aws s3 website s3://my-app-bucket-12345 \
--index-document index.html --error-document error.html
# Launch an EC2 instance
aws ec2 run-instances \
--image-id ami-0c02fb559f6fe2234 \
--instance-type t3.micro \
--key-name my-key-pair \
--security-group-ids sg-12345678
# List IAM users and policies
aws iam list-users
aws iam list-attached-user-policies --user-name myuser
这些 commands 创建 S3 bucket for 静态 hosting, launch EC2 实例, and 列表 IAM 用户. AWS CLI mirrors console functionality for scripting.
动手试一试
- SSH 键 Generator
Generate 键 pairs for EC2 SSH access.
- JSON Schema Validator
验证 IAM policy documents.
- HTTP 请求 Tester
测试 AWS API 端点 and S3-hosted sites.
常见错误
错误写法
Using 根 account for everyday 工作
正确做法
创建 IAM 用户使用有限 permissions for daily 任务. Use roles for services. 根 account 有 unrestricted access and 应该仅 是 used for 初始设置 and account-level 更改.
错误写法
Leaving S3 buckets 公共 unintentionally
正确做法
启用块 公共 Access on 所有 buckets 通过默认. 仅制作对象公共 deliberately 使用 explicit policies. Unintentional 公共 buckets 是 leading cause 的数据 breaches.
查阅不认识的术语
新手友好的术语表用大白话解释编程术语——变量、函数、DOM、Promise 等等。
动手做项目
通过引导式项目应用所学,含起始代码与解决方案。
解读错误信息
用大白话解释常见错误——什么意思、为什么发生、如何修复。