Amazon Cloud - Getting Started

amazon-cloud

What are the basic steps to get started?

  1. Sign up for an AWS account
  2. Install the Auto Scaling command line tools
  3. Find a suitable AMI that meets your hardware and software needs. You'll use this AMI to launch an EC2 instance. When launching your Amazon EC2 instance, you'll create a new key pair and a security group.
  4. Launch an instance. You will be asked to select availability zone, create a key pair, download the key pair, configure security group / firewall
  5. Connect to your instance via SSH
  6. Install desired software.
  7. Create custom AMI. that will become your baseline.
  8. Create an Elastic Load Balancer to distribute the traffic load across multiple instances
  9. Update your security group to allow HTTP traffic from only your load balancer instead of from everyone.
  10. Create an auto-scaling configuration
  11. Create an auto scaling group
  12. Create a scaling policy
  13. Launch EC2 instances via Auto Scaling. You'll create an Auto Scaling policy that tells Auto Scaling when to increment or decrement the number of instances in your group.
  14. Create a CloudWatch alarm that monitors the instances in your Auto Scaling group and tells the Auto Scaling group when to take action on that policy

You create your Elastic Load Balancer before you launch your instances so that you can associate your Auto Scaling group with your Elastic Load Balancer. That way, your load balancer can automatically stop routing traffic to any terminated instances, and it can start routing traffic to any newly launched instances.

How can we install the Auto Scaling Command Line tools?

To install the Auto Scaling command line tools to your local computer, go to Install the Command Line Interface. After you have installed the command line tools, try a couple of commands to make sure they work. For example, try typing the as-cmd command at the prompt. This command returns a list of all the Auto Scaling commands and their descriptions.

How can we find suitable AMI?

  1. Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/
  2. In the navigation pane, click AMI
  3. In the Amazon Machine Images pane, in the Viewing list that displays All Platforms, click Linux. In the list that displays All Images, click an option that narrows the display as you want. In this example, click Amazon Images to limit the display to AMIs that are provided by Amazon Web Services. In the text box, type drupal.
  4. Select an AMI that already has Drupal installed such as ami-7813e011 and then click Launch.

Clicking Launch starts the Request Instances wizard, which configures your instance and then launches it.

How can we launch an instance?

  1. After you select an AMI, and click Launch Instance, the Create a New Instance page appears. This page provides two ways to launch an instance: The Classic Wizard and the Quick Launch Wizard. The Classic Wizard offers you more granular control and advanced settings for configuring the type of instance you want to launch. The Quick Launch Wizard simplifies the process for you and automatically configures many selections for you so you can get started quickly with an instance.
  2. On the Create a New Instance page, click Classic Wizard.
  3. In the Request Instances Wizard, on the Instance Details page, in the Availability Zone list, select us-east-1b. Accept the other defaults on this page, and then click Continue.
  4. Accept the defaults on the next two pages, and then click Continue on each.
  5. When the wizard displays the Create Key Pair page, the Create a new Key Pair button is selected by default.
  6. In the Enter a name for your key pair box, type mykeypair. This will be the name of the private key file associated with the pair (with a .pem extension).
  7. Click Create & Download your Key Pair. You're prompted to save the private key from the key pair to your system. Save the private key in a safe place on your system, and record the location where you saved it. You need the key pair to be able to connect to your Amazon EC2 instance. If you lose the key pair, you will not be able to connect.
  8. The wizard displays the Configure Firewall page, where you create a security group. A security group defines firewall rules for your instances. These rules specify which incoming network traffic should be delivered to your instance (e.g., accept web traffic on port 80). All other traffic is ignored. You can modify rules for a group at any time. The new rules are automatically enforced for all running instances. For more information about security groups, go to Using Security Groups
  9. In the Group Name box, type webappsecuritygroup. In the Description box, type a description for your security group. In the Create a New Rule box inside Inbound Rules, click SSH and click Add Rule. Under Inbound Rules, in the Create a New Rule box, click HTTP, and then click Add Rule.
  10. Click Continue.
  11. Review your settings and launch the instance. If all the settings are as you want them, click Launch. When a confirmation message appears, click Close. In the Navigation pane, click Instances to view the status of your instance. It takes a short time for an instance to launch. While the instance is launching, its status will be shown as pending. After a short period, your instance's status switches to running. To manually refresh the display at any time, you can click Refresh.
  12. Record the public DNS name for your instance. Select the running instance, and note the public DNS address in the bottom pane.

