技术新手求助:AWS免费套餐支持Java/Postgres/Spring网站部署吗?
用AWS免费套餐部署Java/Spring/Postgres网站的新手指南
Hey there! I get it—AWS's free tier docs are packed with jargon that feels totally overwhelming when you're just starting out. Let's break this down into plain English, walk through exactly which free services you need, and get your site up without spending a dime.
先搞懂免费套餐里你要用的核心服务(大白话版)
- EC2: Think of this as a free virtual computer you can rent for 12 months. It's where your Spring Boot app will live and run. The free tier gives you one
t2.microinstance (small, but perfect for a beginner project) 24/7 for a year. - RDS for Postgres: This is a managed Postgres database—meaning AWS handles all the boring stuff like backups, updates, and server maintenance for you. The free tier includes one
db.t2.microinstance with up to 20GB of storage, also free for 12 months. - Security Groups: These are like virtual firewalls for your EC2 and RDS instances. You'll use them to let people access your website (open port 80/443) and let your Spring app talk to the Postgres database (open port 5432). They’re totally free to use.
一步步部署教程
1. 创建你的Postgres数据库(RDS)
- Log into your AWS account, search for "RDS" in the top search bar.
- Click "Create database", choose "Standard Create" and pick "PostgreSQL" as the engine.
- Under "Templates", select Free tier—this ensures you only use resources covered by the free plan.
- Set a DB instance identifier (just a name for your database), master username, and master password (save these somewhere safe—you’ll need them for your Spring app).
- For "DB instance class", make sure
db.t2.microis selected (it should be default for the free tier). - Under "Connectivity", you can enable public access for testing (but restrict it to your EC2 instance’s security group later for safety). Leave other settings default, then click "Create database"—it’ll take a few minutes to spin up.
2. 创建EC2实例来运行Spring Boot应用
- Search for "EC2" in the AWS console, click "Launch instances".
- Pick Amazon Linux 2 AMI (it’s free, has pre-installed tools, and is easy to work with).
- Under "Instance type", select
t2.micro(free tier eligible). - Click through the next few pages with default settings, until you reach "Configure Security Group":
- Create a new security group, add these rules:
- Allow HTTP (port 80) from anywhere (
0.0.0.0/0) so people can visit your site. - Allow SSH (port 22) from your IP address (so you can connect to the instance to upload your app).
- Allow PostgreSQL (port 5432) from your RDS instance’s security group (to let your app talk to the database).
- Allow HTTP (port 80) from anywhere (
- Create a new security group, add these rules:
- Click "Launch", then create a new key pair (save the
.pemfile somewhere safe—you need this to SSH into the instance).
3. 准备EC2实例运行Java应用
- Once your EC2 instance is running, connect to it via SSH (use the
.pemfile; AWS will give you the terminal command for Mac/Linux, or use PuTTY on Windows). - Install Java: Run
sudo amazon-linux-extras install java-openjdk11 -y(Spring Boot works great with Java 11). - Upload your compiled Spring Boot
.jarfile to the EC2 instance (use thescpcommand, likescp -i your-key.pem your-app.jar ec2-user@your-ec2-ip:/home/ec2-user/). - Update your Spring app’s
application.properties/application.ymlwith your RDS credentials:spring.datasource.url=jdbc:postgresql://<your-rds-endpoint>:5432/<your-db-name> spring.datasource.username=<your-master-username> spring.datasource.password=<your-master-password> spring.jpa.hibernate.ddl-auto=update - Run your app: Use
nohup java -jar your-app.jar &to keep it running even if you close the SSH connection.
4. 测试你的网站
- Grab your EC2 instance’s public IP from the EC2 console, paste it into your browser—you should see your Spring app running!
重要注意事项(避免意外收费)
- Double-check all instances are
t2.micro—any larger instance will start charging you. - Keep RDS storage under 20GB to stay in the free tier.
- Stop instances when you’re not using them (don’t terminate if you want to keep data)—stopped instances don’t count towards free tier usage.
内容的提问来源于stack exchange,提问作者vs14
相关产品推荐
相关产品推荐

