Launching an EC2 Instance in AWS

General forum for computers with Linux, Ubuntu,Mac or other operating system. Troubleshooting, installation, tweaks, tips, guides, documentations, software, news, and inquiries for computers here.
Post Reply
User avatar
Posts: 182
Joined: Tue Mar 01, 2016 2:35 am

Launching an EC2 Instance in AWS

Post by Killfrenzy »

Launching an EC2 Instance
For this scenario, you create the employee directory application by using user data that you configure when you set up the EC2 instance.

In this exercise, you log in to the console as the IAM Admin user. You then launch an EC2 instance by using the IAM role that you created previously. Finally, after you create the employee directory application, you stop and then terminate the instance. Because this instance launch is a dry run, you terminate the instance to prevent additional costs from incurring.

Task 1: Launching an EC2 instance that uses a role
In this task, you will launch an EC2 instance that hosts the employee directory application.

If needed, log in to the AWS Management Console as your Admin user.

In the Services search bar, search for EC2, and open the service by choosing EC2.

In the navigation pane, choose Instances.

Choose Launch instances.

For Choose an Amazon Machine Image (AMI), choose Select next to the first AMI that’s listed, which should be Amazon Linux 2 AMI (HVM), SSD Volume Type.

For Choose an Instance Type, select t2.micro (Free tier eligible).

Choose Next: Configure Instance Details.

Configure the following settings.
Network: Keep the default selection, which should have (default) after the network name
Subnet: Choose the first subnet in the dropdown list
Auto-assign Public IP: Enable
IAM role: S3DynamoDBFullAccessRole
Scroll down to Advanced Details and expand the section.

In the User data box, paste the following code:

Code: Select all

#!/bin/bash -ex
cd FlaskApp/
yum -y install python3 mysql
pip3 install -r requirements.txt
amazon-linux-extras install epel
yum -y install stress
export DYNAMO_MODE=on /usr/local/bin/flask run --host= --port=80
Copy to clipboard
In the pasted code, change the following line to match your Region (your Region is listed at the top right, next to your user name):

Code: Select all

Copy to clipboard

The following example uses the US West (Oregon) Region, or us-west-2.

Code: Select all

export AWS_DEFAULT_REGION=us-west-2
Copy to clipboard
Note: In a later lab, you will modify this user data script again to use your Amazon Simple Storage Service (Amazon S3) bucket. For now, keep ${SUB_PHOTOS_BUCKET} in the script.

Choose Next: Add Storage and then choose Next: Add Tags.

Choose Add Tag and enter the following:
Key: Name
Value: employee-directory-app
Choose Next: Configure Security Group.

For Security group name, paste app-sg.

Choose Add Rule and configure the following settings:
Type: HTTP
Source: Anywhere
Delete the SSH rule by choosing the X (at the right of the rule settings).

Note: You might get a warning that you will no longer be able to use SSH to access your instance. You can remove the SSH rule because you won’t need SSH access to the instance.

Choose Review and Launch.

Choose Launch

In the Select an existing key pair or create a new key pair dialog box, choose Create a new key pair.

For Key pair name, paste app-key-pair.

Choose Download Key Pair and save the file.

Finally, choose Launch Instances.

Scroll down, and choose View Instances.

The instance should now be listed under Instances.

Wait for the Instance state to change to Running and the Status check to change to 2/2 checks passed.

Note: Often, the status checks update, but the console user interface (UI) might not update to reflect the most recent information. You can minimize waiting by refreshing the page after a few minutes.

Task 2. Viewing the application
In this task, you will view the application that’s running on the instance in a web browser window.

Select the instance by selecting its check box.

Instance information should load on the tabs in the pane.

On the Details tab, copy the Public IPv4 address.

Note: Make sure that you only copy the address instead of choosing the open address link.

In a new browser window, paste the IP address that you copied.

You should see an Employee Directory placeholder. Right now, you won’t be able to interact with it yet because the application isn’t connected to a database.

Congratulations! You have successfully created an EC2 instance, which hosts the employee directory application.

After you finish exploring the instance, you will stop and terminate your instance so that you don’t incur future costs.

Task 3. Cleaning up
In this task, you will terminate the EC2 instance that you launched.

Go back to the AWS Management Console.

The employee-directory-app instance should still be selected.

At the top of the console pane, choose Instance state, choose Stop instance, and choose Stop.

The status in the Instance state column will eventually go into the Stopped state.

Next, you will terminate the instance.

Make sure that check box next to the instance Name is selected.

Choose Instance state, choose Terminate instance, and choose Terminate.
Post Reply

Return to “Linux, Mac and Other OS”