Today, we will focus on the use of some simple AWS services. We will use the AWS Management Console to create and manage these services. We will also use the AWS CLI to interact with these services.
-
Go to the AWS Management Console and navigate to the EC2 service.
-
Click on the "Launch Instance" button.
-
Write the name of the instance in the "Instance Name" field (e.g., "ejemplo-1").
-
Select "Ubuntu Server 20.04 LTS (HVM), SSD Volume Type" as the Amazon Machine Image (AMI).
-
Select the "t3.micro" instance type.
-
Generate a new key pair and download it. Give it a name (e.g.,
ec2-2keys
). -
Allow ssh, https and http traffic in the security group.
-
Try to login to the EC2 instance using the command that you can find in the EC2 console.
-
For Mac users, an error will appear because the key pair has a permission that is too open. Change the permission of the key pair using the following command:
chmod 400 ec2-2keys.pem
-
Try to login to the EC2 instance again using the command that you can find in the EC2 console.
-
Install docker by running the following commands:
sudo snap install docker
sudo usermod -aG docker $USER
- Logout and login again to apply the changes.
- Run the following command to check if docker is installed correctly:
docker --version
- Run the following command to pull the image with SuperMario:
docker run -d -p 8600:8080 pengbai/docker-supermario
- Get the IP of the EC2 instance by running the following command:
curl ifconfig.me
- Open a browser and go to the following URL:
http://<IP>:8600
-
You will see that you can't connect to the server. This is because the security group is not allowing traffic on port 8600.
-
We need to add a new rule in the security group to allow traffic on port 8600. To do so go to the EC2 instance and check its security group.
- After that, open the security group and modify the inbound rules to allow traffic on port 8600.
- Click add rule and select the following options:
-
Type: Custom TCP
-
Protocol: TCP
-
Port Range: 8600
-
Source: Anywhere IPv4
Once everything is configured, you should see the following:
- Now, try to access the SuperMario game again by going to the following URL. You should see the game running.
To install the AWS CLI, you can follow the instructions provided in the official documentation.
-
Go to the IAM service in the AWS Management Console.
-
Click on "Users" and then on "Add user".
-
Write the username (e.g.,
cli-user
) -
Give it full administrator access.
-
Click on "Next" and then on "Create user".
-
Create a new key pair and download it.
-
Run the following command to configure the AWS CLI:
aws configure
-
Enter the access key and secret key
-
Enter eu-noth-1 as the default region
-
Enter json as the default output format
-
Run the following command to check if the configuration is correct:
-
Go to the EC2 service in the AWS Management Console.
-
Click on
Launch Instance
and select the same options as before. -
Click on
Preview code
and copy the command. -
Run the command in the terminal.
-
A JSON will appear in the terminal with the information of the instance.
-
Run the following command to get the public IP of the instance:
PUBLIC_IP=$(aws ec2 describe-instances \
--filters "Name=tag:Name,Values=app-server" \
--query "Reservations[*].Instances[*].PublicIpAddress" \
--output text)
echo "Public IP: $PUBLIC_IP"
- Run the following command to login to the instance:
ssh -i ec2-2keys.pem ubuntu@$PUBLIC_IP