- Understand how to deploy an API to AWS Elastic Beanstalk
- Understand how to spin up an AWS PostgreSQL instance
- Host frontend static files on AWS S3
- Fork this repository.
- Clone your fork to your machine.
-
Create an RDS Instance:
- Open the AWS Management Console and navigate to the RDS service.
- Click "Create database."
- Choose the "Standard Create" option.
- Select the PostgreSQL engine.
- Configure the DB instance settings (DB instance identifier, master username, password).
- Choose the instance type and allocated storage.
- Click "Create database."
-
Configure Database Connectivity:
- After the database is created, navigate to the "Connectivity & security" tab.
- Note the "Endpoint" and "Port."
- Configure the security group to allow access from your Elastic Beanstalk environment.
-
Build API and Compress
- Open the Backend Projectin IntelliJ.
- Add the connection details to
application.yml - Change the Port number in
application.ymlto5000 - Initially test with a Neon DB then gradually move to use the RDS Database
- Run the command to build a Jar file as we did when building for Docker
- In the next steps when it asks for a local file to upload, use the Jar file you created
-
Open the AWS Management Console:
- Navigate to the Elastic Beanstalk service.
- Click "Create Application."
- Enter the application name (e.g., aws-java-day-1-{studentName}-api).
- Description is Optional.
- Click Create
-
Create and Environment for you Application
- Click on Create new Environment.
- Follow the steps EXACTLY.
-
- Environment tier choose Web Server environment.
- Platform choose Java.
- Application Code pick Upload your code.
- Then choose your local compress file.
- Add your own version Label (e.g. v1, v1.1 etc).
- Preset pick High availability
- Click on Next
-
- Leave everything as it is.
- No Changes to be made.
- Click on Skip to review
-
- Root volume type General Purpose 3(SSD).
- Instance types remove t3.small. (Only t3.micro should be left.)
- Click on Skip to review
-
- Click on Submit
- AWS Account
- Frontend application built locally (e.g., React app)
-
Create an S3 Bucket:
- Open the AWS Management Console and navigate to the S3 service.
- Click on the "Create bucket" button.
- Enter a unique bucket name.
- Choose the AWS region where you want to create the bucket.
- Leave the default settings for the remaining options, or configure as needed.
- Click "Create bucket".
-
Upload Frontend Files:
- Build your frontend application locally (assuming it’s a React app):
npm run build- In the AWS Management Console, navigate to the S3 bucket you created.
- Click on the "Upload" button.
- Click "Add files" and select the files from the build folder.
- Click "Upload" to upload the files to the S3 bucket.
-
Configure Static Website Hosting:
- In the AWS Management Console, navigate to your S3 bucket.
- Go to the "Properties" tab.
- Scroll down to the "Static website hosting" section.
- Click "Edit".
- Enable static website hosting.
- Set the index document name (e.g., index.html).
- (Optional) Set the error document name if needed (e.g., 404.html).
- Click "Save changes".
-
Set Bucket Policy for Public Access:
- Navigate to the "Permissions" tab of your S3 bucket.
- Click on "Bucket Policy".
- Add the following policy to allow public read access: json
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "PublicReadGetObject",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::your-bucket-name/*"
}
]
}- Replace your-bucket-name with the name of your S3 bucket.
- Click "Save".
- Access the Static Site:
- After configuring static website hosting, note the "Bucket website endpoint" URL provided in the static website hosting section.