Moving web resources to the cloud — continues!!

Steven Jones
5 min readAug 28, 2023

--

Moving web resources to the cloud — continues!!

My cloud journey continues!! Thank you Level Up In Tech for the lessons, projects, and most of all the support and openness!!
A couple weeks ago, I was working This week, the LUIT crew has prompted me to start in on leveling up their deployment of their webserver infrastructure based on my use of user-data scripts to have an Apache webserver be launched, patched and ready for deployment. Once this is in place, they can begin migrating their producion webservers (including their online banking platform) to AWS.

I thought back to my project with CloudFormation and decided to re-use the template from there.
https://medium.com/@steven.c.jones/web-server-wars-2-the-bank-strikes-back-b2682b9b1508

So I used the template to deploy the image since it was already using a t2.micro Centos free instance.
I decided I want to use an Amazon Linux 2 image — I selected ami-08a52ddb321b32a8c

I chose it on this project due to the description given on their site about their images: “Amazon Linux 2023 is a modern, general purpose Linux-based OS that comes with 5 years of long term support. It is optimized for AWS and designed to provide a secure, stable and high-performance execution environment to develop and run your cloud applications.”

So I launched the template and added in user-data to launch an AL2023 image and install and run Apache:

Resources:
LinuxInstance:
Type: AWS::EC2::Instance
Properties:
AvailabilityZone: us-east-1a
ImageId: ami-08a52ddb321b32a8c
InstanceType: t2.micro
KeyName: LUIT_Linux
SecurityGroups:
- !Ref AL2023SecurityGroup
UserData:
Fn::Base64: |
#!/bin/bash
yum update -y
yum install httpd -y
systemctl start httpd
systemctl enable httpd


AL2023SecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: SSH and HTTP
SecurityGroupIngress:
- CidrIp: 0.0.0.0/0
FromPort: 22
IpProtocol: tcp
ToPort: 22
- CidrIp: 0.0.0.0/0
FromPort: 80
IpProtocol: tcp
ToPort: 80

Now, I have an instance started and gotten Apache checked off as publically available.

I have this as a CF template that people can use to deploy, but in the case others want to use this, I’m going to create a AMI for consumption for those that may want to use this as an AMI.
So I stopped the instance in the EC2 Console, went to Actions / Images and Templates and selected Create Image.

Went through a few steps in the menu and let it create an image. After Selecting Create, I noted that a message that listed that ami-05c017fdff83d99ec was pending creation.

So I waited for it to complete. Upon completion, I tested the AMI by selecting the AMI and selecting the Launch Instance from AMI button in the top right.

Upon launching, I verified that I could access by SSH:

I checked inside the instance to make sure that Apache was responding by checking the services and using curl http://localhost and received the default Apache “It works” response.

I checked for the Public IP and verified that the Apache instance was running and accessible publicly:

Nice!!

Now as another option, I decided to test this thru using AWS CLI. I could go and use information from the CLI but I wanted to see how much information I could retrieve from the CLI to create the instance — in this case, retrieve the Week6Lab-AL2023 AMI and relevant network information in order to successfully launch an instance using aws cli.

Things I needed:

  1. AMI image ID:

2. Security Groups used previously:

3. Subnets used:

4. VPC to use:

5. SSH Key pair to connect.

So now we have the AMI Id (ami-05c017fdff83d99ec), the VPC Id for Week6-AL2023 (vpc-0a8fd91308f0c831a — it deployed to the default), the security group (sg-0fefb2e09fc7872ab), public subnet Id (subnet-0dd5e0197aebc7fc3), and the SSH key pair (LUIT_Linux), I should be able to run an instance from the command-line:

Now to check the status of this and the webserver:

What gives???

Ahhh — — after doing some research, I found out that the user data run in an instance during the launch request, and not stored to the AMI.

Now to add the user-data that I added to CF template to the aws cli command. I pulled the following out of the template and saved it as a file in my working directory:

#!/bin/bash
yum update -y
yum install httpd -y
systemctl start httpd
systemctl enable httpd

Now to add the launch-apache.txt script to the awscli command.

Checking the status of the instance and web access from here:

And we’re in!!

Happy computing all!!

--

--