Skip to main content

Amazon EC2 Creation Step by Step - LAB

EC2 Creation Step by Step

Step 1: Create Your EC2 Resources and Launch Your EC2 Instance
Step 2: Create Your Amazon EFS File System
Step 3: Connect to Your Amazon EC2 Instance and Mount the Amazon EFS File System
Step 4: Sync Files from Existing File Systems to Amazon EFS Using EFS File Sync
Step 5: Clean Up Resources and Protect Your AWS Account

Step 1: Create Your EC2 Resources and Launch Your EC2 Instance

Before you can launch and connect to an Amazon EC2 instance, you need to create a key pair, unless you already have one. You can create a key pair using the Amazon EC2 console and then you can launch your EC2 instance.
Note
Using Amazon EFS with Microsoft Windows Amazon EC2 instances is not supported.
To create a key pair
  • Follow the steps in Setting Up with Amazon EC2 in the Amazon EC2 User Guide for Linux Instances to create a key pair. If you already have a key pair, you do not need to create a new one and you can use your existing key pair for this exercise.
To launch the EC2 instance
  1. Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/.
  2. Choose Launch Instance.
  3. In Step 1: Choose an Amazon Machine Image (AMI), find the Amazon Linux AMI at the top of the list and choose Select.
    Note
    If you choose either the Amazon Linux AMI 2016.03.0 orAmazon Linux AMI 2016.09.0 AMI when launching your Amazon EC2 instance, you don't need to install nfs-utils because it's already included in the AMI by default.
  4. In Step 2: Choose an Instance Type, choose Next: Configure Instance Details.
  5. In Step 3: Configure Instance Details, choose Network, and then choose the entry for your default VPC. It should look something like vpc-xxxxxxx (172.31.0.0/16) (default).
    1. Choose Subnet, and then choose a subnet in any Availability Zone.
    2. Choose Next: Add Storage.
  6. Choose Next: Tag Instance.
  7. Name your instance and choose Next: Configure Security Group.
  8. In Step 6: Configure Security Group, review the contents of this page, ensure that Assign a security group is set to Create a new security group, and verify that the inbound rule being created has the following default values.
    • Type: SSH
    • Protocol: TCP
    • Port Range: 22
    • Source: Anywhere 0.0.0.0/0
    Note
    You can configure the EFS file system to mount on your EC2 instance automatically. For more information, see Configuring an EFS File System to Mount Automatically at EC2 Instance Launch.
  9. Choose Review and Launch.
  10. Choose Launch.
  11. Select the check box for the key pair that you created, and then choose Launch Instances.
  12. Choose View Instances.
  13. Choose the name of the instance you just created from the list, and then choose Actions.
    1. From the menu that opens, choose Networking and then choose Change Security Groups.
    2. Select the check box next to the security group with the description default VPC security group.
    3. Choose Assign Security Groups.
    Note
    In this step, you assign your VPC's default security group to the Amazon EC2 instance. Doing this ensures that the instance is a member of the security group that the Amazon EFS file system mount target authorizes for connection in Step 2: Create Your Amazon EFS File System.
    By using your VPC's default security group, with its default inbound and outbound rules, you are potentially opening up this instance and this file system to potential threats from within your VPC. Make sure that you follow Step 5: Clean Up Resources and Protect Your AWS Account at the end of this Getting Started exercise to remove resources exposed to your VPC's default security group for this example. For more information, see Security Groups for EC2 Instances and Mount Targets.
  14. Choose your instance from the list.
  15. On the Description tab, make sure that you have two entries listed next to security groups—one for the default VPC security group and one for the security group that you created when you launched the instance.
  16. Make a note of the values listed next to VPC ID and Public DNS. You'll need those values later in this exercise.

Before you can launch and connect to an Amazon EC2 instance, you need to create a key pair, unless you already have one. You can create a key pair using the Amazon EC2 console and then you can launch your EC2 instance.
Note
Using Amazon EFS with Microsoft Windows Amazon EC2 instances is not supported.
To create a key pair
  • Follow the steps in Setting Up with Amazon EC2 in the Amazon EC2 User Guide for Linux Instances to create a key pair. If you already have a key pair, you do not need to create a new one and you can use your existing key pair for this exercise.