How can we connect to your instance via standard SSH?

  1. Most Linux and UNIX computers include a Secure Shell (SSH) client by default. If yours doesn't, the OpenSSH project provides a free implementation of the full suite of SSH tools. For more information, go to http://www.openssh.org.
  2. In a command line shell, change directories to the location of the private key file that you created in Step 4: Launch an Instance.
  3. Use the chmod command to ensure that your private key file isn't publicly viewable. For example, for mykeypair.pem, you would enter the following: chmod 400 mykeypair.pem
  4. Sign in to the AWS Management Console and open the Amazon EC2 console at https://console.aws.amazon.com/ec2/.
  5. In the Navigation pane select US East (Virginia) from the Region drop-down menu.
  6. Click Instances in the Navigation pane.
  7. Right-click your instance, and then click Connect.
  8. Click Connect using a standalone SSH client. AWS automatically detects the public DNS address of your instance and the key pair name you launched the instance with.
  9. Connect to your instance by using the public DNS name of the instance. For example, if the key file is mykeypair.pem and the instance's DNS name is ec2-184-72-209-110.compute-1.amazonaws.com, use the following command: ssh -i mykeypair.pem moc.swanozama.1-etupmoc.011-902-27-481-2ce|resu-2ce#moc.swanozama.1-etupmoc.011-902-27-481-2ce|resu-2ce

How can we create a custom AMI (from a running instance)?

  1. Create an EC2 instance from a suitable AMI
  2. Launch this instance
  3. SSH into this instance and install your desired software
  4. Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/
  5. In the Navigation pane, click Instances
  6. On the Instances page, right click your running instance, and then click Create Image (EBS AMI)
  7. In the Create Image dialog box, fill in a unique image name and an optional description of the image, and then click "Create This Image". Amazon EC2 terminates the instance, takes images of any volumes that were attached, creates and registers the AMI, and then relaunches the instance
  8. In the Navigation pane, click AMIs
  9. View the status of the AMI. While the new AMI is being created, its status is pending. Record the AMI ID. It takes a few minutes for the whole process to finish.
  10. When the status of your AMI changes to "available", go to the "Snapshots" page by clicking on "Snapshots" in the Navigation pane. View the new snapshot that was created for the AMI. Any instance that you launch from the new AMI use this snapshot as its root device volume.

How can we create an Elastic Load Balancer?

Define a load balancer:

  1. Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/.
  2. In the Navigation pane, in the Region list, click US East (Virginia).
  3. In the Navigation pane, click Load Balancers.
  4. In the Create a New Load Balancer wizard, in the Load Balancers pane, click Create Load Balancers.
  5. On the Define Load Balancer page, enter a name for your load balancer. (After you configure the listener information, you cannot change it. If you want to update this information, you will need to create a new load balancer.)
  6. Click Continue.

Configure the health check:

  1. Go to the Configure Health Check page of the Create a New Load Balancer wizard, fill out the fields under Configuration Options
  2. On the Configure Health Check page, under Advanced Options, set the Healthy Threshold to 10. Accept the default values on the other options
  3. Click Continue.

Add Amazon EC2 instances:

  1. On the Add EC2 Instances page, click Continue.
  2. Review your settings. To make changes to the settings, click the Edit link for a specific step in the process. (After you create a load balancer, you can modify any of the settings except for Load Balancer Name and Port Configuration. To rename a load balancer or change its port configuration, create a replacement load balancer)
  3. Click Create
  4. On the Confirmation page, click Close. The confirmation window closes, returning you to the Load Balancers page. Your new load balancer now appears in the list. As a best practice, you should have sufficient instances across Availability Zones to survive the loss of any one Availability Zone. Therefore, we will ensure that our load balancer points to multiple Availability Zones in the next step.

Record the public DNS address:

  1. In the Load Balancers pane, click MyLB.
  2. Click the Description tab.
  3. Write down the public DNS address (the A record)

Add an Availability Zone:

  1. In the Load Balancers pane, click MyLB.
  2. Click the Instances tab.
  3. Click the plus icon.
  4. In the Add and Remove Availability Zones dialog box, select the availability zone (which may show 0 instances). In a later task, you will launch instances in these two Availability Zones by using Auto Scaling. You'll see that the Availability Zones column for the load balancer is updated for both Availability Zones.
  5. Click Save

How can we update your security group to allow HTTP traffic from only your load balancer?

  1. Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/.
  2. In the Navigation pane, in the Region list, click US East (Virginia).
  3. In the Navigation pane, click Security Groups.
  4. On the Security Groups page, click the security group webappsecuritygroup that you created in the previous procedure.
  5. Under Security Group, click the Inbound tab.
  6. In the row that displays port 80 (HTTP), click Delete.
  7. In the Create a new rule list, click HTTP.
  8. In the Source box, type amazon-elb/amazon-elb-sg. This is the name of the security group that AWS assigns to the Elastic Load Balancer. Click Add Rule.
  9. In the Create a new rule drop-down box, click MYSQL.
  10. In the Source box, type webappsecuritygroup. Select the security group ID for the webappsecuritygroup when it appears.
  11. Click Add Rule
  12. Click Apply Rule Changes.

How can we create an auto-scaling configuration?

