Setup AWS Cloud Infrastructure
This document assumes you have followed Setup AWS Account.
Elastic Beanstalk (API)
Login to the AWS Console.
Change to the region you want. I'm going with Sydney.
I'll be paraphrasing the Launching and Connecting to an External Amazon RDS Instance in a Default VPC document.
Open up RDS.
Create a new instance.
Engine options: MySQL
Check the "Only enable options eligable for RDS Free Usage Tier" checkbox if you wish.
DB engine version: latest (5.7.21)
DB instance class: db.t2.micro
DB instance identifier: gluestack
Master username: gluestack
Master password: gluestack
Virtual Private Cloud (VPC): Default
Subnet group: default
Public accessibility: Yes
VPC security groups: Create new VPC security group
Database name: glue
Enhanced monitoring: Enabled
Select View Instance.
Scroll down to Details, Security and network, Security Groups and select the security group.
Select Inbound.
The ip address that is already there is your current ip address, automatically populated. This may change in future depending on your internet setup. For example, it might change when you restart your modem.
Select Edit.
Select Add Rule.
Port: 3306
Security Group: sg-xxxxxxxx rds-launch-wizard
Select Save.
Open the Elastic Beanstalk service.
Create a new Application
Application Name: Glue Stack
Platform: Java
cd api mvn package
Application Code: (upload jar from api/target)
Select Configure More Options.
Select Modify on the Instances configuration.
EC2 instance type: t2.micro
EC2 security group: rds-launch-wizard
Select Save.
Select Modify on the Software configuration.
Under Environment properties add the following:
RDS_HOSTNAME: (copy from the RDS tab under Connect, Endpoint)
RDS_PORT: 3306
RDS_DB_NAME: glue
RDS_USERNAME: gluestack
RDS_PASSWORD: gluestack
These are specific so that they match the properties Elastic Beanstalk would use if it configured the RDS instance for us, which didn't work for me.
SERVER_PORT: 5000
This aligns the port Spring Boot listens on with the port that Elastic Beanstalk expects (from Deploying a Spring Boot Application on AWS Using AWS Elastic Beanstalk).
Select Save.
Select Create app.
Wait a few minutes.
Click on the URL on the top right to see your application running live.
You can connect to the database instance in Sequel pro using the credentials we passed in as environemnt properties.
Cloudfront (UI)
Go to S3.
Select Create bucket.
Bucket name: gluestack
Region: Sydney
Select Next.
Select Next Again.
Leave the bucket as private
Select Next.
Select Create bucket.
Select the gluestack bucket.
Select Permissions.
Select Bucket Policy.
Paste the following.
{ "Id": "Policy1532945968718", "Version": "2012-10-17", "Statement": [ { "Sid": "Stmt1532945962582", "Action": [ "s3:GetObject" ], "Effect": "Allow", "Resource": "arn:aws:s3:::gluestack/*", "Principal": "*" } ] }
Select Save.
Build the ui.
cd ui yarn buld
Upload the contents of the
ui/build/
.Select Next.
Manage public permissions: Grant public read access to this bucket
Select Next.
Select Upload.
Select Properties.
Select Static website hosting.
Select Use this bucket to host a website.
Index document: index.html
Copy the Endpoint.
Select Save.
Go to CloudFront.
Select Create distribution.
Select Get Started under the Web distribution.
Origin Domain Name: (endpoint you copied from s3)
Viewer Protocol Policy: Redirect HTTP to HTTPS
Select Create Distribution.
Select the distribution.
Select Origins.
Select Create Origin.
Origin Domain Name: (Elastic Beanstalk domain)
Select Behaviours.
Select Create.
Select Create Behaviours.
Path pattern api/*
Origin: Custom-gluestack-env
Viewer Protocol Policy: Redirect HTTP to HTTPS
Allowed HTTP Methods: GET, HEAD, OPTIONS, PUT, POST, PATCH, DELETE
Cache Based on Selected Request Headers: All
Min, Max, Default TTL: 0
Query String Forwarding and Caching: Forward all, cache based on all
Compress Objects Automatically: Yes
Select Create.
Select General.
Go to the Domain and see it all working!
Last updated