Use Case:
You don't want to or not able to test some feature on in your local env for some reason, so you want to have separate EC2 machine to check this feature. In my case i was testing the feature where i had to scan files in order to determine whether it is vulnerable or not, i was able to test the non-vulnerable file however i was not able to test vulnearable file test case due the fact that whenever i used to download sample vulnerable file from internet my local machine antivirus used to detect it and delete it immediately, hence i had to use Linux box to test this feature
STEPS
- Launch EC2 machine
- Make sure Instance has access to Internet
- Either Launch instance in Public subnet OR in a subnet which has route 0.0.0.0/0 to Nat Gateway
- Download JAVA - Link You may need to Login to oracle website, If you have signed Up already login using username and password otherwise you can signup and then login
- Download Maven - Link
- Make sure you are downloading apache-maven-3.8.6-bin.tar.gz file not src file.
- Copy apache-maven-3.8.6-bin.tar.gz and jdk-8u202-linux-x64.tar.gz to EC2 instance using scp command:
## Your key must not be publicly viewable for SSH to work. Use this command if needed:
$ chmod 400 ec2-spring.pem
$scp -i ec2-spring.pem jdk-8u202-linux-x64.tar.gz ec2-user@10.123.45.65:/home/ec2-user
$scp -i ec2-spring.pem apache-maven-3.8.6-bin.tar.gz ec2-user@10.123.45.65:/home/ec2-user
$ chmod 400 ec2-spring.pem
$scp -i ec2-spring.pem jdk-8u202-linux-x64.tar.gz ec2-user@10.123.45.65:/home/ec2-user
$scp -i ec2-spring.pem apache-maven-3.8.6-bin.tar.gz ec2-user@10.123.45.65:/home/ec2-user
On Ec2 instance
$mkdir /home/ec2-user/software
## COPY downloaed jdk-8u202-linux-x64.tar.gz file to above location with scp
## Also COPY downloaed maven apache-maven-3.8.6-bin.tar.gz to above location
$cat ~/.bash_profile
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
export JAVA_HOME=/home/ec2-user/software/jdk1.8.0_331
PATH=$PATH:$HOME/.local/bin:$HOME/bin:$JAVA_HOME/bin:/home/ec2-user/software/apache-maven-3.8.6/bin
export PATH
## now copy the spring boot code to ec2 isntance and run the following command
$mvn spring-boot:run
## COPY downloaed jdk-8u202-linux-x64.tar.gz file to above location with scp
## Also COPY downloaed maven apache-maven-3.8.6-bin.tar.gz to above location
$cat ~/.bash_profile
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
export JAVA_HOME=/home/ec2-user/software/jdk1.8.0_331
PATH=$PATH:$HOME/.local/bin:$HOME/bin:$JAVA_HOME/bin:/home/ec2-user/software/apache-maven-3.8.6/bin
export PATH
## now copy the spring boot code to ec2 isntance and run the following command
$mvn spring-boot:run
Call POST method using CURL:
$curl -i -X POST http://10.123.45.65:8080/app/get-file-from-server
Get the heap memory size in elasticbeanstalk env with t2.micro instance type:
t2.micro instance type specs:
$PROCESS_ID=$(ps -ef | grep java | awk '{print $2; exit}')
## Get the process id from the above command
$jhsdb jmap --heap --pid $PROCESS_ID
0 Comments