67
入門ガイド Linux 用 AWS コンピューティングの基本

入門ガイド - Amazon Web Servicesawsdocs.s3.amazonaws.com/gettingstarted/latest/awsgsg...設定済みの新しいAmazonEC2インスタンスを簡単に起動できるよ うにするために、新たなベースライン(たたき台)となるカスタムAMIを作成します。

  • Upload
    others

  • View
    3

  • Download
    0

Embed Size (px)

Citation preview

Page 1: 入門ガイド - Amazon Web Servicesawsdocs.s3.amazonaws.com/gettingstarted/latest/awsgsg...設定済みの新しいAmazonEC2インスタンスを簡単に起動できるよ うにするために、新たなベースライン(たたき台)となるカスタムAMIを作成します。

入門ガイドLinux 用 AWS コンピューティングの基本

Page 2: 入門ガイド - Amazon Web Servicesawsdocs.s3.amazonaws.com/gettingstarted/latest/awsgsg...設定済みの新しいAmazonEC2インスタンスを簡単に起動できるよ うにするために、新たなベースライン(たたき台)となるカスタムAMIを作成します。

入門ガイド: Linux 用 AWS コンピューティングの基本Copyright © 2013 Amazon Web Services, Inc. and/or its affiliates. All rights reserved.

The following are trademarks or registered trademarks of Amazon: Amazon, Amazon.com, Amazon.comDesign, Amazon DevPay, Amazon EC2, Amazon Web Services Design, AWS, CloudFront, EC2, ElasticCompute Cloud, Kindle, and Mechanical Turk. In addition, Amazon.com graphics, logos, page headers,button icons, scripts, and service names are trademarks, or trade dress of Amazon in the U.S. and/or othercountries. Amazon's trademarks and trade dress may not be used in connection with any product or servicethat is not Amazon's, in any manner that is likely to cause confusion among customers, or in any mannerthat disparages or discredits Amazon.

All other trademarks not owned by Amazon are the property of their respective owners, who may or maynot be affiliated with, connected to, or sponsored by Amazon.

入門ガイド Linux 用 AWS コンピューティングの基本

Page 3: 入門ガイド - Amazon Web Servicesawsdocs.s3.amazonaws.com/gettingstarted/latest/awsgsg...設定済みの新しいAmazonEC2インスタンスを簡単に起動できるよ うにするために、新たなベースライン(たたき台)となるカスタムAMIを作成します。

Overview ................................................................................................................................................. 1使用開始 .................................................................................................................................................. 7Step 1: Sign Up for the Service ............................................................................................................... 8ステップ 2: コマンドラインツールをインストールする ........................................................................ 8ステップ 3: 適切な AMI を見つける ........................................................................................................ 9ステップ 4: インスタンスを起動する ................................................................................................... 10ステップ 5: アプリケーションをデプロイする ..................................................................................... 14

ウェブブラウザからMindTerm SSHクライアントを使用してAmazon EC2インスタンスに接続する ...................................................................................................................................... 15PuTTY を使用して Windows コンピュータから Amazon EC2 インスタンスに接続する .......... 16Linux/UNIX マシンからスタンドアロンの SSH クライアントを使用して Amazon EC2 インスタンスに接続する .................................................................................................................... 20Amazon EC2 インスタンスを設定する ....................................................................................... 21

手順6:カスタム AMI を作成 ................................................................................................................ 28手順 7:Elastic Load Balancing の作成 ................................................................................................ 29ステップ 8: Amazon EC2 セキュリティグループを更新する .............................................................. 36ステップ 9: Auto Scaling を使用して Amazon EC2 インスタンスを起動する ..................................... 37ステップ 10: CloudWatch アラームを作成する .................................................................................... 42手順 11: クリーンアップ ....................................................................................................................... 50

Delete Your CloudWatch Alarm ................................................................................................... 50Delete Your Elastic Load Balancer .............................................................................................. 51Terminate Your Amazon EC2 Instances in Your Auto Scaling Group ......................................... 51インスタンスの終了 .................................................................................................................... 53キーペアの削除 ............................................................................................................................ 53Delete an Amazon EC2 Security Group ...................................................................................... 53

Pricing ................................................................................................................................................... 55Amazon EC2 Cost Breakdown .............................................................................................................. 55Summing It All Up ................................................................................................................................. 58How To Further Save Costs .................................................................................................................. 59Related Resources ................................................................................................................................ 62Document History .................................................................................................................................. 64

3

入門ガイド Linux 用 AWS コンピューティングの基本

Page 4: 入門ガイド - Amazon Web Servicesawsdocs.s3.amazonaws.com/gettingstarted/latest/awsgsg...設定済みの新しいAmazonEC2インスタンスを簡単に起動できるよ うにするために、新たなベースライン(たたき台)となるカスタムAMIを作成します。

Overview

When you deploy any type of application, you typically need to do the following:

• Set up a computer to run your application.• Secure your application and resources.• Set up your network for users to access your application.• Scale your application.• Monitor your application and resources.• Ensure that your application is fault-tolerant.

This guide introduces you to several key AWS services and components that help address these basicneeds. In this guide, you will learn more about what these key services are, why they are important indeploying a web application, and how to use them.

To help you learn about the key AWS services, we’ll review an example architecture of a web applicationhosted on AWS, and we’ll walk through the process of deploying Drupal. (Drupal is an open-source contentmanagement system.) You can adapt this sample to your specific needs if you want. By the end of thiswalkthrough, you should be able to do the following:

• Sign up for AWS.• Launch, connect, secure, and deploy Drupal to a computer in the cloud.• Create a custom template of a computer containing the hardware, software, and configuration youneed.

• Set up a load balancer to distribute traffic across multiple computers in the cloud.• Scale your fleet of computers in the cloud.• Monitor the health of your application and computers.• Clean up your AWS resources.

For a deeper understanding of AWS best practices and the various options that AWS provides, werecommend that you readWeb Application Hosting: Best Practices at AWSCloud ComputingWhitepapers.

If you are looking for a quicker and easier way to deploy your web applications, you can use AWS ElasticBeanstalk. AWSElastic Beanstalk handles the deployment details of capacity provisioning, load balancing,auto scaling, and application health monitoring using several of the services discussed in this document.To learn how to get started with AWS Elastic Beanstalk in the AWS Free Usage Tier, go to Deploy a

1

入門ガイド Linux 用 AWS コンピューティングの基本

Page 5: 入門ガイド - Amazon Web Servicesawsdocs.s3.amazonaws.com/gettingstarted/latest/awsgsg...設定済みの新しいAmazonEC2インスタンスを簡単に起動できるよ うにするために、新たなベースライン(たたき台)となるカスタムAMIを作成します。

Sample Web Application in the Free Usage Tier in the AWS Getting Started Guide: AWS Free UsageTier.

If this guide is not exactly what you are looking for, you may want to check out the following documents:

• Getting Started with AWS — Provides information about Amazon Web Services, with helpful links forlearning more.

• Getting Started Guide: AWS Free Usage Tier — Provides information about how to get started withthe free usage tier.

• Getting Started Guide AWSWeb Application Hosting for Linux—Provides a more in-depth walkthroughthat uses more services, such as Amazon Relational Database Service (Amazon RDS) and AmazonRoute 53.

• Hosting Websites on Amazon S3 in the Amazon Simple Storage Service Developer Guide — Providesa walkthrough in just a few steps of a static website deployment that does not require running anapplication.

• Getting Started with AWSCloudFormation in the AWSCloudFormation User Guide—Helps you quicklyget started using an AWS CloudFormation WordPress blog sample template without needing to figureout the order in which AWS services need to be provisioned or worry about the subtleties of how tomake those dependencies work.

• Amazon Elastic Compute Cloud Getting Started Guide — Provides information that helps you getstarted using Amazon EC2 instances.

Introduction to AWSIf you are responsible for running a web application, you face a variety of infrastructure and architectureissues for which AWS can give you easy, seamless, and cost-effective solutions. This section providesa list of Amazon Web Services and components, and it explains the value they add in meeting thechallenges you'll face in this example solution. We break this down in to the following sections: computingresources, security, monitoring, networking, and fault-tolerance.

Computing ResourcesWhen you deploy an on-premises solution, you need to buy a computer with an operating system, software,and hardware that match your needs. When you deploy your solution on Amazon Web Services, youselect an Amazon Machine Image (AMI) and then use it to deploy a virtual server known as an AmazonElastic Compute Cloud (EC2) instance. An AMI is a template that contains a software configuration (e.g.,operating system, application server, and applications). For example, an AMI might contain all the softwareto act as a web server (e.g., Linux, Apache, and your website). A large selection of public AMIs is availablefrom Amazon and the Amazon EC2 community. You can find an AMI that most closely matches yourneeds and then customize it. You can save this customized configuration to another AMI, which you canuse to launch new Amazon EC2 instances whenever you need them.

Storage can be an integral part of an Amazon EC2 instance, or it can be an independent componentwhose lifetime is managed separately from the lifetime of the instance. There are AMIs for each storagestrategy, and you will need to decide which type you want to use. When you launch your Amazon EC2instances, you can store your root device data on Amazon Elastic Block Store (Amazon EBS) or the localinstance store. Amazon Elastic Block Store (Amazon EBS) is a durable, block-level storage volume thatyou can attach to a single Amazon EC2 running instance. Amazon EBS volumes behave like raw,unformatted, external block devices you can attach. They persist independently from the running life ofan Amazon EC2 instance. Alternatively, the local instance store is a temporary storage volume andpersists only during the life of the instance. You might use Amazon EBS-backed instances for web ordatabase servers that keep state locally and require the data to be available even if the associated instancecrashes. You might use Amazon instance-store backed instances to manage traffic on large web sites

2

入門ガイド Linux 用 AWS コンピューティングの基本Introduction to AWS

Page 6: 入門ガイド - Amazon Web Servicesawsdocs.s3.amazonaws.com/gettingstarted/latest/awsgsg...設定済みの新しいAmazonEC2インスタンスを簡単に起動できるよ うにするために、新たなベースライン(たたき台)となるカスタムAMIを作成します。

where each instance is a clone. This is an inexpensive way to launch instances where data is not storedto the root device. To summarize the two key differences between these AMIs:

• You can stop and restart an Amazon EBS-backed instance, but you can only run or terminate anAmazon EC2 instance store-backed instance.

• By default, any data on the instance store is lost if the instance fails or terminates. Data on AmazonEBS-backed instances is stored on an Amazon EBS volume, so no data is lost if the instance isterminated.

For more information about the differences between instance store-backed and Amazon EBS-backedinstances, go to Basics of Amazon EBS-Backed AMIs and Instances in the Amazon Elastic ComputeCloud User Guide.

SecurityWhen you buy a new computer, you create a user name and password, which you then use to log in. InAWS, you use a public/private key pair to sign in to your Amazon EC2 instance. The public key is embeddedin your instance, and you use the private key to sign in securely without a password. When connectingto Amazon Linux instances, you initially sign in with a username of "ec2-user" or "root," depending on theAMI you are using.

When you deploy your application, you’ll want to secure your system. For an on-premises deployment,you would normally specify the ports and the protocols in which users can access your application. InAWS, you do the same thing. AWS has security groups that act like inbound network firewalls so you candecide who can connect to your Amazon EC2 instances over which ports.

ScalingYou may find that your application traffic varies during the day. For example, from 9 a.m. to 5 p.m., youmay experience peak traffic; for the rest of the day, traffic may be much slower. As traffic levels change,it would be useful to continually adjust the number of computers running your application to changes intraffic. Auto Scaling can automatically launch and terminate instances on your behalf according to thepolicies that you set. If you have defined a baseline AMI, Auto Scaling launches new instances with theexact same configuration. Auto Scaling can also send you notifications when it adds or removes instances.

MonitoringYou need to stay aware of the current performance and state of your resources. If your resources are notin the appropriate state, can’t handle the traffic load, or are sitting idle, you need to be alerted so you cantake appropriate action. Amazon CloudWatch monitors AWS cloud resources and the applications yourun on AWS. You can collect and track metrics, analyze the data, and react immediately to keep yourapplications and businesses running smoothly. You can use information from Amazon CloudWatch totake action on the policies that you set using Auto Scaling. For example, you can create an alarm thatnotifies you if your CPU utilization exceeds 95%. If the threshold is exceeded, Amazon CloudWatch sendsan alarm, and Auto Scaling takes action according to the policy that you set. In this example, Auto Scalingcan launch a new instance to handle the increased load. Similarly, you could set an alarm to notify youif your CPU utilization falls below a certain threshold. In that case, Auto Scaling could terminate an instance,saving you money.

You can monitor the status of your instances by viewing status checks and scheduled events for yourinstances. Automated status checks performed by Amazon EC2 detect whether specific issues areaffecting your instances. The status check information, together with the data provided by AmazonCloudWatch, gives you detailed operational visibility into each of your instances.

3

入門ガイド Linux 用 AWS コンピューティングの基本Security

Page 7: 入門ガイド - Amazon Web Servicesawsdocs.s3.amazonaws.com/gettingstarted/latest/awsgsg...設定済みの新しいAmazonEC2インスタンスを簡単に起動できるよ うにするために、新たなベースライン(たたき台)となるカスタムAMIを作成します。

You can also see the status of specific events scheduled for your instances. Scheduled events provideinformation about upcoming activities, such as rebooting or terminating an instance, that are planned foryour instances, along with the scheduled start and end times of each event. To learn more about instancestatus, go to Monitoring the Status of Your Instances in the Amazon Elastic Compute Cloud User Guide.

NetworkingIf you require multiple computers to host your web application, you need to balance the traffic acrossthose computers. Elastic Load Balancing provides this service in the same way that an on-premises loadbalancer does. You can associate a load balancer with an Auto Scaling group. As instances are launchedand terminated, the load balancer automatically directs traffic to the running instances. Elastic LoadBalancing also performs health checks on each instance. If an instance is not responding, the load balancercan automatically redirect traffic to the healthy instances.

AWS assigns a URL to your AWS resources, such as your Elastic Load Balancer and your Amazon EC2instances; however, you may want a URL that is more specific and easy to remember, such aswww.example.com. To do so, you need to purchase a domain name from a domain registrar. After youpurchase your domain name, you can use Amazon Route 53 to map your domain name to your AWSdeployment.