To launch the EC2 instance
  1. Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/.
  2. Choose Launch Instance.
  3. In Step 1: Choose an Amazon Machine Image (AMI), find the Amazon Linux AMI at the top of the list and choose Select.
    Note
    If you choose either the Amazon Linux AMI 2016.03.0 orAmazon Linux AMI 2016.09.0 AMI when launching your Amazon EC2 instance, you don't need to install nfs-utils because it's already included in the AMI by default.
  4. In Step 2: Choose an Instance Type, choose Next: Configure Instance Details.
  5. In Step 3: Configure Instance Details, choose Network, and then choose the entry for your default VPC. It should look something like vpc-xxxxxxx (172.31.0.0/16) (default).
    1. Choose Subnet, and then choose a subnet in any Availability Zone.
    2. Choose Next: Add Storage.
  6. Choose Next: Tag Instance.
  7. Name your instance and choose Next: Configure Security Group.
  8. In Step 6: Configure Security Group, review the contents of this page, ensure that Assign a security group is set to Create a new security group, and verify that the inbound rule being created has the following default values.
    • Type: SSH
    • Protocol: TCP
    • Port Range: 22
    • Source: Anywhere 0.0.0.0/0
    Note
    You can configure the EFS file system to mount on your EC2 instance automatically. For more information, see Configuring an EFS File System to Mount Automatically at EC2 Instance Launch.
  9. Choose Review and Launch.
  10. Choose Launch.
  11. Select the check box for the key pair that you created, and then choose Launch Instances.
  12. Choose View Instances.
  13. Choose the name of the instance you just created from the list, and then choose Actions.
    1. From the menu that opens, choose Networking and then choose Change Security Groups.
    2. Select the check box next to the security group with the description default VPC security group.
    3. Choose Assign Security Groups.
    Note
    In this step, you assign your VPC's default security group to the Amazon EC2 instance. Doing this ensures that the instance is a member of the security group that the Amazon EFS file system mount target authorizes for connection in Step 2: Create Your Amazon EFS File System.
    By using your VPC's default security group, with its default inbound and outbound rules, you are potentially opening up this instance and this file system to potential threats from within your VPC. Make sure that you follow Step 5: Clean Up Resources and Protect Your AWS Account at the end of this Getting Started exercise to remove resources exposed to your VPC's default security group for this example. For more information, see Security Groups for EC2 Instances and Mount Targets.
  14. Choose your instance from the list.
  15. On the Description tab, make sure that you have two entries listed next to security groups—one for the default VPC security group and one for the security group that you created when you launched the instance.
  16. Make a note of the values listed next to VPC ID and Public DNS. You'll need those values later in this exercise.

Step 2: Create Your Amazon EFS File System

In this step, you create your Amazon EFS file system.
To create your Amazon EFS file system
  1. Open the Amazon EFS console at https://console.aws.amazon.com/efs/.
  2. Choose Create File System.
  3. Choose your default VPC from the VPC list. It has the same VPC ID that you noted at the end of Step 1: Create Your EC2 Resources and Launch Your EC2 Instance.
  4. Select the check boxes for all of the Availability Zones. Make sure that they all have the default subnets, automatic IP addresses, and the default security groups chosen. These are your mount targets. For more information, see Creating Mount Targets.
  5. Choose Next Step.
  6. Name your file system, keep general purpose selected as your default performance mode, and choose Next Step.
  7. Choose Create File System.
  8. Choose your file system from the list and make a note of the File system ID value. You'll need this value for the next step.

Step 3: Connect to Your Amazon EC2 Instance and Mount the Amazon EFS File System

You can connect to your Amazon EC2 instance from a computer running Windows or Linux. To connect to your Amazon EC2 instance and mount the Amazon EFS file system, you need the following information:
To connect to your Amazon EC2 instance and mount the Amazon EFS file system
  1. Connect to your Amazon EC2 instance. For more information, see Connecting to Your Linux Instance from Windows Using PuTTY or Connecting to Your Linux Instance Using SSH in the Amazon EC2 User Guide for Linux Instances.
  2. After you've connected, install the Network File System (NFS) client.
    If you're using an Amazon Linux AMI or RedHat Linux AMI, install the NFS client with the following command.
    Copy
    $ sudo yum -y install nfs-utils
    If you're using an Ubuntu AMI, install the NFS client with the following command.
    Copy
    $ sudo apt-get -y install nfs-common
  3. Make a directory for the mount point with the following command.
    Copy
    $ sudo mkdir efs
  4. Mount the Amazon EFS file system to the directory that you created. Use the following command and replace the file-system-id and aws-region placeholders with your File System ID value and AWS Region, respectively.
    Copy
    $ sudo mount -t nfs -o nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2 file-system-id.efs.aws-region.amazonaws.com:/ efs
    Note
    We recommend that you wait 90 seconds after creating a mount target before you mount the file system, as the DNS records propagate fully in the region.
  5. Change directories to the new directory that you created with the following command.
    Copy
    $ cd efs
  6. Make a subdirectory and change the ownership of that subdirectory to your EC2 instance user. Then, navigate to that new directory with the following commands.
    Copy
    $ sudo mkdir getting-started $ sudo chown ec2-user getting-started $ cd getting-started
  7. Create a text file with the following command.
    Copy
    $ touch test-file.txt
  8. List the directory contents with the following command.
    Copy
    $ ls -al
As a result, the following file is created.
Copy
-rw-rw-r-- 1 ec2-user ec2-user 0 Aug 15 15:32 test-file.txt

Step 4: Sync Files from Existing File Systems to Amazon EFS Using EFS File Sync

