- Create EC2 instance using AWS management console
You have 2 ways to connect to the newly commissioned EC2 instance.
-
If you have GIT Bash use the following command:
- ssh -i khandola-demo-key.pem [email protected]
-
If you would like to use Putty instead, make sure you convert .pem to .ppk using PuttyGen and follow instruction in the video to connect to running ec2 instance
Once you are connected to the EC2 instance you can use following commands to install Tomcat9 on the instance.
sudo yum install -y java-1.8.0-openjdk.x86_64
sudo groupadd --system tomcat
sudo useradd -d /usr/share/tomcat -r -s /bin/false -g tomcat tomcat
export TOMCAT_VER="9.0.39"
sudo wget https://archive.apache.org/dist/tomcat/tomcat-9/v${TOMCAT_VER}/bin/apache-tomcat-${TOMCAT_VER}.tar.gz
sudo tar xvf apache-tomcat-${TOMCAT_VER}.tar.gz -C /usr/share/
sudo ln -s /usr/share/apache-tomcat-${TOMCAT_VER}/ /usr/share/tomcat
sudo chown -R tomcat:tomcat /usr/share/tomcat
sudo chown -R tomcat:tomcat /usr/share/apache-tomcat-${TOMCAT_VER}/
sudo tee /etc/systemd/system/tomcat.service<<EOF
[Unit]
Description=Tomcat Server
After=syslog.target network.target
[Service]
Type=forking
User=tomcat
Group=tomcat
Environment=JAVA_HOME=/usr/lib/jvm/jre
Environment='JAVA_OPTS=-Djava.awt.headless=true'
Environment=CATALINA_HOME=/usr/share/tomcat
Environment=CATALINA_BASE=/usr/share/tomcat
Environment=CATALINA_PID=/usr/share/tomcat/temp/tomcat.pid
Environment='CATALINA_OPTS=-Xms512M -Xmx1024M'
ExecStart=/usr/share/tomcat/bin/catalina.sh start
ExecStop=/usr/share/tomcat/bin/catalina.sh stop
[Install]
WantedBy=multi-user.target
EOF
sudo systemctl enable tomcat
<Resource name="jdbc/khandola"
auth="Container"
type="javax.sql.DataSource"
maxTotal="100"
maxIdle="30"
maxWaitMillis="10000"
username="khandolauser"
password="s3cr3t2021"
driverClassName="com.mysql.cj.jdbc.Driver"
url="jdbc:mysql://localhost:3306/khandola_db" />
- You basically need to spin up a new EC2 instance and then use the MySQL SSH server
- https://medium.com/misfit-technologies/connecting-to-a-serverless-aurora-database-locally-cd479cd5aa42
create database khandola_db; -- Creates the new database;
create user 'khandolauser'@'%' identified by 's3cr3t2021'; -- Creates the user
grant all on khandola_db.* to 'khandolauser'@'%'; -- Gives all privileges to the new user on the newly created database
CREATE TABLE `khandola_db`.`employee` (
`id` INT NOT NULL,
`name` VARCHAR(255) NULL,
`role` VARCHAR(255) NULL,
PRIMARY KEY (`id`));
- INSERT INTO
khandola_db
.employee
(id
,name
,role
) VALUES ('1', 'Samir', 'Architect');
- select * from employee;
- curl -v -X POST -H 'Content-type:application/json' -d '{"name": "Samir Shaik", "role": "Technical Architect"}' localhost:8080/khandola-demo-svc/employees
- curl -v localhost:8080/employees | json_pp
- curl -v -X DELETE localhost:8080/employees/1
- curl -v -X PUT -H 'Content-type:application/json' -d '{"name": "Samir Hymed Shaik", "role": "Technical Architect"}' localhost:8080/employees/1
- mvn clean spring-boot:run