The launch configuration is a template for the instances you launch in your Auto Scaling group. To define the launch configuration, we will use the as-create-launch-config command. The following parameters define your launch configuration:

  • image-id is the AMI ID. Use the custom AMI ID that you created in Step 6: Create a Custom AMI.
  • instance-type contains basic information, such as operating system, memory, and local storage, about the instance that you will launch. For this example, use the same instance type that you used when your first launched your instance.
  • key is the key pair used to connect to your instances. Use the same key pair that you created when you first launched your instance.
  • group is the security group where you defined the access rules for your instance. Use the same security group that you created when you first launched your instance.
  • monitoring-disabled specifies that you want to use basic monitoring instead of detailed monitoring. By default, detailed monitoring is enabled. For more information about basic and detailed monitoring, go to Amazon CloudWatch.

as-create-launch-config MyLC —image-id ami-95ce1afc —instance-type t1.micro —group webappsecuritygroup —key mykeypair —monitoring-disabled

How can we create an auto scaling group?

An Auto Scaling group is used to specify the launch configuration, availability zones, minimum and maximum number of instances that should be running, and the name of the load balancer. To create an Auto Scaling group to launch multiple Amazon EC2 instances, you will use the as-create-auto-scaling-group command. Use the following parameters to define your Auto Scaling group:

  • launch-configuration is the name of the launch configuration that you created in the previous step.
  • availability-zones specifies the Availability Zones where the Amazon EC2 instances in the Auto Scaling group will be launched. In this example, you will specify two Availability Zones. Specifying multiple Availability Zones is a good practice for building fault-tolerant applications. If one Availability Zone experiences an outage, traffic will be routed to another Availability Zone. The number of instances that are launched in the Auto Scaling group will be evenly distributed across the Availability Zones.
  • min-size and max-size set the minimum and maximum number of Amazon EC2 instances in the Auto Scaling group. By setting the minimum and maximum number to be the same, you can fix the number of instances in your group. In this example, set both the minimum and maximum number to 2.
  • load-balancer is the name of the load balancer that is used to route traffic to the Auto Scaling group.

as-create-auto-scaling-group MyAutoScalingGroup —launch-configuration MyLC —availability-zones us-east-1b, us-east-1c —min-size 2 —max-size 2 —load-balancers MyLB

How can we create a scaling policy?

To create a policy to enlarge your fleet of instances, use the Auto Scaling as-put-scaling-policy command. This policy applies to your Auto Scaling group you created in the previous step. Use the following parameters when defining your Auto Scaling policy:

  • auto-scaling-group is the name of the Auto Scaling group that you want to apply the policy to. Use the Auto Scaling group name that you created in the previous step.
  • adjustment is the number of instances you want to increment or decrement. For this example, use 1.
  • type is the type of policy you want to create. For this example, use ChangeInCapacity to change the fleet size of your instances.
  • cooldown is the time, in seconds, after an action before Auto Scaling should evaluate conditions again.

as-put-scaling-policy MyScaleUpPolicy —auto-scaling-group MyAutoScalingGroup —adjustment=1 —type ChangeInCapacity —cooldown 300

To save time, we created only a policy to add an instance. In most cases, you would also create a policy to terminate one or more instances when traffic declines. Auto Scaling can decrease the number of instances when your application doesn't need the resources, saving you money. To create a policy for terminating an instance, change the policy name, and then change the value of adjustment from 1 to -1. You use "—adjustment=-1" on a Windows machine.

as-put-scaling-policy MyScaleDownPolicy —auto-scaling-group MyAutoScalingGroup —adjustment=-1 —type ChangeInCapacity —cooldown 300

How can we create a cloud watch alarm and associate it with an auto-scaling policy?

Select a metric for your alarm:

  1. Open the Amazon CloudWatch console at https://console.aws.amazon.com/cloudwatch/.
  2. In the Navigation pane, in the Region list, click US East (Virginia). Click Alarms.
  3. In the details pane, click Create Alarm.
  4. In the Create Alarm Wizard, on the Select Metric page, in the Viewing list, select EC2: Aggregated by Auto Scaling Group.
  5. Click the MyAutoScalingGroup/NetworkOut row, and then click Continue (It can take up to 15 minutes for the Auto Scaling group to appear in the list. If you do not see your Auto Scaling group, wait up to 15 minutes, and then try again.)

Define the alarm:

  1. Fill out the form on the Define Alarm page of the Create Alarm wizard

Define your actions:

  1. Fill out the form on the Configure Actions page of the Create Alarm wizard. (Under When Alarm state is, click ALARM. Under the Take Action list, click Auto Scaling Policy. In the Auto Scaling Group list, clickMyAutoScalingGroup. In the Policy list, click MyScaleUpPolicy (Add 1 instance))
  2. In the new row that is created, under When Alarm state is, click ALARM. Under the Take Action list, click Send Notification. In the Topic box, type a topic name. In the Email(s) box, type an email address where notifications will be sent.
  3. Click Continue
  4. On the Review page, review the settings. If everything is all right, click Create Alarm.
  5. On the confirmation page, click Close.
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License