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
-
Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/.
-
Choose Launch Instance.
-
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.
-
In Step 2: Choose an Instance Type, choose Next: Configure Instance Details.
-
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)
.
-
Choose Subnet, and then choose a subnet in any Availability Zone.
-
Choose Next: Add Storage.
-
Choose Next: Tag Instance.
-
Name your instance and choose Next: Configure Security Group.
-
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.
-
Choose Review and Launch.
-
Choose Launch.
-
Select the check box for the key pair that you created, and then choose Launch Instances.
-
Choose View Instances.
-
Choose the name of the instance you just created from the list, and then choose Actions.
-
From the menu that opens, choose Networking and then choose Change Security Groups.
-
Select the check box next to the security group with the description default VPC security group.
-
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.
-
Choose your instance from the list.
-
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.
-
Make a note of the values listed next to VPC ID and Public DNS. You'll need those values later in this exercise.
Note
Using Amazon EFS with Microsoft Windows Amazon EC2 instances is not supported.
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.
Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/.
Choose Launch Instance.
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.
In Step 2: Choose an Instance Type, choose Next: Configure Instance Details.
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)
.- Choose Subnet, and then choose a subnet in any Availability Zone.
- Choose Next: Add Storage.
Choose Next: Tag Instance.
Name your instance and choose Next: Configure Security Group.
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.
Choose Review and Launch.
Choose Launch.
Select the check box for the key pair that you created, and then choose Launch Instances.
Choose View Instances.
Choose the name of the instance you just created from the list, and then choose Actions.
- From the menu that opens, choose Networking and then choose Change Security Groups.
- Select the check box next to the security group with the description default VPC security group.
- 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.
Choose your instance from the list.
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.
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
- Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/.
- Choose Launch Instance.
- In Step 1: Choose an Amazon Machine Image (AMI), find the Amazon Linux AMI at the top of the list and choose Select.NoteIf 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. - In Step 2: Choose an Instance Type, choose Next: Configure Instance Details.
- 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)
.- Choose Subnet, and then choose a subnet in any Availability Zone.
- Choose Next: Add Storage.
- Choose Next: Tag Instance.
- Name your instance and choose Next: Configure Security Group.
- 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
NoteYou 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. - Choose Review and Launch.
- Choose Launch.
- Select the check box for the key pair that you created, and then choose Launch Instances.
- Choose View Instances.
- Choose the name of the instance you just created from the list, and then choose Actions.
- From the menu that opens, choose Networking and then choose Change Security Groups.
- Select the check box next to the security group with the description default VPC security group.
- Choose Assign Security Groups.
NoteIn 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. - Choose your instance from the list.
- 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.
- 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
- Open the Amazon EFS console at https://console.aws.amazon.com/efs/.
- Choose Create File System.
- 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.
- 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.
- Choose Next Step.
- Name your file system, keep general purpose selected as your default performance mode, and choose Next Step.
- Choose Create File System.
- 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:
- The Public DNS name of the Amazon EC2 instance. You made a note of this value at the end of Step 1: Create Your EC2 Resources and Launch Your EC2 Instance.
- The File system ID value for the mount target for your Amazon EFS file system. You made a note of this value at the end of Step 2: Create Your Amazon EFS File System.
To connect to your Amazon EC2 instance and mount the Amazon EFS file system
- 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.
- 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.
$ sudo yum -y install nfs-utils
If you're using an Ubuntu AMI, install the NFS client with the following command.$ sudo apt-get -y install nfs-common
- Make a directory for the mount point with the following command.
$ sudo mkdir efs
- Mount the Amazon EFS file system to the directory that you created. Use the following command and replace the
file-system-id
andaws-region
placeholders with your File System ID value and AWS Region, respectively.$ 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:/ efsNoteWe 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. - Change directories to the new directory that you created with the following command.
$ cd efs
- 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.
$ sudo mkdir getting-started $ sudo chown ec2-user getting-started $ cd getting-started
- Create a text file with the following command.
$ touch test-file.txt
- List the directory contents with the following command.
$ ls -al
As a result, the following file is created.
-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:
- 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.
- Create a sync task to use the sync agent and specify your source and destination file systems.
- Start your sync task to begin syncing files from the source file system to the destination file system.
For more details on the EFS File Sync process, see the following:
- For information about how to sync files from an on-premises file system to Amazon EFS, see Walkthrough 7: Sync Files from an On-Premises File System to Amazon EFS by Using EFS File Sync.
- For information about how to sync files from Amazon EC2 to Amazon EFS, see Walkthrough 8: Sync a File System from Amazon EC2 to Amazon EFS Using EFS File Sync.
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
- Connect to your Amazon EC2 instance.
- Unmount the Amazon EFS file system with the following command.
$ sudo umount efs
- Open the Amazon EFS console at https://console.aws.amazon.com/efs/.
- Choose the Amazon EFS file system that you want to delete from the list of file systems.
- For Actions, choose Delete file system.
- 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.
- Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/.
- Choose the Amazon EC2 instance that you want to terminate from the list of instances.
- For Actions, choose Instance State and then choose Terminate.
- In Terminate Instances, choose Yes, Terminate to terminate the instance that you created for this Getting Started exercise.
- In the navigation pane, choose Security Groups.
- 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.WarningDon't delete the default security group for your VPC.
- For Actions, choose Delete Security Group.
- In Delete Security Group, choose Yes, Delete to delete the security group you created for this Getting Started exercise.
Comments
Post a Comment