Youmay want to provision a private, isolated network. You can use Amazon Virtual Private Cloud (AmazonVPC) to provision a private, isolated section of the Amazon Web Services (AWS) cloud where you canlaunch AWS resources in a virtual network that you define. For example, if you are hosting a multitierweb application, you may want to customize the network configuration so that your web servers are publicfacing and your database and application servers are in a private-facing subnet with no Internet access.The application servers and databases can’t be directly accessed from the Internet, but they can stillaccess the Internet over a NAT instance so they can, for example, download patches.

You can control access between the servers and subnets by using inbound and outbound packet filteringprovided by network access control lists and security groups. Some other cases where you may want touse Amazon VPC include:

• Hosting scalable web applications in the AWS cloud that are connected to your data center• Extending your corporate network into the cloud• Disaster recovery

For information on how to get started using Amazon VPC, go to Get Started with Amazon VPC in theAmazon Virtual Private Cloud (Amazon VPC) Getting Started Guide.

Fault ToleranceTo make your web application fault-tolerant, you need to consider deploying your computers in differentphysical locations. It can be expensive to maintain hardware in different physical locations for anon-premises solution. AWS offers resources in different Availability Zones and regions. Availability Zonesare analogous to data centers. You can have multiple instances running in different Availability Zones sothat if one Availability Zone becomes unavailable (e.g., due to a natural disaster), then all traffic wouldbe routed to another Availability Zone. There are multiple Availability Zones in each region.

It’s even more advantageous to spread your instances across Regions. If a region, including all of itsAvailability Zones, becomes completely unavailable, your traffic is routed to another region.

SummaryThe following table summarizes the key challenges to developing a simple web application and the AWSservices that address these challenges.

4

入門ガイド Linux 用 AWS コンピューティングの基本Networking

Page 8: 入門ガイド - Amazon Web Servicesawsdocs.s3.amazonaws.com/gettingstarted/latest/awsgsg...設定済みの新しいAmazonEC2インスタンスを簡単に起動できるよ うにするために、新たなベースライン(たたき台)となるカスタムAMIを作成します。

BenefitAmazon Web ServicesChallenge

Amazon EC2 runs the web server andapplication servers.

Amazon Elastic Compute Cloud (EC2)Need computers torun yourapplication.

Elastic Load Balancing supports healthchecks on hosts, distribution of traffic toAmazon EC2 instances across multipleAvailability Zones, and dynamic additionand removal of Amazon EC2 hosts fromthe load-balancing rotation.

Elastic Load BalancingIncoming trafficneeds to be evenlydistributed acrosscomputers tomaximizeperformance.

Auto Scaling creates capacity groups ofservers that can grow or shrink ondemand.

Auto ScalingServers need to beprovisioned tohandle peakcapacity, but theunused cycles arewasted at othertimes.

Amazon CloudWatch reports metricsdata for Amazon EC2 instances, and themetrics it gathers are used by AutoScaling.

Amazon CloudWatchServers need to bemonitored forperformance andstate

Amazon EBS provides a persistent filesystem for web and application servers.

Amazon Elastic Block Store (AmazonEBS)

Applications mayrequire persistentstorage.

The following table summarizes additional challenges to developing a simple web application and theAWS components that address these challenges.

BenefitAWS ComponentChallenge

A key pair is a security credential similarto a password, which you use to securelyconnect to your instance after theinstance running.

Amazon Key PairNeed a securemechanism toconnect to thecomputer.

An Amazon Security Group gives youcontrol over the protocols, ports, andsource IP address ranges that areallowed to reach your Amazon EC2instances.

Amazon Security GroupNeed to providesecurity to protectapplication serversfrom outsidemalicious users.

Availability Zones are distinct locationsengineered to be insulated from failuresin other Availability Zones. EachAvailability Zone provides inexpensive,low-latency network connectivity to otherAvailability Zones in the same region.

Availability ZonesNeed to designwith failover inmind.

5

入門ガイド Linux 用 AWS コンピューティングの基本Summary

Page 9: 入門ガイド - Amazon Web Servicesawsdocs.s3.amazonaws.com/gettingstarted/latest/awsgsg...設定済みの新しいAmazonEC2インスタンスを簡単に起動できるよ うにするために、新たなベースライン(たたき台)となるカスタムAMIを作成します。

Sample ArchitectureThe following diagram shows an example architecture that uses the AWS resources mentioned in theprevious section.

As an example, we’ll walk through a deployment of a simple web application. If you’re doing somethingelse, you can adapt this example architecture to your specific situation. In this diagram, Amazon EC2instances in a security group run the application and web server. The Amazon EC2 Security Group actsas an exterior firewall for the Amazon EC2 instances. An Auto Scaling group maintains a fleet of AmazonEC2 instances that can be automatically added to or removed in order to handle the presented load. ThisAuto Scaling group spans two Availability Zones to protect against potential failures in either AvailabilityZone. To ensure that traffic is distributed evenly among the Amazon EC2 instances, an Elastic LoadBalancer is associated with the Auto Scaling group. If the Auto Scaling group launches or terminatesinstances to respond to load changes, the Elastic Load Balancer automatically adjusts accordingly.

For a step-by-step walkthrough of how to build out this architecture, see使用開始 (p. 7). This walkthroughwill teach you how to do the following:

• Sign up for AWS.• Launch, connect, and deploy Drupal to an Amazon EC2 instance.• Create a Custom AMI.• Set up an Elastic Load Balancer to distribute traffic across your Amazon EC2 instances.• Scale your fleet of instances automatically using Auto Scaling.• Monitor your AWS resources using Amazon CloudWatch.• Clean up your AWS resources.

6

入門ガイド Linux 用 AWS コンピューティングの基本Sample Architecture

Page 10: 入門ガイド - Amazon Web Servicesawsdocs.s3.amazonaws.com/gettingstarted/latest/awsgsg...設定済みの新しいAmazonEC2インスタンスを簡単に起動できるよ うにするために、新たなベースライン(たたき台)となるカスタムAMIを作成します。

使用開始

Topics• Step 1: Sign Up for the Service (p. 8)• ステップ 2: コマンドラインツールをインストールする (p. 8)• ステップ 3: 適切な AMI を見つける (p. 9)• ステップ 4: インスタンスを起動する (p. 10)• ステップ 5: アプリケーションをデプロイする (p. 14)• 手順6:カスタム AMI を作成 (p. 28)• 手順 7:Elastic Load Balancing の作成 (p. 29)• ステップ 8: Amazon EC2 セキュリティグループを更新する (p. 36)• ステップ 9: Auto Scaling を使用して Amazon EC2 インスタンスを起動する (p. 37)• ステップ 10: CloudWatch アラームを作成する (p. 42)• 手順 11: クリーンアップ (p. 50)

オープンソースのコンテンツ管理システム(CMS)である Drupal をデプロイする必要があるとします。初めてでも簡単です。ほとんどのタスクにはAWSマネジメントコンソールを使用できます。このトピックでは、ウェブアプリケーションをAWSにデプロイするための一連の手順について、順を追って説明します。ウェブアプリケーションのデプロイに取り組むにはさまざまな方法があります。このチュートリアルで採用している手法はベストプラクティスに従っています。また、いくつかのコアサービスを使用し、それらがどのように連携するかを把握できるようにしています。

AWSを使用したDrupalのデプロイを開始する前に、AWSアカウントにサインアップし、AutoScalingコマンドラインツールをインストールする必要があります。AWS にサインアップするとすべてのサービスにアクセスできますが、料金は使用したものに対してのみかかります。

まず、お使いのハードウェアおよびソフトウェアのニーズを満たす適切なAMIを見つけます。このAMIを使用して Amazon EC2 インスタンスを起動します。Amazon EC2 インスタンスを起動したら、新しいキーペアとセキュリティグループを作成します。セキュリティグループには Amazon EC2 インスタンスにアクセスできるユーザーについてのルールを設定します。キーペアは Amazon EC2 インスタンスへの接続に必要になります。

インスタンスを安全に実行している状態で、必要なソフトウェアのインストールを完了し、次にDrupalアプリケーションを設定します。設定済みの新しい Amazon EC2 インスタンスを簡単に起動できるようにするために、新たなベースライン(たたき台)となるカスタム AMI を作成します。

次に、Elastic LoadBalancerを作成してトラフィック負荷を複数のインスタンスに分散させます。続いてセキュリティグループを更新し、すべてのHTTPトラフィックではなく、お使いのロードバランサー

7

入門ガイド Linux 用 AWS コンピューティングの基本

Page 11: 入門ガイド - Amazon Web Servicesawsdocs.s3.amazonaws.com/gettingstarted/latest/awsgsg...設定済みの新しいAmazonEC2インスタンスを簡単に起動できるよ うにするために、新たなベースライン(たたき台)となるカスタムAMIを作成します。

からのHTTPトラフィックのみを許可するようにします。Elastic Load Balancerは、インスタンスを起動する前に作成します。Auto ScalingグループをElastic Load Balancerに関連付けることができるようにするためです。このようにすると、ロードバランサーは自動的に、終了したインスタンスへのトラフィックのルーティングを停止し、新たに起動したインスタンスへのトラフィックのルーティングを開始できます。

ここで Auto Scaling を使用して Amazon EC2 インスタンスを起動します。グループ内のインスタンス数を増減させるタイミングを Auto Scaling に伝える Auto Scaling ポリシーを作成します。

最後に、AutoScalingグループのインスタンスをモニタリングして、そのポリシーに応じてアクションを実行するタイミングを Auto Scaling グループに伝える CloudWatch アラームを作成します。

これはサンプルデプロイなので、作成したすべての AWS リソースを終了することをお勧めします。AWS リソースを終了すると、ただちにそのリソースの料金がかからなくなります。

Step 1: Sign Up for the ServiceIf you don't already have an AWS account, you’ll need to get one. Your AWS account gives you accessto all services, but you will be charged only for the resources that you use. For this example walkthrough,the charges will be minimal.

To sign up for AWS

1. Go to http://aws.amazon.com and click Sign Up Now.2. Follow the on-screen instructions.

AWS notifies you by email when your account is active and available for you to use.

The credentials for your AWS account give you access to all the resources that you have deployed. Ifyou give other people access to your resources, you will probably want to control who has access andwhat they can do. AWS Identity and Access Management (IAM) is a web service that controls access toyour resources by other people. In IAM, you create a user, which other people can use to obtain accessand permissions that you define. For more information about IAM, go to What Can I Do with IAM?

ステップ2:コマンドラインツールをインストールする

AutoScalingで使用するコマンドラインをいくつかインストールする必要があります。有料サービスの使用を最小限にとどめるには、まずこれを実行してください。

Auto Scaling コマンドラインツールをローカルコンピュータにインストールするには、Auto ScalingDeveloper Guide の Using the Command Line Tools を参照してください。コマンドラインツールをインストールしたら、いくつかのコマンドを試して動作を確認します。例えば、プロンプトでas-cmdコマンドを入力してみてください。

PROMPT>as-cmd

このコマンドは、すべての Auto Scaling コマンドとその説明を返します。以下の図のような結果が表示されるはずです。

8

入門ガイド Linux 用 AWS コンピューティングの基本Step 1: Sign Up for the Service

Page 12: 入門ガイド - Amazon Web Servicesawsdocs.s3.amazonaws.com/gettingstarted/latest/awsgsg...設定済みの新しいAmazonEC2インスタンスを簡単に起動できるよ うにするために、新たなベースライン(たたき台)となるカスタムAMIを作成します。

コマンドラインツールをインストールしたら、AWSリソースの作成を開始できます。ステップ3:適切な AMI を見つける (p. 9) に進み、適切な AMI を見つける方法の詳細について学習します。この AMIを使用して Amazon EC2 インスタンスを起動します。これはまた、独自のカスタム AMI を作成するベースラインともなります。

ステップ 3: 適切な AMI を見つけるAmazon Machine Image(AMI)には、ソフトウェアのインスタンスを起動するのに必要なすべての情報が格納されています。例えば、ウェブサーバーとして動作するのに必要なすべてのソフトウェア(Linux、Apache、ウェブサイト)が格納された AMI などがあります。この説明では、これらの AMIの 1 つを使用します。1つの AMI から 1 つ以上の Amazon EC2 インスタンスを起動できますが、すべてのインスタンスは完全に同一になります。

Amazon および Amazon EC2 コミュニティから、多様な AMI が提供されています。詳細については、AWS ウェブサイトの Amazon Machine Images (AMIs) を参照してください。