Now that you have created a functioning Amazon EFS file system, you can use EFS File Sync to sync files from an existing file system to Amazon EFS. EFS File Sync can sync your file data, your entire file system, and also file system metadata such as ownership, time stamps, and access permissions.
In this step, we assume that you have the following:
  • A source NFS file system that you can sync from. This source system needs to be accessible over NFS version 3 or version 4. The source file system can be on-premises or on Amazon EC2.
  • A destination Amazon EFS file system to sync to. If you don't have an Amazon EFS file system, create one. For more information, see Getting Started with Amazon Elastic File System.
To get started with EFS File Sync, do the following:
  1. On the Amazon EFS Management Console, download and deploy a sync agent. For on-premises deployment the sync agent is provided as virtual machine (VM) image for VMware. Alternatively, you can create an Amazon EC2 instance from the community AMI.
  2. Create a sync task to use the sync agent and specify your source and destination file systems.
  3. Start your sync task to begin syncing files from the source file system to the destination file system.
  4. Monitor your sync task on the Amazon EFS console or from Amazon CloudWatch For more information, see .
For more details on the EFS File Sync process, see the following:

Step 5: Clean Up Resources and Protect Your AWS Account

This guide includes walkthroughs that you can use to further explore Amazon EFS. Before you perform this clean-up step, you can use the resources you've created and connected to in this Getting Started exercise in those walkthroughs. For more information, see Walkthroughs. After you have finished the walkthroughs or if you don't want to explore the walkthroughs, you should follow these steps to clean up your resources and protect your AWS account.
To clean up resources and protect your AWS account
  1. Connect to your Amazon EC2 instance.
  2. Unmount the Amazon EFS file system with the following command.
    Copy
    $ sudo umount efs
  3. Open the Amazon EFS console at https://console.aws.amazon.com/efs/.
  4. Choose the Amazon EFS file system that you want to delete from the list of file systems.
  5. For Actions, choose Delete file system.
  6. In the Permanently delete file system dialog box, type the file system ID for the Amazon EFS file system that you want to delete, and then choose Delete File System.
  7. Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/.
  8. Choose the Amazon EC2 instance that you want to terminate from the list of instances.
  9. For Actions, choose Instance State and then choose Terminate.
  10. In Terminate Instances, choose Yes, Terminate to terminate the instance that you created for this Getting Started exercise.
  11. In the navigation pane, choose Security Groups.
  12. Select the name of the security group that you created for this Getting Started exercise in Step 1: Create Your EC2 Resources and Launch Your EC2 Instance as a part of the Amazon EC2 instance launch wizard.
    Warning
    Don't delete the default security group for your VPC.
  13. For Actions, choose Delete Security Group.
  14. In Delete Security Group, choose Yes, Delete to delete the security group you created for this Getting Started exercise.

Comments

Popular posts from this blog

AWS S3 Simple Storage Service

                             Amazon  S3  (Simple Storage Service) Amazon Simple Storage Service is storage for the Internet. It is designed to make web-scale computing easier for developers. Amazon  S3  has a simple web services interface that you can use to store and retrieve any amount of data, at any time, from anywhere on the web. What Is Amazon S3? Amazon Simple Storage Service is storage for the Internet. It is designed to make web-scale computing easier for developers. Amazon S3 has a simple web services interface that you can use to store and retrieve any amount of data, at any time, from anywhere on the web. It gives any developer access to the same highly scalable, reliable, fast, inexpensive data storage infrastructure that Amazon uses to run its own global network of web sites. The service aims to maximize benefits of scale and to pass those benefit...

AWS Route 53 & Routing Policy

Amazon Route 53 You can use Amazon Route 53 to register new domains, transfer existing domains, route traffic for your domains to your AWS and external resources, and monitor the health of your resources. Amazon  Route 53  ( Route 53 ) is a scalable and highly available Domain Name System (DNS). It is part of Amazon.com's cloud computing platform, Amazon Web Services (AWS). The name is a reference to TCP or UDP port  53 , where DNS server requests are addressed. ...  Route 53's  servers are distributed throughout the world. DNS management If you already have a domain name, such as example.com, Route 53 can tell the Domain Name System (DNS) where on the Internet to find web servers, mail servers, and other resources for your domain. Learn More Traffic management Route 53 traffic flow provides a visual tool that you can use to create and update sophisticated routing policies to route end users to multiple endpoints for your application. Le...

Amazon EBS Elastic Block Store

     Amazon Elastic Block Store Amazon  Elastic Block Store  (Amazon  EBS ) provides persistent block storage volumes for use with Amazon EC2 instances in the  AWS  Cloud. Each Amazon  EBS volume is automatically replicated within its Availability Zone to protect you from component failure, offering high availability and durability. Amazon Elastic Block Store (Amazon EBS) provides persistent block storage volumes for use with  Amazon EC2  instances in the AWS Cloud. Each Amazon EBS volume is automatically replicated within its Availability Zone to protect you from component failure, offering high availability and durability. Amazon EBS volumes offer the consistent and low-latency performance needed to run your workloads. With Amazon EBS, you can scale your usage up or down within minutes – all while paying a low price for only what you provision. Amazon EBS is designed for application workloads that benefit from fine tu...