AWS マネジメントコンソール(http://console.aws.amazon.com)を使用して特定の条件を満たす AMIを検索し、それら AMI のインスタンスを起動することができます。例えば、Amazon が提供しているAMI、EC2 コミュニティが提供している AMI、特定のオペレーティングシステムを使用する AMI などを表示できます。

このタスクでは、Apache、MySQL、PHP、Drupal がインストールされたAmazon Linux AMIを使用します。この AMI をベースラインとしてカスタマイズし、後のタスクで独自のカスタム AMI を作成することができます。

適切な AMI を見つけるには

1. Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/.2. [Navigation] ペインの [AMIs] をクリックします。

9

入門ガイド Linux 用 AWS コンピューティングの基本ステップ 3: 適切な AMI を見つける

Page 13: 入門ガイド - Amazon Web Servicesawsdocs.s3.amazonaws.com/gettingstarted/latest/awsgsg...設定済みの新しいAmazonEC2インスタンスを簡単に起動できるよ うにするために、新たなベースライン(たたき台)となるカスタムAMIを作成します。

3. [Amazon Machine Images] ペインで、[All Platforms] と表示された [Viewing] リストから [Linux] をクリックします。[All Images] と表示されたリストで、表示を絞り込む希望のオプションを選択します。この例では、[Amazon Images] をクリックして、アマゾンウェブサービスによって提供されている AMI に表示を限定します。テキストボックスに drupal と入力します。

4. DrupalがすでにインストールされているAMI(ami-7813e011など)を選択し、[Launch]をクリックします。

このAMI をベースラインとして使用します。[Launch] をクリックすると [Request Instances] ウィザードが起動するので、ウィザードに従ってインスタンスを設定して起動します。

ステップ 4: インスタンスを起動する前のステップで選択した AMI を使用して Amazon EC2 インスタンスを起動する準備ができました。インスタンスの起動には以下のタスクが関連します。

• インスタンスを設定します。• キーペアを作成します。• セキュリティグループを作成します。• インスタンスを起動します。

Important

起動しようとしたインスタンスが起動します。このチュートリアルにある最後のタスクでインスタンスを終了するまで、Amazon EC2 使用料が発生します。チュートリアルを 1 回のセッションで完了すると、合計金額は最小になります(多くの場合 1 USD 未満です)。AmazonEC2 使用料に関する詳細は、Amazon EC2 製品ページを参照してください。

Amazon EC2 インスタンスを起動するには

1. AMIを選択し、前のステップと同様に[Launch Instance]をクリックすると、[Create aNew Instance]ページが表示されます。このページでは、インスタンスを起動する 2 つの方法が提供されます。

• Classic Wizard では、起動するインスタンスのタイプを詳細に設定できます。• Quick Launch Wizard では、プロセスが単純化されており、多数の選択項目が自動的に設定されるので、インスタンスの使用をすぐに開始できます。

• AWSMarketplaceは、AWS上で実行されるソフトウェアを購入できるオンラインストアです。ワンクリックでインスタンスを起動できます。

10

入門ガイド Linux 用 AWS コンピューティングの基本ステップ 4: インスタンスを起動する

Page 14: 入門ガイド - Amazon Web Servicesawsdocs.s3.amazonaws.com/gettingstarted/latest/awsgsg...設定済みの新しいAmazonEC2インスタンスを簡単に起動できるよ うにするために、新たなベースライン(たたき台)となるカスタムAMIを作成します。

このチュートリアルで説明する手順では、Classic Wizard を使用します。[Create a New Instance]ページの [Classic Wizard] をクリックします。

2. [Request Instances] ウィザードの [Instance Details] ペインで、[Availability Zone] リストから[us-east-1b] を選択します。

このページにあるその他のデフォルト値を受け入れ、[Continue]をクリックします。後続の2ページにあるデフォルト値を受け入れ、それぞれ [Continue] をクリックします。ウィザードで [CreateKey Pair] ページが表示されたら、次のステップに進みます。

3. キーペアの作成:

a. パブリック AMI から作成された Amazon EC2 インスタンスでは、サインインにパスワードではなくパブリックキーとプライベートキーのペアを使用します。パブリックキーはインスタンスに埋め込まれています。プライベートキーを使用して、パスワードなしで安全にサインインします。独自 AMI の作成後は、新しいインスタンスに安全にログインするための他のメカニズムを選択できます。

Amazon EC2 を初めて使用する場合でまだキーペアを作成していなければ、ウィザードの[Create Key Pair] ページが表示されたときに、[Create a new Key Pair] ボタンがデフォルトで選択されています。

[Create Key Pair] ページの [Enter a name for your key pair] ボックスに mykeypairと入力します。これが、ペアに関連付けられているプライベートキーファイルの名前となります (拡張子 .pemが付きます)。

11

入門ガイド Linux 用 AWS コンピューティングの基本ステップ 4: インスタンスを起動する

Page 15: 入門ガイド - Amazon Web Servicesawsdocs.s3.amazonaws.com/gettingstarted/latest/awsgsg...設定済みの新しいAmazonEC2インスタンスを簡単に起動できるよ うにするために、新たなベースライン(たたき台)となるカスタムAMIを作成します。

b. 作成 &キーペアをダウンロードをクリックします。キーペアのプライベートキーをシステムへ保存するように求められます。

c. プライベートキーをお使いのシステムの安全な場所に保存し、保存した場所を記録します。

Important

AmazonEC2インスタンスに接続するにはキーペアが必要です。キーペアを紛失すると接続できなくなります。

ウィザードに [”Configure Firewall”] ページが表示されます。ここでセキュリティグループを作成します。

4. セキュリティグループの作成:

セキュリティグループは、インスタンスのファイアウォールルールを定義します。これらのルールは、どの着信ネットワークトラフィックがインスタンスに配信されるべきかを指定します(例:ポート 80 のウェブトラフィックを受け入れる)。他のすべてのトラフィックは遮断されます。グループのルールはいつでも変更することができます。新しいルールが自動的に実行中のすべてのインスタンスに適用されます。セキュリティグループの詳細については、Amazon Elastic ComputeCloud (Amazon EC2) の セキュリティグループの使用を参照してください。

a. [Group Name] ボックスで、webappsecuritygroupと入力します。b. [Description] ボックスにセキュリティグループの説明を入力します。c. [Inbound Rules] の [Create a New Rule] で、[SSH] をクリックして [Add Rule] をクリックしま

す。

12

入門ガイド Linux 用 AWS コンピューティングの基本ステップ 4: インスタンスを起動する

Page 16: 入門ガイド - Amazon Web Servicesawsdocs.s3.amazonaws.com/gettingstarted/latest/awsgsg...設定済みの新しいAmazonEC2インスタンスを簡単に起動できるよ うにするために、新たなベースライン(たたき台)となるカスタムAMIを作成します。

Caution

このセキュリティグループにより、すべての IP アドレスが、SSH 経由でお使いのインスタンスにアクセスできます。これは、このチュートリアルの短い実習では許容されますが、実稼働環境には安全ではありません。実稼働環境では、特定の IP アドレスまたは特定のアドレス範囲に、インスタンスへのアクセスを限定します。

d. [Inbound Rules]の下にある [Create a NewRule]ボックスで、[HTTP]をクリックしてから [AddRule] をクリックします。

e. [Continue] をクリックします。

セキュリティグループが作成され、ID(sg-48996e20 など)が割り当てられます。インスタンスは、この新しいセキュリティグループに起動されます。

5. 設定を確認してインスタンスを起動:

a. すべての設定が希望通りに完了したら、[Launch] をクリックします。b. 確認メッセージが表示されたら、[Close] をクリックします。c. [Navigation]ペインの[Instances]をクリックして、インスタンスのステータスを表示します。

インスタンスはすぐに起動します。インスタンスの起動中、そのステータスは「pending」と示されます。

まもなく、インスタンスのステータスが「running」に変わります。任意のタイミングで表示を手動で更新するには、[Refresh] をクリックします。

13

入門ガイド Linux 用 AWS コンピューティングの基本ステップ 4: インスタンスを起動する

Page 17: 入門ガイド - Amazon Web Servicesawsdocs.s3.amazonaws.com/gettingstarted/latest/awsgsg...設定済みの新しいAmazonEC2インスタンスを簡単に起動できるよ うにするために、新たなベースライン(たたき台)となるカスタムAMIを作成します。

d. インスタンスのパブリック DNS 名を記録します。

• 実行中のインスタンスを選択します。下ペインに記載されたパブリック DNS アドレスをメモします。これは次のタスクで必要になります。

インスタンスのステータスが「running」であれば、インスタンスに接続してアプリケーションをデプロイできます。

ステップ 5: アプリケーションをデプロイするTopics• ウェブブラウザから MindTerm SSH クライアントを使用して Amazon EC2 インスタンスに接続する (p. 15)

• PuTTY を使用してWindows コンピュータから Amazon EC2 インスタンスに接続する (p. 16)• Linux/UNIX マシンからスタンドアロンの SSH クライアントを使用して Amazon EC2 インスタンスに接続する (p. 20)

• Amazon EC2 インスタンスを設定する (p. 21)

Amazon EC2 インスタンスが起動したので、次はこのインスタンスに接続してアプリケーションをデプロイします。このステップでは、まずAmazonEC2インスタンスに接続します。次に、すでにLinuxAMI で利用可能な Drupal をデプロイします。

14

入門ガイド Linux 用 AWS コンピューティングの基本ステップ 5: アプリケーションをデプロイする

Page 18: 入門ガイド - Amazon Web Servicesawsdocs.s3.amazonaws.com/gettingstarted/latest/awsgsg...設定済みの新しいAmazonEC2インスタンスを簡単に起動できるよ うにするために、新たなベースライン(たたき台)となるカスタムAMIを作成します。

ウェブブラウザからMindTerm SSH クライアントを使用して Amazon EC2 インスタンスに接続するLinux/UNIX インスタンスにブラウザを使用して接続する手順は以下のとおりです。

1. Java をブラウザにインストールして有効にする (p. 15)2. MindTerm(SSH)クライアントを使用して接続する (p. 15)

Java をブラウザにインストールして有効にするインスタンスに Amazon Elastic Compute Cloud(Amazon EC2)コンソールから接続するには、Javaがブラウザにインストールされて有効化されている必要があります。Java をインストールして有効にするには、下記のOracleから提供されている手順を実行するか、組織の IT管理者に依頼してウェブブラウザに Java をインストールし、有効にしてください。

1. Java をインストールします(http://java.com/en/download/help/index_installing.xml を参照)。2. ウェブブラウザでJavaを有効にします(http://java.com/en/download/help/enable_browser.xmlを参照)。

MindTerm(SSH)クライアントを使用して接続するインスタンスにウェブブラウザから接続するには

1. Sign in to the AWS Management Console and open the Amazon EC2 console athttps://console.aws.amazon.com/ec2/.

2. Navigation ペインの Instances をクリックします。3. インスタンスを右クリックしてから、Connect をクリックします。4. [Connect from your browser using the MindTerm SSH client (Java Required)] をクリックします。

インスタンスのパブリック DNS アドレスと、インスタンス起動時に使用されたキーペア名が自動的に検出されます。

5. [User name] に、インスタンスにログインするためのユーザー名を入力します。この例では、ec2-userと入力します。

6. [Key name] 欄の内容は自動的に入力されます。7. [Path to private key] に、.pem プライベートキーファイルの完全修飾パスを入力します。8. [Save key location] をクリックし、[Stored in browser cache] をクリックしてキーの場所をブラウ

ザのキャッシュに保存します。これで、キーの場所が以降のブラウザセッションで検出されるようになります(ユーザーがブラウザのキャッシュをクリアするまでの間)。

9. [Launch MindTerm] をクリックします。

15

入門ガイド Linux 用 AWS コンピューティングの基本ウェブブラウザからMindTermSSHクライアントを使用し

て Amazon EC2 インスタンスに接続する

Page 19: 入門ガイド - Amazon Web Servicesawsdocs.s3.amazonaws.com/gettingstarted/latest/awsgsg...設定済みの新しいAmazonEC2インスタンスを簡単に起動できるよ うにするために、新たなベースライン(たたき台)となるカスタムAMIを作成します。

10. 必要に応じて、証明書を信頼するかどうかを指定する画面で Yes をクリックします。11. Run をクリックして MindTerm クライアントを実行します。12. ライセンス契約書に同意する場合は、Accept をクリックします。13. MindTermを実行するのが初めての場合は、ホームディレクトリなどの設定を確認するための一連

のダイアログボックスが表示されます。14. MindTerm の設定の内容を確認します。15. 次に示すような画面が開き、インスタンスに接続した状態になります。

PuTTY を使用してWindows コンピュータからAmazon EC2 インスタンスに接続するWindows をローカルマシンから実行している場合、Secure Shell(SSH)は内蔵されていないため、PuTTYとPuTTYGenをインストールする必要があります。ステップ4:インスタンスを起動する(p. 10)で作成したプライベートキーファイル(例: mykeypair.pem)の内容が必要になります。

16

入門ガイド Linux 用 AWS コンピューティングの基本PuTTY を使用してWindows コンピュータから Amazon

EC2 インスタンスに接続する

Page 20: 入門ガイド - Amazon Web Servicesawsdocs.s3.amazonaws.com/gettingstarted/latest/awsgsg...設定済みの新しいAmazonEC2インスタンスを簡単に起動できるよ うにするために、新たなベースライン(たたき台)となるカスタムAMIを作成します。

Windows マシンから Amazon EC2 インスタンスに接続するには

1. PuTTYとPuTTYGenをダウンロードしてインストールします。Googleで「ダウンロードPutty」と検索すると、ダウンロードサイトのリストが表示されます。必ず PuTTY と PuTTYGen の両方をインストールしてください。両方とも必要になります。

2. PuTTYGen を使用してキーペアを変換します。キーペアの詳細については、ステップ 4: インスタンスを起動する (p. 10) を参照してください。

a. PuTTYGen を起動します。[Conversions] メニューで、[Import Key] をクリックします。b. mykeypair.pemを見つけて [Open] をクリックします。

c. [Save private key]をクリックします。パスフレーズなしで続行するかどうかを尋ねるメッセージが表示されたら、[OK] をクリックします。キーを mykeypair.ppkとして保存します。

d. PuTTYGen を閉じます。

3. SSH を設定します。

a. PuTTY を起動し、[SSH] ノードを展開して、[Auth] をクリックします。b. [Private key file for authentication] ボックスに mykeypair.ppkの場所を入力します。

17

入門ガイド Linux 用 AWS コンピューティングの基本PuTTY を使用してWindows コンピュータから Amazon

EC2 インスタンスに接続する

Page 21: 入門ガイド - Amazon Web Servicesawsdocs.s3.amazonaws.com/gettingstarted/latest/awsgsg...設定済みの新しいAmazonEC2インスタンスを簡単に起動できるよ うにするために、新たなベースライン(たたき台)となるカスタムAMIを作成します。

4. キープアライブを変更します。

a. [PuTTY Configuration] ウィンドウの [Catgeory] ペインで、[Connection] をクリックします。b. [Seconds between keepalives (0 to turn off)] ボックスに 60と入力します。この値を変更しな

いと、セッションがタイムアウトします。

5. セッション設定を保存します。

a. [PuTTY Configuration] ウィンドウの [Category] ペインで、[Session] をクリックします。b. [Load, save, or delete a stored session] ボックスで、[Default Settings] をクリックし、[Save]

をクリックします。

18

入門ガイド Linux 用 AWS コンピューティングの基本PuTTY を使用してWindows コンピュータから Amazon

EC2 インスタンスに接続する

Page 22: 入門ガイド - Amazon Web Servicesawsdocs.s3.amazonaws.com/gettingstarted/latest/awsgsg...設定済みの新しいAmazonEC2インスタンスを簡単に起動できるよ うにするために、新たなベースライン(たたき台)となるカスタムAMIを作成します。

6. 前のタスクで取り出した Amazon EC2 インスタンスの DNS アドレスを入力します。

a. [PuTTYConfiguration]ウィンドウの [Catgeory]ペインで、[Session]をクリックします。[HostName (or IP address)] ボックスで、<ec2-user@Amazon EC2 インスタンスの DNS アドレス> を入力します。

Note

AMI のユーザー名は ec2-user です。

b. [Open] をクリックします。[PuTTY Security Alert] ダイアログボックスが表示されたら、[Yes]をクリックして、フィンガープリントが問題ないことを確認します。[SSH PuTTY] ウィンドウが開きます。

19

入門ガイド Linux 用 AWS コンピューティングの基本PuTTY を使用してWindows コンピュータから Amazon

EC2 インスタンスに接続する

Page 23: 入門ガイド - Amazon Web Servicesawsdocs.s3.amazonaws.com/gettingstarted/latest/awsgsg...設定済みの新しいAmazonEC2インスタンスを簡単に起動できるよ うにするために、新たなベースライン(たたき台)となるカスタムAMIを作成します。

Note

やがて、SSH フィンガープリントがシステムログに出現します。SSH フィンガープリントは、中間者攻撃を防ぐための比較対象として使用できます。詳細については、Amazon Elastic Compute Cloud (Amazon EC2) ユーザーガイドの PuTTY を使用した接続を参照してください。

画面は以下のようになるはずです。

インスタンスへのサインインが成功したら、インスタンスを設定する準備は完了です。インスタンスの設定手順については、Amazon EC2 インスタンスを設定する (p. 21) を参照してください。

Linux/UNIX マシンからスタンドアロンの SSH クライアントを使用してAmazon EC2インスタンスに接続するLinux/UNIXインスタンスにLinux/UNIXコンピュータから接続するには、sshコマンドを使用します。

Note

ほとんどの Linux/UNIX コンピュータは、デフォルトで Secure Shell(SSH)クライアントを内蔵しています。そうでない場合は、OpenSSHプロジェクトが、SSHツールの完全なスイートの無料実装を提供しています。詳細に関しては、http://www.openssh.org を閲覧してください。

接続に SSH を使用する方法

1. コマンドラインシェルで、ステップ 4: インスタンスを起動する (p. 10) で作成したプライベートキーファイルの場所にディレクトリを変更します。

2. chmodコマンドを使って、プライベートキーファイルが公開されていないことを確認します。例えば、mykeypair.pemについては以下のように入力します。

chmod 400 mykeypair.pem

20

入門ガイド Linux 用 AWS コンピューティングの基本Linux/UNIX マシンからスタンドアロンの SSH クライアントを使用して Amazon EC2 インスタンスに接続する

Page 24: 入門ガイド - Amazon Web Servicesawsdocs.s3.amazonaws.com/gettingstarted/latest/awsgsg...設定済みの新しいAmazonEC2インスタンスを簡単に起動できるよ うにするために、新たなベースライン(たたき台)となるカスタムAMIを作成します。

3. AWS マネジメントコンソールにサインインして Amazon EC2 コンソール(https://console.aws.amazon.com/ec2/)を開きます。

4. [Navigation] ペインで [Region] ドロップダウンメニューから [US East (Virginia)] を選択します。5. [Navigation] ペインの [Instances] をクリックします。6. インスタンスを右クリックしてから、Connect をクリックします。7. Connect using a standalone SSH client をクリックします。インスタンスのパブリック DNS アド

レスと、インスタンス起動時に使用されたキーペア名が自動的に検出されます。8. インスタンスのパブリック DNS 名を使用してインスタンスに接続します。例えば、キーファイル

が mykeypair.pemで、インスタンスのDNS名がec2-184-72-209-110.compute-1.amazonaws.comの場合は、以下のコマンドを使用します。

ssh -i mykeypair.pem [email protected]

Note

この演習では、この AMI について、ec2-userというユーザー名を使用します。

以下のようなレスポンスが表示されます。

The authenticity of host 'ec2-184-72-209-110.compute-1.amazonaws.com (10.254.142.33)'can't be established.RSA key fingerprint is 00:00:00:00:00:00:00:00:00:00:00:00:00:00:00.Are you sure you want to continue connecting (yes/no)? yes

Note

やがて、SSH フィンガープリントがシステムログに出現します。SSH フィンガープリントは、中間者攻撃を防ぐための比較対象として使用できます。詳細については、AmazonElastic Compute Cloud (Amazon EC2) User GuideのConnect to Linux/UNIX Instances fromLinux/UNIX with SSH を参照してください。

9. yesと入力します。

以下のようなレスポンスが表示されます。

Warning: Permanently added 'ec2-184-72-209-110.compute-1.amazonaws.com' (RSA) to the list of known hosts.

インスタンスへのログインが成功したら、インスタンスを設定する準備は完了です。インスタンスの設定手順については、Amazon EC2 インスタンスを設定する (p. 21) を参照してください。

Amazon EC2 インスタンスを設定するこのトピックでは、稼働中のインスタンスを設定します。以下のタスクを実行します。

• 設定ファイルに権限を設定します。• MySQL サーバーをインストールします。

21

入門ガイド Linux 用 AWS コンピューティングの基本Amazon EC2 インスタンスを設定する

Page 25: 入門ガイド - Amazon Web Servicesawsdocs.s3.amazonaws.com/gettingstarted/latest/awsgsg...設定済みの新しいAmazonEC2インスタンスを簡単に起動できるよ うにするために、新たなベースライン(たたき台)となるカスタムAMIを作成します。

• ウェブサーバーと MySQL を起動します。• データベースを設定します。• アプリケーションを設定します。

チュートリアルを簡単にするため、単一の Amazon EC2 インスタンス上でローカルに稼働するデータベースを作成します。Drupal アプリケーションを設定して、データベースにこの Amazon EC2 インスタンスを使用するようにします。その他すべての Amazon EC2 インスタンスは、このインスタンスに接続してデータベースにアクセスします。

2つ以上のAmazonEC2インスタンスを使用する場合、通常は、アプリケーションを実行しているサーバーとは別のサーバー上にデータベースを設定します。この方法なら情報が1か所に格納され、すべてのインスタンスが同じデータへアクセスできます。同期していない可能性のある稼働中のローカルデータベースにアクセスすることはありません。

別のデータベースの作成については、本書では扱いません。ウェブアプリケーション向けに AmazonRDS をセットアップする方法の詳細については、Getting Started Guide Web Application Hosting forLinux の Step 8: Add Amazon RDS を参照してください。

設定ファイルで権限を設定するには

• Amazon EC2 インスタンスのコマンドプロンプトで、以下のコマンドを使用して権限を設定します。

sudo chmod 666 /var/www/html/sites/default/settings.php

MySQL サーバーをインストールするには

• AmazonEC2インスタンスのコマンドプロンプトで、以下のコマンドを使用してMySQLサーバーをインストールします。

sudo yum install mysql-server

プロンプトが表示されたら、「y」と入力します。

ウェブサーバーと MySQL を起動するには

1. Amazon EC2 インスタンスのコマンドプロンプトで、ウェブサーバーを起動して、再起動後に自動的に起動するように設定します。

sudo chkconfig httpd on

sudo service httpd start

以下のようなレスポンスが表示されます。

Starting httpd [OK]

2. mysql を起動し、再起動後に自動的に起動するように設定します。

22

入門ガイド Linux 用 AWS コンピューティングの基本Amazon EC2 インスタンスを設定する

Page 26: 入門ガイド - Amazon Web Servicesawsdocs.s3.amazonaws.com/gettingstarted/latest/awsgsg...設定済みの新しいAmazonEC2インスタンスを簡単に起動できるよ うにするために、新たなベースライン(たたき台)となるカスタムAMIを作成します。

sudo chkconfig mysqld on

sudo service mysqld start

以下のようなレスポンスが表示されます。

Starting mysqld [OK]

データベースを設定するには

1. Amazon EC2 インスタンスで、「ルート」ユーザーのパスワードを更新します。この例では、パスワード「root」を使用します。

mysqladmin -u root password root

2. データベースを作成します。この例では、データベース名「mydb」を使用します。

mysqladmin -u root -p create mydb

パスワードを求められたら、「root」と入力します。3. サインインして、データベースのアクセス権限を設定します。

mysql -u root -p

パスワードを求められたら、「root」と入力します。4. MySQLプロンプトで、以下のコマンドを使用して権限を設定します。<EC2のパブリックDNSア

ドレス> を、ステップ 4: インスタンスを起動する (p. 10) で記録した Amazon EC2 インスタンスのパブリック DNS アドレスで置き換えます。

GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER, LOCK TABLES, CREATE TEMPORARY TABLES ON mydb.* TO 'awsuser'@'<your public EC2 DNS address>' IDENTIFIED BY 'mypassword';

成功した場合、MySQL は以下のように応答します。

Query OK, 0 rows affected

5. MySQL プロンプトで、以下のコマンドを使用して権限を設定します。

GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER, LOCK TABLES, CREATE TEMPORARY TABLES ON mydb.* TO 'awsuser'@'%' IDENTIFIED BY 'mypassword';

成功した場合、MySQL は以下のように応答します。

Query OK, 0 rows affected

23

入門ガイド Linux 用 AWS コンピューティングの基本Amazon EC2 インスタンスを設定する

Page 27: 入門ガイド - Amazon Web Servicesawsdocs.s3.amazonaws.com/gettingstarted/latest/awsgsg...設定済みの新しいAmazonEC2インスタンスを簡単に起動できるよ うにするために、新たなベースライン(たたき台)となるカスタムAMIを作成します。

6. 新しい権限を有効にするには、以下のコマンドを入力します。

FLUSH PRIVILEGES;

成功した場合、MySQL は以下のように応答します。

Query OK, 0 rows affected

7. 以下を入力して MySQL プロンプトを終了します。

exit

サーバーは以下のように応答します。

Bye

アプリケーションを設定するには

1. ウェブブラウザを開きます。アドレス欄に、ステップ 4: インスタンスを起動する (p. 10) で記録した Amazon EC2 インスタンスのパブリック DNS アドレスを入力します。Drupal のインストールウィザードに、[Choose profile] ページが表示されます。

2. [Choose profile] ページで [Standard] をクリックし、[Save and continue] をクリックします。

3. [Choose language] ページで [English] を選択し、[Save and continue] をクリックします。[Set updatabase] ページが表示されます。

24

入門ガイド Linux 用 AWS コンピューティングの基本Amazon EC2 インスタンスを設定する

Page 28: 入門ガイド - Amazon Web Servicesawsdocs.s3.amazonaws.com/gettingstarted/latest/awsgsg...設定済みの新しいAmazonEC2インスタンスを簡単に起動できるよ うにするために、新たなベースライン(たたき台)となるカスタムAMIを作成します。

4. [Set up database] ページで、以下の情報を入力します。

a. [Database type] で、[MySQL, MariaDB, or equivalent] をクリックします。b. [Database name] ボックスにデータベースの名前を入力します。この例では、mydbを使用し

ます。c. [Database username] ボックスにデータベースのユーザー名を入力します。この例では、

awsuserを使用します。

d. [Database password] ボックスにデータベースのパスワードを入力します。この例では、mypasswordを使用します。

e. [Advanced Options] をクリックします。f. [Database host] ボックスに、ステップ4:インスタンスを起動する (p. 10) で記録したAmazon

EC2 インスタンスのパブリック DNS アドレスを入力します。

25

入門ガイド Linux 用 AWS コンピューティングの基本Amazon EC2 インスタンスを設定する

Page 29: 入門ガイド - Amazon Web Servicesawsdocs.s3.amazonaws.com/gettingstarted/latest/awsgsg...設定済みの新しいAmazonEC2インスタンスを簡単に起動できるよ うにするために、新たなベースライン(たたき台)となるカスタムAMIを作成します。

g. [Save and continue] をクリックします。

5. [Configure site] ページで、以下の情報を入力します。

a. [Site name] ボックスにサイトの名前を入力します。b. [Site e-mail address] ボックスにメールアドレスを入力します。c. [Username] ボックスにユーザー名を入力します。d. [Password] ボックスに、ユーザー名に対応するパスワードを入力します。e. [Confirm password] ボックスにパスワードをもう一度入力します。

26

入門ガイド Linux 用 AWS コンピューティングの基本Amazon EC2 インスタンスを設定する

Page 30: 入門ガイド - Amazon Web Servicesawsdocs.s3.amazonaws.com/gettingstarted/latest/awsgsg...設定済みの新しいAmazonEC2インスタンスを簡単に起動できるよ うにするために、新たなベースライン(たたき台)となるカスタムAMIを作成します。

f. [Save and continue] をクリックします。

これでインストールが完了しました。

6. [Visit your new site] をクリックします。

7. サイトに新しい記事を追加するには、[Add new content] をクリックします。

これで、アマゾンウェブサービスを使用してウェブアプリケーションをデプロイできました。今後、さらにインスタンスを起動する際に、いちいちカスタマイズするのは面倒です。実施した設定変更がすべて組み込まれたカスタム AMI を作成しましょう。

27

入門ガイド Linux 用 AWS コンピューティングの基本Amazon EC2 インスタンスを設定する

Page 31: 入門ガイド - Amazon Web Servicesawsdocs.s3.amazonaws.com/gettingstarted/latest/awsgsg...設定済みの新しいAmazonEC2インスタンスを簡単に起動できるよ うにするために、新たなベースライン(たたき台)となるカスタムAMIを作成します。

手順6:カスタム AMI を作成AmazonEC2インスタンスをカスタマイズしたので、このAmazonMachine Image(AMI)を保存し、保存したこの設定を使用して将来の環境を起動できます。

実行中の Amazon EC2 インスタンスから AMI を作成

1. Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/.2. [Navigation] ペインの[Region] 一覧のにある、[US East (Virginia)] をクリックします。3. [Navigation] ペインの [Instances] をクリックします。4. 「Instances」ページで、実行中のインスタンスを右クリックし、[Create Image (EBS AMI)] を選

択します。5. [Create Image] ダイアログボックスに一意の画像名と、画像の説明(255文字以内、オプション)

を記入してから、[Create This Image] をクリックします。

Amazon EC2 がインスタンスをシャットダウンし、アタッチされていたすべてのボリュームのイメージを記録し、AMI を作成して登録し、インスタンスを再起動します。

6. [Navigation] ペインの [AMIs] をクリックします。7. AMIのステータスが表示されます。新しいAMIが作成される間、そのステータスはpendingです。

AMI ID を記録します。後のタスクで ID が必要になります。

プロセスが終了するには数分かかります。8. AMI のステータスを使用可能に変更したら、[Navigation] ペインの [Snapshots] をクリックして、

「Snapshots 」ページに移動します。AMI について作成した新規スナップショットが表示されます。新規 AMI から起動するインスタンスはルートデバイスボリュームとしてこのスナップショットを使用します。

28

入門ガイド Linux 用 AWS コンピューティングの基本手順6:カスタム AMI を作成

Page 32: 入門ガイド - Amazon Web Servicesawsdocs.s3.amazonaws.com/gettingstarted/latest/awsgsg...設定済みの新しいAmazonEC2インスタンスを簡単に起動できるよ うにするために、新たなベースライン(たたき台)となるカスタムAMIを作成します。

最終的に、複数のアベイラビリティーゾーンで複数の Amazon EC2 インスタンスを実行する際、 1 つのアベイラビリティーゾーンが利用できなくなると、トラフィックは別のアベイラビリティーゾーンに迂回されます。Elastic Load Balancing は、すべてのインスタンスが同じアベイラビリティーゾーンまたは複数のアベイラビリティーゾーンにあるかによらず、アプリケーションの可用性を向上させます。Elastic Load Balancing を作成するには、手順 7:Elastic Load Balancing の作成 (p. 29)に移動します。

手順 7:Elastic Load Balancing の作成Elastic Load Balancing は、実行しているすべてのインスタンスで自動的に着信アプリケーショントラフィックの分散とバランシングを行い、アプリケーションの可用性と拡張性を改善します。このサービスにより、アプリケーションの機能を増やすまたは減らす必要がある場合に、新規インスタンスの追加や、あまり使用されていないインスタンスの削除を簡単に行えます。以下の図には、ロードバランサーの機能が示されています。この図では、ロードバランサーには2つのリスナーが含まれています。最初のリスナーは、HTTPを使用してポート80でトラフィックを受信し、このリクエストを、ポート8080で HTTP を使用して Amazon EC2 インスタンスに転送します。もう一方のリスナーは、HTTPS を使用してポート 433 でトラフィックを受信し、ポート 4443 で HTTPS を使用して Amazon EC2 インスタンスにリクエストを転送します。

クライアントと Amazon EC2 インスタンスの両方について、プロトコルとポートを指定できます。この手順では、HTTPサービスのロードバランサーを作成します。ロードバランサーが、クライアントからの着信トラフィックをポート 80 でリッスンし、ポート 80 でトラフィックをインスタンスに分散するよう指定します。

ロードバランサーが利用可能になると、ロードバランサーの実行時間に応じて1時間ごと、または1時間未満の時間について課金されます。Elastic Load Balancing の価格の詳細については、「Elastic LoadBalancing」の詳細ページを参照してください。

Elastic Load Balancing の詳細については、「Elastic Load Balancing Documentation」を参照してください。

ロードバランサーを作成する

1. ロードバランサーを定義:

a. Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/.b. [Navigation] ペインの [Region] 一覧にある、[US East (Virginia)] をクリックします。c. [Navigation] ペインで、[Load Balancers] をクリックします。d. [Load Balancers] ペインにある [Create a New Load Balancer] ウィザードで、[Create Load

Balancers] をクリックします。e. 「Define Load Balancer」ページで、ロードバランサーの名前を入力します。この例では、

MyLBと入力します。

29

入門ガイド Linux 用 AWS コンピューティングの基本手順 7:Elastic Load Balancing の作成

Page 33: 入門ガイド - Amazon Web Servicesawsdocs.s3.amazonaws.com/gettingstarted/latest/awsgsg...設定済みの新しいAmazonEC2インスタンスを簡単に起動できるよ うにするために、新たなベースライン(たたき台)となるカスタムAMIを作成します。

f. この例では、Listener Configuration の設定はデフォルト値のままにしておきます。「LoadBalancer Port and Protocol」が、クライアントからのトラフィックのリッスンにロードバランサーが使用するポートとプロトコルを指定します。「InstanceProtocol andPort」が、ロードバランサーがインスタンスへのトラフィックのルーティングに使用するポートとプロトコルを指定します。例えば、ロードバランサーでトラフィックを、ポート8080を使用してインスタンスに転送する場合、ここにあるように指定できます。

Note

リスナー情報を設定した後は、変更はできません。この情報を更新する場合、新規のロードバランサーを作成する必要があります。

g. [Continue] をクリックします。

2. ヘルスチェックを設定:

Elastic Load Balancing は定期的に、ロードバランスのあるそれぞれのAmazon EC2 インスタンスの状態をチェックします。問題のあるインスタンスを検出した場合、Elastic Load Balancing はそのインスタンスへのトラフィックの送信を停止し、トラフィックのルートを正常なインスタンスに変更します。

a. [Create a New Load Balancer] ウィザードの「Configure Health Check」ページで、以下を実行します。

30

入門ガイド Linux 用 AWS コンピューティングの基本手順 7:Elastic Load Balancing の作成

Page 34: 入門ガイド - Amazon Web Servicesawsdocs.s3.amazonaws.com/gettingstarted/latest/awsgsg...設定済みの新しいAmazonEC2インスタンスを簡単に起動できるよ うにするために、新たなベースライン(たたき台)となるカスタムAMIを作成します。

Configuration Optionsの下にある「 Configure Health Check」ページで、以下を実行します。

• PingProtocolの設定はデフォルト値HTTPのままにしておきます。将来、ロードバランサーでより安全なプロトコルを使用し、pingリクエストをインスタンスに送信する場合、HTTPSを使用して別のポートを指定できます。 Elastic Load Balancing とともに HTTPS を使用する詳細については、Elastic Load Balancing Developer Guideの「Elastic Load BalancingSecurity Features」を参照してください。

• Ping Port の設定はデフォルト値 80 のままにしておきます。

Elastic Load Balancingは、pingポートを使用して、ヘルスチェッククエリをAmazon EC2インスタンスに送信します。

Note

pingポート値を指定すると、AmazonEC2インスタンスは、指定したポートで着信トラフィックを受信する必要があります。ポートの値を 80 以外に設定し、この値をいつでも変更できます。

• [Ping Path] ボックスのデフォルト値を半角のスラッシュ(「/」)で置き換えます。Elastic Load Balancingは、ヘルスチェッククエリを、指定したpingパスに送信します。この例では、デフォルトページに index.html、default.htmlまたは別の名前が付けられていても、Elastic Load Balancing が HTTP サーバーのデフォルトのホームページにクエリを送信するように半角のスラッシュを使用しています。アプリケーションを配備する際は、ヘルスチェックにのみ対応する特別の小さなファイルを作成するようにしてください。それにより、サイトにヒットしているトラフィックを区別し、ロードバランサーに対応できるようになります。

b. [Advanced Options] の下にある「Configure Health Check」ページで、適切なしきい値を 2に設定します。他のオプションでは、デフォルト値をそのまま使用します。

31

入門ガイド Linux 用 AWS コンピューティングの基本手順 7:Elastic Load Balancing の作成

Page 35: 入門ガイド - Amazon Web Servicesawsdocs.s3.amazonaws.com/gettingstarted/latest/awsgsg...設定済みの新しいAmazonEC2インスタンスを簡単に起動できるよ うにするために、新たなベースライン(たたき台)となるカスタムAMIを作成します。

通常、デフォルト値 10は、しきい値として適切です。このチュートリアルでは 2を指定しているので、適切なインスタンスが表示されるのを待つ必要はありません。

c. [Continue] をクリックします。

3. Amazon EC2 インスタンスの追加:

a. 「Add EC2 Instances」ページで、[Continue] をクリックします。

b. 設定を確認します。設定を変更するには、プロセスの特定の手順で[Edit]をクリックします。

32

入門ガイド Linux 用 AWS コンピューティングの基本手順 7:Elastic Load Balancing の作成

Page 36: 入門ガイド - Amazon Web Servicesawsdocs.s3.amazonaws.com/gettingstarted/latest/awsgsg...設定済みの新しいAmazonEC2インスタンスを簡単に起動できるよ うにするために、新たなベースライン(たたき台)となるカスタムAMIを作成します。

Important

ロードバランサーを作成した後、ロードバランサーの名前とポート設定以外の設定を変更できます。ロードバランサーの名前を変更、またはポート設定を変更するには、代わりのロードバランサーを作成します。

c. [Create] をクリックします。d. 「Confirmation」ページで、[Close] をクリックします。

33

入門ガイド Linux 用 AWS コンピューティングの基本手順 7:Elastic Load Balancing の作成

Page 37: 入門ガイド - Amazon Web Servicesawsdocs.s3.amazonaws.com/gettingstarted/latest/awsgsg...設定済みの新しいAmazonEC2インスタンスを簡単に起動できるよ うにするために、新たなベースライン(たたき台)となるカスタムAMIを作成します。

確認ウィンドウを閉じると、「LoadBalancers」ページに戻ります。新しいロードバランサーが一覧に表示されます。

ベストプラクティスは、いずれかのアベイラビリティーゾーンが利用できなくなっても停止しないように、複数のアベイラビリティーゾーンに十分な数のインスタンスを用意することです。よって、次の手順では、ロードバランサーを、複数のアベイラビリティーゾーンに配置します。

4. パブリック DNS アドレスを記録:

a. [Load Balancers] ペインで、[MyLB] をクリックします。b. [Description] タブをクリックします。

c. パブリック DNS アドレスをメモします。このチュートリアルで後ほど、このアドレスが必要になります。

5. アベイラビリティーゾーンを追加します。

34

入門ガイド Linux 用 AWS コンピューティングの基本手順 7:Elastic Load Balancing の作成

Page 38: 入門ガイド - Amazon Web Servicesawsdocs.s3.amazonaws.com/gettingstarted/latest/awsgsg...設定済みの新しいAmazonEC2インスタンスを簡単に起動できるよ うにするために、新たなベースライン(たたき台)となるカスタムAMIを作成します。

a. [Load Balancers] ペインで、[MyLB] をクリックします。b. Instances タブをクリックします。c. + アイコンをクリックします。

d. [Add and Remove Availability Zones] ダイアログボックスで、次の項目を実行します。

• [us-east-1b: 0 instances] をクリックします。• [us-east-1c: 0 instances] をクリックします。• [Save] をクリックします。

後のタスクで、Auto Scalingを使用して、この2つのアベイラビリティーゾーンでインスタンスを起動します。ロードバランサーの [Availability Zones] 列が、両方のアベイラビリティーゾーンについて更新されて表示されます。

現在扱っている内容現在、アーキテクチャの構築を行っています。

ステップ 4: インスタンスを起動する (p. 10)で、ポート 80(HTTP)を介しすべてのトラフィックがAmazon EC2 インスタンスに接続することを許可するよう設定しました。Elastic Load Balancing を作成したので、セキュリティグループを更新し、Elastic Load Balancing から着信 HTTP トラフィックの

35

入門ガイド Linux 用 AWS コンピューティングの基本現在扱っている内容

Page 39: 入門ガイド - Amazon Web Servicesawsdocs.s3.amazonaws.com/gettingstarted/latest/awsgsg...設定済みの新しいAmazonEC2インスタンスを簡単に起動できるよ うにするために、新たなベースライン(たたき台)となるカスタムAMIを作成します。

みを許可するようにできます。ステップ8: Amazon EC2セキュリティグループを更新する (p. 36)に移動します。

ステップ8: Amazon EC2セキュリティグループを更新する

ステップ 4: インスタンスを起動する (p. 10) では、ポート 80 経由の HTTP を有効にするセキュリティグループを作成しました。このセキュリティグループでは、すべてのトラフィックが HTTP/80 を経由して Amazon EC2 インスタンスに直接アクセスできます。Elastic Load Balancer を作成したので、さらに安全な方法はロードバランサーのみが Amazon EC2 インスタンスにアクセスできるようにすることです。さらに、Auto Scalingグループで2つの新しいインスタンスを起動したので、すべてのインスタンスが1つのデータベースの情報にアクセスするようにして、ユーザーに提示される情報の同期を維持する必要があります。そのためには、新しいルールをセットアップして、新しいインスタンスがMySQL を使って元のインスタンス上のデータベースをクエリできるようにする必要があります。このタスクでは、セキュリティグループを更新し、ロードバランサーのみが HTTP/80 経由でお使いのAmazon EC2 インスタンスにアクセスできるようにし、webappsecuritygroup 内のインスタンスのみが、3306/MySQL 経由でインバウンドトラフィックを受け付けることができるようにします。データベースをセットアップする方法には、専用のデータベースサーバーをセットアップする方法やAmazonRDS を使用する方法などいくつかあります。データベースのセットアップについては、本書では扱いません。ウェブアプリケーション向けに Amazon RDS をセットアップする方法の詳細については、Getting Started Guide Web Application Hosting for Linux の Step 8: Add Amazon RDS を参照してください。

セキュリティグループを設定するには

1. Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/.2. [Navigation] ペインの [Region] リストで、[US East (Virginia)] をクリックします。3. [Navigation] ペインで、[Security Groups] をクリックします。4. [Security Groups] ページで、前の手順で作成したセキュリティグループ webappsecuritygroup

をクリックします。5. [Security Group] で、[Inbound] タブをクリックします。6. ポート 80(HTTP)が表示されている行で、[Delete] をクリックします。7. [Create a new rule] リストで、[HTTP] をクリックします。8. [Source]ボックスに amazon-elb/amazon-elb-sgと入力します。これは、AWSによってElastic

Load Balancer に割り当てられるセキュリティグループ名です。[Add Rule] をクリックします。9. [Create a new rule] ドロップダウンボックスで、[MYSQL] をクリックします。10. [Source] ボックスに webappsecuritygroupと入力します。webappsecuritygroup が表示された

ら、webappsecuritygroup のセキュリティグループ ID を入力します。11. [Add Rule] をクリックします。12. [Apply Rule Changes] をクリックします。

36

入門ガイド Linux 用 AWS コンピューティングの基本ステップ 8: Amazon EC2 セキュリティグループを更新す

Page 40: 入門ガイド - Amazon Web Servicesawsdocs.s3.amazonaws.com/gettingstarted/latest/awsgsg...設定済みの新しいAmazonEC2インスタンスを簡単に起動できるよ うにするために、新たなベースライン(たたき台)となるカスタムAMIを作成します。

Note

このセキュリティグループのルールは、これらのルールを使用するインスタンスが起動されたときに適用されます。

AmazonEC2セキュリティグループを設定したので、ステップ9: Auto Scalingを使用してAmazonEC2インスタンスを起動する (p. 37) に進みます。Auto Scaling は、トラフィックレベルの変化に応じて実行されるインスタンス数を調整できます。

ステップ 9: Auto Scaling を使用して Amazon EC2インスタンスを起動する

AutoScalingは、ユーザー定義のポリシー、スケジュール、アラームに従って、AmazonEC2インスタンスを自動的に起動および終了します。AutoScalingを使用すると、提示されるあらゆる負荷に合わせて調整できる Amazon EC2 インスタンス群を維持できます。Auto Scaling を使用して、グループ内の複数のインスタンスを一度に起動することもできます。

AutoScalingはその名のとおり、変化する状況に自動的に対応します。必要なのは、そうした変化にどのように対応するかを指定することだけです。例えば、Auto Scaling に対して、1つ以上の既存インスタンスの CPU 利用率が 60% を超えた場合に追加のインスタンスを起動するように指示できます。あるいは、トラフィックの減少が予想される週末にウェブサイトのインスタンスの半分を終了するように指定することも可能です。

AutoScalingによって、アプリケーションが効率的に実行され続けるように、インスタンス群を最適なパフォーマンスで稼働させることができます。さらに、Auto Scaling グループは複数のアベイラビリティゾーンにわたって機能することができます。このため、1つのアベイラビリティゾーンが利用できなくなると、異なるアベイラビリティゾーンのアプリケーションへトラフィックを自動的に再分散させます。Auto Scalingを使用することで、正常なインスタンスが常に1つ以上稼働している状態を確保できます。詳細については、Auto Scaling を参照してください。

37

入門ガイド Linux 用 AWS コンピューティングの基本ステップ 9: Auto Scaling を使用して Amazon EC2 インス

タンスを起動する

Page 41: 入門ガイド - Amazon Web Servicesawsdocs.s3.amazonaws.com/gettingstarted/latest/awsgsg...設定済みの新しいAmazonEC2インスタンスを簡単に起動できるよ うにするために、新たなベースライン(たたき台)となるカスタムAMIを作成します。

この例では、多くのアプリケーションで Auto Scaling を使用するために配置する必要がある基本インフラストラクチャをセットアップします。以下を実行します。

• 起動設定を作成します。• Auto Scaling グループを作成します。• Auto Scaling グループにポリシーを作成します。

このチュートリアルの目的上、Amazon EC2 上で稼働するアプリケーションの負荷分散と自動スケーリングを行うインスタンス数を、最小 2 個、最大 2 個に設定します。最小値と最大値を同じ値に設定することで、1つのインスタンスに障害が発生した場合にも、常に希望するインスタンス数を確保できます。実際のウェブサイトを作成する場合は、ベストプラクティスとして、いずれか1つのアベイラビリティーゾーンの喪失に耐えるように、複数のアベイラビリティーゾーン間に十分な数のインスタンスを起動することをお勧めします。さらに、AutoScalingの機能を活用するためには、インスタンスの最大数を最小数より大きくなるように増やす必要があります。

インスタンスの最大数を指定すると、インスタンス群がどのくらい大きくなるかを制御できます。この例では、Auto Scalingは負荷が増加した場合にインスタンスを1つ追加するように設定されています。このトピックではポリシーを定義します。次のセクションでは Cloud Watch アラームを設定し、平均NetworkOut が 6,000,000 バイトのしきい値を 5 分間超過し続けた場合に、ポリシーに応じてアクションを実行するようにします。Auto Scaling と Amazon CloudWatch は連携して、作成されたポリシーに従って、インスタンスを起動または終了します。時間を節約するため、ここではポリシーを1つしか作成しませんが、負荷が減少したときにインスタンスを終了するポリシーなど、他のポリシーも作成できます。

AutoScalingコマンドラインツールをまだインストールしていなければ、ここでインストールする必要があります。詳細については、Auto Scaling DeveloperGuide の Using the Command Line Tools を参照してください。コマンドラインツールを使用して Auto Scaling を設定します。

自動スケーリングと負荷分散が施されたアプリケーションがAmazonEC2で実行されるように設定するには

1. コマンドプロンプトウィンドウを開きます。ローカルのWindows コンピュータで、[スタート] をクリックします。検索ボックスに cmdと入力し、Enter キーを押します。

2. 起動設定は、AutoScalingグループ内で起動するインスタンスのテンプレートです。この例で起動設定を定義するためには、as-create-launch-configコマンドを使用します。以下のパラメータで起動設定を定義します。

• image-id は AMI ID です。手順6:カスタム AMI を作成 (p. 28) で作成したカスタム AMI ID を使用します。

• instance-type には、オペレーティングシステム、メモリ、ローカルストレージなど、起動するインスタンスに関する基本的な情報が格納されます。この例では、最初にインスタンスを起動したときに使用したのと同じインスタンスタイプを使用します。

• keyはインスタンスへの接続に使用したキーペアです。最初にインスタンスを起動したときに作成したのと同じキーペアを使用します。

• groupは、インスタンスのアクセスルールを定義したセキュリティグループです。最初にインスタンスを起動したときに作成したのと同じセキュリティグループを使用します。

• monitoring-disabledでは、詳細モニタリングの代わりに基本モニタリングを使用することを指定します。デフォルトでは、詳細モニタリングが有効です。基本モニタリングと詳細モニタリングの詳細については、Amazon CloudWatch を参照してください。

リージョンは指定しません。デフォルトリージョンの米国東部(バージニア)を使用します。コマンドプロンプトで以下を入力して Enter キーを押します。

38

入門ガイド Linux 用 AWS コンピューティングの基本ステップ 9: Auto Scaling を使用して Amazon EC2 インス

タンスを起動する

Page 42: 入門ガイド - Amazon Web Servicesawsdocs.s3.amazonaws.com/gettingstarted/latest/awsgsg...設定済みの新しいAmazonEC2インスタンスを簡単に起動できるよ うにするために、新たなベースライン(たたき台)となるカスタムAMIを作成します。

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

Auto Scaling は以下のような出力を返します。

OK-Created launch config

Note

このドキュメントからコマンドをコピーして、コマンドプロンプトウィンドウに貼り付けることができます。コマンドラインウィンドウに内容を貼り付けるには、コマンドプロンプトウィンドウで右クリックして [貼り付け]をクリックします。コマンドの動作に問題がある場合は、コマンドを正しく入力したことを確認します。

これで起動設定が作成されました。

3. 複数の Amazon EC2 インスタンスを起動可能な Auto Scaling グループを作成するには、as-create-auto-scaling-groupコマンドを使用します。以下のパラメータを使用して AutoScaling グループを定義します。

• launch-configuration は前のステップで作成した起動設定の名前です。• availability-zones には、Auto Scaling グループの Amazon EC2 インスタンスを起動するアベイラビリティーゾーンを指定します。この例では、2 つのアベイラビリティーゾーンを指定します。複数のアベイラビリティーゾーンを指定することは、耐障害性の高い(フォルトトレラントな)アプリケーションを作成するためのベストプラクティスです。一方のアベイラビリティーゾーンが停止すると、トラフィックがもう一方のアベイラビリティーゾーンにルーティングされます。AutoScalingグループで起動されるインスタンス数は、複数のアベイラビリティーゾーンに均等に分散されます。

• min-size およびmax-size には、Auto Scaling グループ内のAmazon EC2 インスタンス数の最小値と最大値を設定します。最小値と最大値を同じ値に設定すると、グループ内のインスタンス数を一定にできます。この例では、最小値と最大値の両方を 2 に設定します。

• load-balancerは、AutoScalingグループにトラフィックをルーティングするために使用するロードバランサーの名前です。

コマンドプロンプトで以下を入力し、Enter キーを押します。

PROMPT>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

Auto Scaling は以下を返します。

OK-Created AutoScalingGroup

39

入門ガイド Linux 用 AWS コンピューティングの基本ステップ 9: Auto Scaling を使用して Amazon EC2 インス

タンスを起動する

Page 43: 入門ガイド - Amazon Web Servicesawsdocs.s3.amazonaws.com/gettingstarted/latest/awsgsg...設定済みの新しいAmazonEC2インスタンスを簡単に起動できるよ うにするために、新たなベースライン(たたき台)となるカスタムAMIを作成します。

4. インスタンス群を大きくするポリシーを作成する場合は、AutoScalingのas-put-scaling-policyコマンドを使用します。このポリシーは、前のステップで作成した Auto Scaling グループに適用されます。Auto Scaling ポリシーを定義する際には、以下のパラメータを使用します。

• auto-scaling-group は、ポリシーの適用先となる Auto Scaling グループの名前です。前のステップで作成した Auto Scaling グループ名を使用します。

• adjustment は、インスタンスの増減数です。この例では 1 を使用します。• type は作成するポリシーのタイプです。この例では、ChangeInCapacity を使用してインスタンス群のサイズを変更します。

• cooldown は、あるアクションが完了してから Auto Scaling が条件を再び評価するまでの秒単位の時間です。

コマンドプロンプトで以下を入力して Enter キーを押します。

PROMPT>as-put-scaling-policy MyScaleUpPolicy --auto-scaling-group MyAutoScal ingGroup --adjustment=1 --type ChangeInCapacity --cooldown 300

Auto Scaling は以下のような出力を返します。

POLICY-ARN arn:aws:autoscaling:us-east-1:012345678901:scalingPolicy:cbe7da4e-5d00-4882-900a-2f8113431e30:autoScalingGroupName/MyAutoScalingGroup:policy Name/MyScaleUpPolicy

Note

時間を節約するため、今回はインスタンスを追加するポリシーのみを作成しました。ほとんどの場合、トラフィックが減少したときに1つ以上のインスタンスを終了するポリシーも作成します。Auto Scaling によって、アプリケーションがリソースを必要としないときにインスタンス数を減らすことができるため、コストを削減できます。インスタンスを終了するポリシーを作成するには、今作成したポリシーから始め、ポリシー名を変更して、調整値を1から -1に変更します。Windowsマシンでは "--adjustment=-1"を使用します。コマンドプロンプトで以下を入力し、Enter キーを押します。

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

5. 対象の Auto Scaling グループが存在することを確認するため、as-describe-auto-scaling-groupsコマンドを使用します。コマンドプロンプトで以下を入力し、Enter キーを押します。

PROMPT>as-describe-auto-scaling-groups MyAutoScalingGroup --headers

Auto Scaling は以下を返します。

AUTO-SCALING-GROUP GROUP-NAME LAUNCH-CONFIG AVAILABILITY-ZONES MIN-SIZE MAX-SIZE DESIRED-CAPACITYAUTO-SCALING-GROUP MyAutoScalingGroup MyLC us-east-1b,us-east-

40

入門ガイド Linux 用 AWS コンピューティングの基本ステップ 9: Auto Scaling を使用して Amazon EC2 インス

タンスを起動する

Page 44: 入門ガイド - Amazon Web Servicesawsdocs.s3.amazonaws.com/gettingstarted/latest/awsgsg...設定済みの新しいAmazonEC2インスタンスを簡単に起動できるよ うにするために、新たなベースライン(たたき台)となるカスタムAMIを作成します。

1c 2 2 2INSTANCE INSTANCE-ID AVAILABILITY-ZONE STATE STATUS LAUNCH-CONFIGINSTANCE i-xxxxxxxx us-east-1c InService Healthy MyLCINSTANCE i-xxxxxxxx us-east-1b InService Healthy MyLC

Amazon EC2 アプリケーションが、自動スケーリングと負荷分散を施されたアプリケーションとして起動しました。

Auto Scaling の詳細については、Auto Scaling のドキュメントを参照してください。

Caution

AmazonEC2インスタンスが稼働している限り、料金がかかります。任意のタイミングでこれらのインスタンスを終了したい場合は、Terminate Your Amazon EC2 Instances in Your AutoScaling Group (p. 51) を参照してください。

現在扱っている内容現在、アーキテクチャの構築を行っています。

AutoScalingグループを作成し、AmazonEC2インスタンスを実行しているので、インスタンスの状態を監視します。次の手順では、Amazon CloudWatch アラームを作成し、先ほど作成した Auto Scalingポリシーを追跡します。

41

入門ガイド Linux 用 AWS コンピューティングの基本現在扱っている内容

Page 45: 入門ガイド - Amazon Web Servicesawsdocs.s3.amazonaws.com/gettingstarted/latest/awsgsg...設定済みの新しいAmazonEC2インスタンスを簡単に起動できるよ うにするために、新たなベースライン(たたき台)となるカスタムAMIを作成します。

ステップ 10: CloudWatch アラームを作成するAmazon CloudWatch は、さまざまなメトリックスをモニタリング、管理、発行して、それらのメトリックスに基づいてアラームアクションを設定できるウェブサービスです。

Amazon CloudWatch を使用すると、システムとアプリケーションのメトリックスを収集、分析、確認できるため、運用上やビジネス上の判断をすばやく、確信を持って下すことが可能になります。AmazonCloudWatch は、Amazon EC2 インスタンスのパフォーマンスなど、AWS リソースに関するメトリックスを自動的に収集します。独自のメトリックスをAmazonCloudWatchに対して直接発行できます。

Amazon CloudWatch を使用して問題発生前と発生後のシステムパフォーマンスを確認することで、問題を診断できます。Amazon CloudWatch はパフォーマンスをリアルタイムで追跡できるため、原因の特定と修正の検証に役立ちます。例えば、アプリケーションの速度が低下した場合にただちに E メールを送信するように Amazon CloudWatch をセットアップできます。そうすることで、例えば特定のデータベースが過負荷になっていたというような問題をさかのぼって発見できます。問題を修正したら、Amazon CloudWatch を使用して、レスポンス時間が正常に戻っていることを観察できます。CloudWatch アラーム作成の詳細については、Amazon CloudWatch Developer Guide の CreatingCloudWatch Alarms を参照してください。

Amazon CloudWatch の一般的な使い方は、アプリケーションとサービスが正常かつ効率的に実行されるよう維持することです。例えば、Amazon CloudWatch を使用すると、Amazon EC2インスタンスへのネットワークトラフィックがあるしきい値以下の場合に、ウェブサイトが最適に稼働することを発見できます。この場合、存在するトラフィック量に見合うだけの適切なインスタンス数を常に確保するための Auto Scaling ポリシーを作成できます。

前述のタスクでは、実行中のインスタンス数を増やす Auto Scaling ポリシーを作成しました。このタスクでは、このポリシーにアラームアクションを関連付けます。アラームがトリガーされると、AutoScaling は通知を受け取り、リソースに適切な変更を加えます。

以下の特性を備えたアラームを作成します。

以下の図は、Amazon CloudWatch と Auto Scaling がどのように連携するかを示しています。AmazonEC2インスタンスは、自身のNetworkOut メトリックスをAmazon CloudWatchに報告します。指定したしきい値を上回るとAmazon CloudWatchはアラームを生成し、このことをAuto Scalingグループに報告します。次に Auto Scaling グループが、設定されているポリシーに基づいてアクションを実行します。

42

入門ガイド Linux 用 AWS コンピューティングの基本ステップ 10: CloudWatch アラームを作成する

Page 46: 入門ガイド - Amazon Web Servicesawsdocs.s3.amazonaws.com/gettingstarted/latest/awsgsg...設定済みの新しいAmazonEC2インスタンスを簡単に起動できるよ うにするために、新たなベースライン(たたき台)となるカスタムAMIを作成します。

このトピックでは、CloudWatchアラームを作成して、しきい値を超えたときにアプリケーションにアラートを送信する方法について順を追って説明します。時間を節約するため、ここではアラームを1つだけ作成しますが、同じ手順を適用することで他のアラームも作成できます。例えば、AutoScalingにインスタンスを終了する必要があることを通知する別のアラームを作成できます。AmazonCloudWatchの詳細については、Amazon CloudWatch の詳細ページを参照してください。

Amazon CloudWatch を作成

1. アラームの基準を選択するには:

a. Open the Amazon CloudWatch console at https://console.aws.amazon.com/cloudwatch/.b. [Navigation]ペインの [Region]一覧にある、[USEast(Virginia)]をクリックします。[Alarms]

をクリックします。c. 詳細ペインで、[Create Alarm] をクリックします。d. 表示一覧の「基準を選択」ページにある [Create Alarm Wizard ] で、[EC2: Aggregated by

Auto Scaling Group] を選択します。

43

入門ガイド Linux 用 AWS コンピューティングの基本ステップ 10: CloudWatch アラームを作成する

Page 47: 入門ガイド - Amazon Web Servicesawsdocs.s3.amazonaws.com/gettingstarted/latest/awsgsg...設定済みの新しいAmazonEC2インスタンスを簡単に起動できるよ うにするために、新たなベースライン(たたき台)となるカスタムAMIを作成します。

e. [MyAutoScalingGroup/NetworkOut] 行をクリックしてから、[Continue] をクリックします。

Note

Auto Scaling グループを一覧に表示するには、最大で 15 分かかる場合があります。Auto Scaling グループが表示されない場合、最大で 15 分待ってからもう一度行います。

2. アラームの定義:

[Create Alarm] ウィザードの「Define Alarm」ページで、以下の作業を行ってから、[Continue] をクリックします。

• [Name] ボックスに、「MyNetworkOutAlarm」と入力します。• [Description] ボックスに、説明を入力します。• [Define Alarm Threshold] セクションで、[>=] をクリックし、最初のボックスに 6000000、分のボックスに5と入力します。自分のアプリケーションで、負荷テストを行い、どの値が最適化を確かめることができます。

44

入門ガイド Linux 用 AWS コンピューティングの基本ステップ 10: CloudWatch アラームを作成する

Page 48: 入門ガイド - Amazon Web Servicesawsdocs.s3.amazonaws.com/gettingstarted/latest/awsgsg...設定済みの新しいAmazonEC2インスタンスを簡単に起動できるよ うにするために、新たなベースライン(たたき台)となるカスタムAMIを作成します。

3. アクションを定義:

a. [Create Alarm]ウィザードの「Configure Actions」ページで、以下の作業を行ってから、[AddAction] をクリックします。

• [When Alarm state is] の下で、[ALARM] をクリックします。• 「アクションを起こす」一覧の下で、[Auto Scaling Policy] をクリックします。• 「Auto Scaling グループ」一覧で、[MyAutoScalingGroup] をクリックします。• 「ポリシー」一覧で、[MyScaleUpPolicy (Add 1 instance)] をクリックします。

b. 以下の作業を行ってから、[Continue] をクリックします。

• 作成した新たな行で、「When Alarm state is」の下で、[ALARM] をクリックします。• 「アクションを起こす」一覧で、[Send Notification] をクリックします。• [Topic] ボックスに、トピック名を入力します。• [Email(s)] ボックスに、通知の送信先の電子メールアドレスを入力します。

45

入門ガイド Linux 用 AWS コンピューティングの基本ステップ 10: CloudWatch アラームを作成する

Page 49: 入門ガイド - Amazon Web Servicesawsdocs.s3.amazonaws.com/gettingstarted/latest/awsgsg...設定済みの新しいAmazonEC2インスタンスを簡単に起動できるよ うにするために、新たなベースライン(たたき台)となるカスタムAMIを作成します。

4. 「Review」ページで、設定を見直します。すべてが正常の場合、[Create Alarm] をクリックします。

5. 確認ページで、[Close] をクリックします。

46

入門ガイド Linux 用 AWS コンピューティングの基本ステップ 10: CloudWatch アラームを作成する

Page 50: 入門ガイド - Amazon Web Servicesawsdocs.s3.amazonaws.com/gettingstarted/latest/awsgsg...設定済みの新しいAmazonEC2インスタンスを簡単に起動できるよ うにするために、新たなベースライン(たたき台)となるカスタムAMIを作成します。

これで、AmazonCloudWatchコンソールの「ダッシュボード」ページに、新規のアラームが一覧に表示されるようになりました。

MyScaleDownPolicy を作成すると、同じ手順を使用して別のアラームを作成できます。

設定内容を確認するアーキテクチャーの構築が完了しました。

47

入門ガイド Linux 用 AWS コンピューティングの基本設定内容を確認する

Page 51: 入門ガイド - Amazon Web Servicesawsdocs.s3.amazonaws.com/gettingstarted/latest/awsgsg...設定済みの新しいAmazonEC2インスタンスを簡単に起動できるよ うにするために、新たなベースライン(たたき台)となるカスタムAMIを作成します。

これで、AWSの重要な構成要素をいくつか使って、ウェブアプリケーションをEC2に正しくデプロイできました。すべてが想定通りに動作していることを確認するために、以下の手順を実行します。

1. ブラウザを更新します。ウェブサイトにアクセスできなくなっているはずです。これは、セキュリティグループを更新して、Elastic LoadBalancerからのアクセスのみを許可するように設定したためです。

2. 手順 7:Elastic Load Balancingの作成 (p. 29) に記録した、Elastic Load Balancer のパブリックDNSアドレスを入力して、アプリケーションが表示されるかどうか確認します。

48

入門ガイド Linux 用 AWS コンピューティングの基本設定内容を確認する

Page 52: 入門ガイド - Amazon Web Servicesawsdocs.s3.amazonaws.com/gettingstarted/latest/awsgsg...設定済みの新しいAmazonEC2インスタンスを簡単に起動できるよ うにするために、新たなベースライン(たたき台)となるカスタムAMIを作成します。

このチュートリアルでは、以下のAWS製品を使ってウェブアプリケーションをデプロイする方法について学習しました。

• Amazon EC2。アプリケーションを実行するために使用します。• Elastic Load Balancing。実行中のインスタンス間でトラフィックの負荷を分散するために使用します。

• Auto Scaling。設定したポリシーに従って自動的にインスタンスを追加したり終了したりするために使用します。

• Amazon CloudWatch。インスタンスをモニタリングし、指定したしきい値を超過した場合に通知するために使用します。

AWS サービスとその利用法についての理解が深まったら、より簡単な方法でアプリケーションをデプロイできます。AWS CloudFormation を使用すると、各種AWSサービスをプロビジョニングする順番や、依存関係を機能させるための細かい作業を意識することなく、AWS でリソースをデプロイできます。このチュートリアルで使ったサービスを使ってサンプルテンプレートを構築する方法を学習するには、AWS CloudFormation User Guide の Auto Scaling Group with LoadBalancer, Auto Scaling Policies,and CloudWatch Alarms を参照してください。

使い終わったら、それ以上課金されないように、AWS リソースを終了します。手順 11: クリーンアップ (p. 50) に進みます。

49

入門ガイド Linux 用 AWS コンピューティングの基本設定内容を確認する

Page 53: 入門ガイド - Amazon Web Servicesawsdocs.s3.amazonaws.com/gettingstarted/latest/awsgsg...設定済みの新しいAmazonEC2インスタンスを簡単に起動できるよ うにするために、新たなベースライン(たたき台)となるカスタムAMIを作成します。

手順 11: クリーンアップTopics• Delete Your CloudWatch Alarm (p. 50)• Delete Your Elastic Load Balancer (p. 51)• Terminate Your Amazon EC2 Instances in Your Auto Scaling Group (p. 51)• インスタンスの終了 (p. 53)• キーペアの削除 (p. 53)• Delete an Amazon EC2 Security Group (p. 53)

おめでとうございます。ウェブアプリケーションのデプロイを行いました。以後費用が発生しないようにするには、環境を終了してリソースのクリーンアップを行います。

Delete Your CloudWatch AlarmAfter you've decided that you no longer need the alarm, you can delete it.

To delete your alarm

1. Open the Amazon CloudWatch console at https://console.aws.amazon.com/cloudwatch/.

2. In the Navigation pane, under Regions, click US East (Virginia).3. Select the check box next to the alarm that you want to delete, and then click Delete.4. When a confirmation message appears, click Yes, Delete.

50

入門ガイド Linux 用 AWS コンピューティングの基本手順 11: クリーンアップ

Page 54: 入門ガイド - Amazon Web Servicesawsdocs.s3.amazonaws.com/gettingstarted/latest/awsgsg...設定済みの新しいAmazonEC2インスタンスを簡単に起動できるよ うにするために、新たなベースライン(たたき台)となるカスタムAMIを作成します。

Delete Your Elastic Load BalancerAs soon as your load balancer becomes available, AWS bills you for each hour or partial hour that youkeep the load balancer running. After you've decided that you no longer need the load balancer, you candelete it.

To delete your load balancer

1. Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/.

2. In the Navigation pane, under Regions, click US East (Virginia).3. Under Load Balancers, select the check box next to the load balancer you want to delete, and then

click Delete.4. When a confirmation message appears, click Yes, Delete.

Elastic Load Balancing deletes the load balancer. As soon as the load balancer is deleted, you stopincurring charges for that load balancer.

Caution

Even after you delete a load balancer, the Amazon EC2 instances associated with the loadbalancer continue to run. You will continue to incur charges on the Amazon EC2 instanceswhile they are running.

Terminate Your Amazon EC2 Instances in Your AutoScaling GroupIn this section you will first remove the Amazon EC2 instance, then delete the Auto Scaling group, andfinally delete the launch configuration.

You must terminate all Amazon EC2 instances in an Auto Scaling group before you can delete the group.A simple way to terminate all instances in a group is to update the group so that both the minimum sizeand maximum size are set to zero.

To remove the Amazon EC2 instance from the Auto Scaling group

1. Open a command prompt window: From a Windows computer, click Start. In the Search box, typecmd, and then press Enter.

2. You'll use the as-update-auto-scaling-group command to update the Auto Scaling group thatwe created earlier. At the command prompt, type the following, and then press Enter:

51

入門ガイド Linux 用 AWS コンピューティングの基本Delete Your Elastic Load Balancer

Page 55: 入門ガイド - Amazon Web Servicesawsdocs.s3.amazonaws.com/gettingstarted/latest/awsgsg...設定済みの新しいAmazonEC2インスタンスを簡単に起動できるよ うにするために、新たなベースライン(たたき台)となるカスタムAMIを作成します。

PROMPT>as-update-auto-scaling-group MyAutoScalingGroup --min-size 0 --max-size 0

Auto Scaling returns the following:

OK-Updated AutoScalingGroup

3. Now you'll use the as-describe-auto-scaling-groups command to verify that Auto Scalinghas removed the instance from MyAutoScalingGroup.

It can take a few minutes for the instance to terminate, so you might have to check the status morethan once. At the command prompt, type the following, and then press Enter:

PROMPT>as-describe-auto-scaling-groups MyAutoScalingGroup --headers

If the instance termination is still in progress, Auto Scaling returns information similar to the following.(Your value for INSTANCE-ID will differ):

AUTO-SCALING-GROUP GROUP-NAME LAUNCH-CONFIG AVAILABILITY-ZONES LOAD-BALANCERS MIN-SIZE MAX-SIZE DESIRED-CAPACITYAUTO-SCALING-GROUP MyAutoScalingGroup MyLC us-east-1b,us-east-1c MyLB 0 0 0INSTANCE INSTANCE-ID AVAILABILITY-ZONE STATE STATUS LAUNCH-CONFIGINSTANCE i-xxxxxxxx us-east-1c InService Healthy MyLC

Note

You can also click Instances in the Amazon EC2 console to view the status of your instances.

When no instances exist in MyAutoScalingGroup, you can delete the group.

To delete the Auto Scaling group

• At the command prompt, type the following, and then press Enter:

PROMPT>as-delete-auto-scaling-group MyAutoScalingGroup

To confirm the deletion, type Y, and then press Enter.

Are you sure you want to delete this MyAutoScalingGroup? [Ny]

Auto Scaling returns the following:

OK-Deleted MyAutoScalingGroup

All that remains now is to delete the launch configuration you created for this Auto Scaling group.

52

入門ガイド Linux 用 AWS コンピューティングの基本Terminate Your Amazon EC2 Instances in Your Auto Scaling

Group

Page 56: 入門ガイド - Amazon Web Servicesawsdocs.s3.amazonaws.com/gettingstarted/latest/awsgsg...設定済みの新しいAmazonEC2インスタンスを簡単に起動できるよ うにするために、新たなベースライン(たたき台)となるカスタムAMIを作成します。

To delete the launch configuration

• At the command prompt,type the following, and then press Enter:

PROMPT>as-delete-launch-config MyLC

To confirm the deletion, type Y and then press Enter.

Are you sure you want to delete this launch configuration? [Ny]

Auto Scaling returns the following:

OK-Deleted launch configuration

インスタンスの終了インスタンスが起動するとすぐに、実行中のインスタンス 1 時間ごと、または 1 時間未満で、請求が発生します(インスタンスがアイドル状態の場合でも)。インスタンスを終了すると、料金は以後発生しません。このインスタンスは Auto Scaling グループの一員ではないため、手作業で終了する必要があります。

インスタンスを終了する

1. Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/.2. インスタンスを右クリックしてから、[Terminate] をクリックします。3. 確認を求めるメッセージが表示されたら、[Yes, Terminate] をクリックします。インスタンスのス

テータスが [shutting down] または [terminated] に変わったら、インスタンスの料金請求が停止します。

キーペアの削除この手順はオプションです。キーペアを保持しても費用はかかりません。後でこのキーペアを再び使用することもできます。

To delete a key pair

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, under Region, click Key Pairs.4. Select the check box beside the key pair you want to delete, and then click Delete.5. When a confirmation message appears, click Yes, Delete.

Delete an Amazon EC2 Security GroupTo delete a security group

1. Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/.2. In the Navigation pane, under Region, click US East (Virginia).

53

入門ガイド Linux 用 AWS コンピューティングの基本インスタンスの終了

Page 57: 入門ガイド - Amazon Web Servicesawsdocs.s3.amazonaws.com/gettingstarted/latest/awsgsg...設定済みの新しいAmazonEC2インスタンスを簡単に起動できるよ うにするために、新たなベースライン(たたき台)となるカスタムAMIを作成します。

3. In the Navigation pane, click Security Groups.4. In the details pane, under Security Groups, Select a security group you want to delete, and then click

Delete.5. Click Yes, Delete.

54

入門ガイド Linux 用 AWS コンピューティングの基本Delete an Amazon EC2 Security Group

Page 58: 入門ガイド - Amazon Web Servicesawsdocs.s3.amazonaws.com/gettingstarted/latest/awsgsg...設定済みの新しいAmazonEC2インスタンスを簡単に起動できるよ うにするために、新たなベースライン(たたき台)となるカスタムAMIを作成します。

Pricing

Topics• Amazon EC2 Cost Breakdown (p. 55)• Summing It All Up (p. 58)• How To Further Save Costs (p. 59)

The AWSSimple Monthly Calculator estimates your monthly bill. It provides a per-service cost breakdown,as well as an aggregate monthly estimate. You can also use the calculator to see an estimate andbreakdown of costs for common solutions. This topic walks you through an example of using the AWSSimple Monthly Calculator to estimate your monthly bill.

Note

AWS pricing you see in this documentation is current at the time of publication. For the latestpricing information, go to AWS Service Pricing Overview . For more information on how AWSpricing works, go to How AWS Pricing Works.

Amazon EC2 Cost BreakdownThe following table shows the characteristics for Amazon EC2 we have identified for this web applicationarchitecture. In this example, we'll assume that you've moved into full production and you need betweenthree and six instances. Three instances run all the time, two additional instances are required to handlepeak traffic times, and another instance handles nightly backups.

DescriptionMetricCharacteristic

Assuming an average of 30.5days in a month, the full-timeinstances run 732 hours/month,the peak traffic instances run 244hours/month, and the backupinstances run 91.5 hours/month

3 instances running 24 hours/day2 instances running 8 hours/day

1 instances running 3 hours/day

Clock Hours of Server Time

55

入門ガイド Linux 用 AWS コンピューティングの基本Amazon EC2 Cost Breakdown

Page 59: 入門ガイド - Amazon Web Servicesawsdocs.s3.amazonaws.com/gettingstarted/latest/awsgsg...設定済みの新しいAmazonEC2インスタンスを簡単に起動できるよ うにするために、新たなベースライン(たたき台)となるカスタムAMIを作成します。

DescriptionMetricCharacteristic

Micro - 613 MB of memory, up to2 ECUs (for short periodic bursts),EBS storage only, 32-bit or 64-bitplatform

Small- 1.7 GB of memory, 1 EC2Compute Unit (1 virtual core with1 EC2 Compute Unit), 160 GB oflocal instance storage, 32-bitplatform

For a list of instance types, go tohttp://aws.amazon.com/ec2/instance-types/.

1 ti.micro instance

5 m1.small instances

Machine Characteristics

The AMI is EBS-backed. Thevolume will have 10 GBprovisioned storage, and 100 I/Orequests per second made to thevolume.

1 EBS Volume

Storage: 10 GB/Month

100 IOPS

Additional Storage

There are approximately 1,000hits per day. Each response isabout 50 KB, and each request isabout 5 KB.

Data In: 0.005 GB/day

Data Out: 0.05 GB/day

Data Transfer

You need 3 instances running allthe time, another two to handlepeak traffic, and another to handlenightly backups.

Between 3 and 6 instancesInstance Scale

Elastic Load Balancing is used 24hrs/day, 7 days/week

Elastic Load Balancing processesa total of 0.055 GB/day (data in +data out)

Hourly usage: 732 hrs/month

Data processed: 1.525GB/month

Elastic Load Balancing

The following image from the AWS Simple Monthly Calculator shows the cost breakdown for AmazonEC2.

56

入門ガイド Linux 用 AWS コンピューティングの基本Amazon EC2 Cost Breakdown

Page 60: 入門ガイド - Amazon Web Servicesawsdocs.s3.amazonaws.com/gettingstarted/latest/awsgsg...設定済みの新しいAmazonEC2インスタンスを簡単に起動できるよ うにするために、新たなベースライン(たたき台)となるカスタムAMIを作成します。

The total monthly cost is the sum of the cost of the running instances, EBS volumes and I/O requests,Elastic Load Balancer, and the data processed by the Elastic Load Balancers. Because we used basicmonitoring and only one metric and alarm for our Amazon EC2 instances, there is no additional chargefor Amazon CloudWatch monitoring.

CalculationFormulaVariable

$0.080

3

x 732

-------

$175.68

Instance cost per hour

Number of instances

x Clock hours of server time

------------------------

Instance Cost

57

入門ガイド Linux 用 AWS コンピューティングの基本Amazon EC2 Cost Breakdown

Page 61: 入門ガイド - Amazon Web Servicesawsdocs.s3.amazonaws.com/gettingstarted/latest/awsgsg...設定済みの新しいAmazonEC2インスタンスを簡単に起動できるよ うにするために、新たなベースライン(たたき台)となるカスタムAMIを作成します。

CalculationFormulaVariable

$0.080

2

x 244

-------

$39.04

Instance cost per hour

Number of instances

x Clock hours of server time

------------------------

Instance Cost

$0.02

1

x 91.5

-------

$1.83

Instance cost per hour

Number of instances

x Clock hours of server time

------------------------

Instance Cost

$0.10 X 10

+ (100 x 2.6M x $0.10)/1M

x 6

-------------------------

$162.00

Storage rate x Storage Amount(GB)

+ (I/O requests rate x secondsper month x Request rate(per 1M

requests))

x Number of Volumes

--------------------------------------------------------------------------

Additional Storage

732 x $0.025

+ 1.6775 x $0.008

-----------------

$18.31

Hours used x Hourly rate

+ (Data processed (GB) xProcess rate)

--------------------------------------

Elastic Load Balancing

$396.86Total Cost Per Month

Move on to Summing It All Up (p. 58) to view a summary of the total charges including AWSData TransferOut and the Free Usage Tier discounts.

Summing It All UpTo calculate the total cost for this example, we add the cost for Amazon EC2 instances and the AWSData Transfer Out and then subtract any discount that falls into the AWS free usage tier. To learn moreabout the free usage tier and to find out if you are eligible, go to Getting Started Guide AWS Free UsageTier.

The total AWS Transfer Out is an aggregate Data Transfer Out usage across all Amazon EC2 instances.For Amazon EC2, we have 0.05 GB per day, which is approximately 1.525 GB per month. Because upto 1 GB per month of data transferred out is free, we are left with a total of 0.525 GB per month.

58

入門ガイド Linux 用 AWS コンピューティングの基本Summing It All Up

Page 62: 入門ガイド - Amazon Web Servicesawsdocs.s3.amazonaws.com/gettingstarted/latest/awsgsg...設定済みの新しいAmazonEC2インスタンスを簡単に起動できるよ うにするために、新たなベースライン(たたき台)となるカスタムAMIを作成します。

CalculationFormulaVariable

0.1525 X $0.00

+ (0.525) X $0.12

-----------------

$0.06

(Data in (GB) X Data In Rate)

+ (Data out (GB) X Data OutRate)

---------------------------------

AWS Data Transfer

The following image shows an example of your monthly estimate.

According to the calculator, the total cost for Amazon EC2 is $373.50.

How To Further Save CostsIn the example deployment we have been discussing, we used On-Demand Instances for all six of ourinstances. With On-Demand Instances, you are charged only from the time you launch an instance untilthe time you terminate it. If you plan to be running your instances for a long time, you can save moremoney by reserving them.

To obtain Reserved Instances, you make a low, one-time payment for each instance you want to reserve.In return, you receive a significant discount on the hourly usage charge. If you know approximately howheavily your Amazon EC2 instances will be used when they are running, you can save even more byopting for Heavy, Medium, or Light Utilization Reserved Instances. With Heavy Utilization, you pay ahigher upfront fee, but your hourly usage rate is the lower than that for Medium and Light UtilizationReserved Instances. Light Utilization has the lowest upfront free, but your hourly rate is higher than thatfor Medium and Heavy Utilization Instances. In the previous example, three of the instances are runningall the time. These instances are ideal candidates for Heavy Utilization Reserved Instances. Two instances

59

入門ガイド Linux 用 AWS コンピューティングの基本How To Further Save Costs

Page 63: 入門ガイド - Amazon Web Servicesawsdocs.s3.amazonaws.com/gettingstarted/latest/awsgsg...設定済みの新しいAmazonEC2インスタンスを簡単に起動できるよ うにするために、新たなベースライン(たたき台)となるカスタムAMIを作成します。

run only during peak traffic, about one third of the time. They are ideal candidates for Light UtilizationReserved Instances. Because the instance that performs the nightly backups runs only a few hours aday, you can run it as an On-Demand Instance.

Reserved Instances can be obtained on 1-year or 3-year terms. The 3-year term can offer additionalsavings over the 1-year term. For more information about reserved instances, go to Amazon EC2 ReservedInstances. You can see the cost comparison with On-Demand versus Reserved Instances over a three-yearperiod in the following table.

Using the same characteristics and metrics in the above example, let's update the calculator to enter theHeavy and Light Utilization as in the following diagram.

The total monthly cost is calculated the same way as the previous example, except that there is anadditional one-time fee for Reserved Instances. The total cost is shown in the following diagram.

60

入門ガイド Linux 用 AWS コンピューティングの基本How To Further Save Costs

Page 64: 入門ガイド - Amazon Web Servicesawsdocs.s3.amazonaws.com/gettingstarted/latest/awsgsg...設定済みの新しいAmazonEC2インスタンスを簡単に起動できるよ うにするために、新たなベースライン(たたき台)となるカスタムAMIを作成します。

The following table compares the total costs for using a mix of Heavy and Light Utilization ReservedInstances with those for On-Demand Instances.

Total Cost (3 years)One-time FeeMonthly CostInstance

$13446.00n/a$373.506 On-Demand Instances

$8401.16$1112.60$202.461 On-Demand Instance

3 Heavy Utilization ReservedInstances

2 Light Utilization ReservedInstances

As you can see from the table, by using a mix of Heavy and Light Utilization Reserved Instances in thisexample, you can save approximately 30%. For more information on how AWS pricing works, go to theHow AWS Pricing Works whitepaper.

Another way you can save money is by using Spot Instances. Spot Instances are unused Amazon EC2capacity that you bid for. Instances are charged at the Spot Price, which is set by Amazon EC2 andfluctuates periodically depending on the supply of, and demand for, Spot Instance capacity. If yourmaximum bid exceeds the current Spot Price, your bid request is fulfilled, and your instances will run untileither you choose to terminate them or the Spot Price increases above your maximum bid, whichever issooner. To learn more about Spot Instances, go to http://aws.amazon.com/ec2/spot-instances.

61

入門ガイド Linux 用 AWS コンピューティングの基本How To Further Save Costs

Page 65: 入門ガイド - Amazon Web Servicesawsdocs.s3.amazonaws.com/gettingstarted/latest/awsgsg...設定済みの新しいAmazonEC2インスタンスを簡単に起動できるよ うにするために、新たなベースライン(たたき台)となるカスタムAMIを作成します。

Related Resources

The following table lists related resources that you'll find useful as you work with AWS services.

DescriptionResource

A comprehensive list of products and services AWS offers.AWS Products and Services

Official documentation for each AWS product including serviceintroductions, service features, and API references, and otheruseful information.

Documentation

Provides the necessary guidance and best practices to buildhighly scalable and reliable applications in the AWS cloud.These resources help you understand the AWS platform, itsservices and features. They also provide architecturalguidance for design and implementation of systems that runon the AWS infrastructure.

AWS Architecture Center

Provides access to information, tools, and resources tocompare the costs of Amazon Web Services with ITinfrastructure alternatives.

AWS Economics Center

From here, you will find links to developer centers that providedocumentation, code samples, release notes, and otherinformation to help you build innovative applications with AWS.

AWS Developer Resource Centers

Features a comprehensive list of technical AWS whitepaperscovering topics such as architecture, security, and economics.These whitepapers have been authored either by the Amazonteam or by AWS customers or solution providers.

AWS Cloud Computing Whitepapers

Previously recorded webinars and videos about products,architecture, security, and more.

Videos and Webinars

A community-based forum for developers to discuss technicalquestions related to Amazon Web Services.

Discussion Forums

The home page for AWS Technical Support, including accessto our Developer Forums, Technical FAQs, Service Statuspage, and AWS Premium Support. (subscription required).

AWS Support Center

62

入門ガイド Linux 用 AWS コンピューティングの基本

Page 66: 入門ガイド - Amazon Web Servicesawsdocs.s3.amazonaws.com/gettingstarted/latest/awsgsg...設定済みの新しいAmazonEC2インスタンスを簡単に起動できるよ うにするために、新たなベースライン(たたき台)となるカスタムAMIを作成します。

DescriptionResource

The primary web page for information about AWS PremiumSupport, a one-on-one, fast-response support channel to helpyou build and run applications on AWS Infrastructure Services.

AWS Premium Support Information

This form is only for account questions. For technicalquestions, use the Discussion Forums.

Form for questions related to your AWSaccount: Contact Us

Detailed information about the copyright and trademark usageat Amazon.com and other topics.

Conditions of Use

63

入門ガイド Linux 用 AWS コンピューティングの基本

Page 67: 入門ガイド - Amazon Web Servicesawsdocs.s3.amazonaws.com/gettingstarted/latest/awsgsg...設定済みの新しいAmazonEC2インスタンスを簡単に起動できるよ うにするために、新たなベースライン(たたき台)となるカスタムAMIを作成します。

Document History

This document history is associated with the release of Getting Started Guide: AWS Computing Basicsfor Linux. This guide was last updated on January 24, 2013.

Release DateDescriptionChange

29 February2012

Created new documentNew content

8 March 2012Added section for connecting to Amazon EC2 using theMindTerm client

Added new section

64

入門ガイド Linux 用 AWS コンピューティングの基本