入門ガイド - Amazon Web...

62
入門ガイド

Transcript of 入門ガイド - Amazon Web...

Page 1: 入門ガイド - Amazon Web Servicesawsdocs.s3.amazonaws.com/gettingstarted/latest/awsgsg...始するので、インスタンスを設定して起動します。手順4:インスタンスを起動(p.10)

入門ガイド

Page 2: 入門ガイド - Amazon Web Servicesawsdocs.s3.amazonaws.com/gettingstarted/latest/awsgsg...始するので、インスタンスを設定して起動します。手順4:インスタンスを起動(p.10)

入門ガイド: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.

入門ガイド

Page 3: 入門ガイド - Amazon Web Servicesawsdocs.s3.amazonaws.com/gettingstarted/latest/awsgsg...始するので、インスタンスを設定して起動します。手順4:インスタンスを起動(p.10)

Overview ................................................................................................................................................. 1開始 ......................................................................................................................................................... 7Step 1: Sign Up for the Service ............................................................................................................... 8手順 2:コマンドラインツールのインストール ..................................................................................... 8手順 3:適切な AMI を検索 .................................................................................................................... 9手順 4: インスタンスを起動 ............................................................................................................... 10手順 5:アプリケーションをデプロイ .................................................................................................. 14

Windows から Amazon EC2 インスタンスに接続 ...................................................................... 14IIS Manager を使用してウェブサイトを開始 .............................................................................. 17Amazon EC2 インスタンスの設定 .............................................................................................. 17

手順6:カスタム AMI を作成 ................................................................................................................ 24手順 7:Elastic Load Balancing の作成 ................................................................................................ 26手順 8: Amazon EC2 の更新 .............................................................................................................. 33手順 9:Auto Scaling を使用して Amazon EC2 インスタンスを起動 ................................................. 34手順 10:CloudWatch アラームの作成 ................................................................................................ 38手順 11: クリーンアップ ....................................................................................................................... 45

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

Pricing ................................................................................................................................................... 50Amazon EC2 Cost Breakdown .............................................................................................................. 50Summing It All Up ................................................................................................................................. 53How To Further Save Costs .................................................................................................................. 54Related Resources ................................................................................................................................ 57Document History .................................................................................................................................. 59

3

入門ガイド

Page 4: 入門ガイド - Amazon Web Servicesawsdocs.s3.amazonaws.com/gettingstarted/latest/awsgsg...始するので、インスタンスを設定して起動します。手順4:インスタンスを起動(p.10)

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 DotNetNuke. (DotNetNuke is anopen-source content management system.) You can adapt this sample to your specific needs if you want.By the end of this walkthrough, you should be able to do the following:

• Sign up for AWS.• Launch, connect, secure, and deploy DotNetNuke 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

入門ガイド

Page 5: 入門ガイド - Amazon Web Servicesawsdocs.s3.amazonaws.com/gettingstarted/latest/awsgsg...始するので、インスタンスを設定して起動します。手順4:インスタンスを起動(p.10)

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 forleaning more.

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

• Getting Started Guide: AWS Web Application Hosting for Windows — Provides a more in-depthwalkthrough that uses more services, such as Amazon Simple Storage Service (Amazon S3), AmazonCloudFront, Amazon Relational Database Service (Amazon RDS), and Amazon Route 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 Cloud Compute Microsoft Windows Guide — Provides information that helps you getstarted using Amazon EC2 instances that run the Microsoft Windows Server operating system.

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., Windows Server, IIS, and your website). A large selection of public AMIs isavailable from Amazon and the Amazon EC2 community. You can find an AMI that most closely matchesyour needs and then customize it. You can save this customized configuration to another AMI, which youcan use 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

入門ガイドIntroduction to AWS

Page 6: 入門ガイド - Amazon Web Servicesawsdocs.s3.amazonaws.com/gettingstarted/latest/awsgsg...始するので、インスタンスを設定して起動します。手順4:インスタンスを起動(p.10)

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.

SecurityTypically, after you buy a new computer you need to create a new password to access it. In AWS, a keypair is used to connect to your instance. After you connect to your instance, you'll change your passwordjust as you would on your local computer. You'll use this password to sign in to your instance each time.

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 instance 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 business running smoothly. You can use information from Amazon CloudWatch to takeaction on the policies that you set using Auto Scaling. For example, you can create an alarm to notify youif your CPU utilization exceeds 95%. If the threshold is exceeded, Amazon CloudWatch sends an alarm,and Auto Scaling takes action according to the policy that you set. In this example, Auto Scaling canlaunch a new instance to handle the increased load. Similarly, you could set an alarm that notifies you ifyour 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.

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 for

3

入門ガイドSecurity

Page 7: 入門ガイド - Amazon Web Servicesawsdocs.s3.amazonaws.com/gettingstarted/latest/awsgsg...始するので、インスタンスを設定して起動します。手順4:インスタンスを起動(p.10)

your 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

入門ガイドNetworking

Page 8: 入門ガイド - Amazon Web Servicesawsdocs.s3.amazonaws.com/gettingstarted/latest/awsgsg...始するので、インスタンスを設定して起動します。手順4:インスタンスを起動(p.10)

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

入門ガイドSummary

Page 9: 入門ガイド - Amazon Web Servicesawsdocs.s3.amazonaws.com/gettingstarted/latest/awsgsg...始するので、インスタンスを設定して起動します。手順4:インスタンスを起動(p.10)

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

入門ガイドSample Architecture

Page 10: 入門ガイド - Amazon Web Servicesawsdocs.s3.amazonaws.com/gettingstarted/latest/awsgsg...始するので、インスタンスを設定して起動します。手順4:インスタンスを起動(p.10)

開始

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. 24)• 手順 7:Elastic Load Balancing の作成 (p. 26)• 手順 8: Amazon EC2 の更新 (p. 33)• 手順 9:Auto Scaling を使用して Amazon EC2 インスタンスを起動 (p. 34)• 手順 10:CloudWatch アラームの作成 (p. 38)• 手順 11: クリーンアップ (p. 45)

オープンソースのコンテンツ管理システム (CMS)であるDotNetNuke Community Editionのデプロイを行ってみましょう。初めてでも簡単です。ほとんどのタスクには、AWS マネジメントコンソールを使用できます。このトピックでは、ウェブアプリケーションをAWSにデプロイする一連の手順を扱います。ウェブアプリケーションのデプロイには、多くの異なる方法があります。ここで扱うアプローチはベストプラクティスに従い、複数のコアサービスを使用しているため、それぞれの仕組みが分かるようになっています。

AWS を使用して DotNetNuke をデプロイする前に、AWS アカウントのサインアップを行い、AutoScaling コマンドラインツールをインストールする必要があります。 AWS にサインアップすると、すべてのサービスにアクセスできるようになりますが、料金は使用した分についてのみ発生します。

サインアップの後、ハードウェアとソフトウェアのニーズに合った適切な AMI が表示されます。このAMI を使用して、Amazon EC2 インスタンスを起動します。 Amazon EC2 を起動すると、新しいキーペアとセキュリティグループが作成されます。セキュリティグループは、Amazon EC2 インスタンスにアクセス可能なユーザーの規則を設定し、キーペアは Amazon EC2 インスタンスへの接続に必要です。

インスタンスを安全に実行すると、必要なソフトウェアのインストールが終了し、DotNetNukeアプリケーションが構成されます。すでに構成された新規の Amazon EC2 インスタンスの起動を簡単にするには、新たなベースラインとなるカスタムの AMI を作成します。

Elastic Load Balancing を作成してトラフィック負荷を複数のインスタンスに分散し、セキュリティグループを更新して HTTP トラフィックを全員ではなく使用するロードバランサーからのみ使用できる

7

入門ガイド

Page 11: 入門ガイド - Amazon Web Servicesawsdocs.s3.amazonaws.com/gettingstarted/latest/awsgsg...始するので、インスタンスを設定して起動します。手順4:インスタンスを起動(p.10)

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

この時点で、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 Scaling コマンドラインツールに移動します。AutoScalingツール設定の説明については、AmazonElasticComputeCloud Microsoft Windows Guideの「Installing the Amazon EC2 Command Line Tools on Windows 」を参照してください。コマンドラインツールをインストールしたら、いくつかのコマンドを試して動作を確認します。たとえば、プロンプトでas-cmdコマンドを入力してみてください。

PROMPT>as-cmd

このコマンドは、すべての Auto Scaling コマンドとその説明の一覧を返します。以下と同様の出力結果が表示されるはずです。

8

入門ガイドStep 1: Sign Up for the Service

Page 12: 入門ガイド - Amazon Web Servicesawsdocs.s3.amazonaws.com/gettingstarted/latest/awsgsg...始するので、インスタンスを設定して起動します。手順4:インスタンスを起動(p.10)

コマンドラインツールをインストールした後、AWS リソースの作成を開始できます。手順 3:適切なAMIを検索(p. 9)に移動し、適切なAMIを検索する方法を学習します。このAMIを使用して、AmazonEC2 インスタンスを起動します。この AMI は、カスタム AMI 作成の基本ともなります。

手順 3:適切な AMI を検索Amazon Machine Image(AMI)は、サーバの画像化されたバージョンと同じです。通常、インスタンスを起動する、Amazonが提供した基本画像から開始し、アプリケーションと権限の内容を設定し、それを自らのAMIにまとめ、起動を迅速化し拡張性を高めます。これにより、AMIをウェブサーバ(例:Windows Server、IIS、ウェブサイト)として、またはその他の権限として事前に設定できます。

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

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

ここでは、Windows Server 2008 R2 SP1 と SQL Server Express 2008 R2、IIS をインストールしたAmazon Windows AMI を使用します。Windows AMI の詳細については、 Amazon Elastic ComputeCloud User Guideの「Amazon Windows AMI Basics」を参照してください。

適切な AMI を見つける

1. Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/.2. [Navigation] ペインの [AMIs] をクリックします。3. すべてのプラットフォームを表示する「Viewing」一覧の [Amazon Machine Images] ペインで、

[Windows] をクリックします。すべての画像を表示する一覧で、必要に応じ表示を絞り込むオプ

9

入門ガイド手順 3:適切な AMI を検索

Page 13: 入門ガイド - Amazon Web Servicesawsdocs.s3.amazonaws.com/gettingstarted/latest/awsgsg...始するので、インスタンスを設定して起動します。手順4:インスタンスを起動(p.10)

ションをクリックします。この例では、[Amazon Images] をクリックして、アマゾンウェブサービスが提供する AMI に表示を限定します。

4. Windows Server 2008 R2 および IIS、SQL Server を実行する、AMI ID ami-e31ccb8a などの AMIを選択してから、[Launch] をクリックします。

このAMIを基本として使用します。 [ Launch]をクリックすると、[Request Instances]ウィザードが開始するので、インスタンスを設定して起動します。手順 4:インスタンスを起動 (p. 10)

手順 4:インスタンスを起動前の手順で選択した AMI を使用して、Amazon EC2 インスタンスを次に起動します。インスタンスの起動には、次のタスクが関連しています。

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

Important

これから起動するインスタンスはライブです。このチュートリアルにある最後のタスクでインスタンスを終了するまで、Amazon EC2標準使用料が発生します。この作業を1つのセッションで完了すると、合計の使用量が最小限に抑えられます(通常は 1ドル以下)。Amazon EC2使用料に関する詳細は、Amazon EC2 製品ページを参照してください。

Amazon EC2 インスタンスを起動

1. AMI を選択した後、前の手順のように [Launch Instance] をクリックすると、「Create a NewInstance」ページが表示されます。このページには、次のようにインスタンスを起動する 2 つの方法が記載されています。

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

10

入門ガイド手順 4:インスタンスを起動

Page 14: 入門ガイド - Amazon Web Servicesawsdocs.s3.amazonaws.com/gettingstarted/latest/awsgsg...始するので、インスタンスを設定して起動します。手順4:インスタンスを起動(p.10)

• AWSMarketplaceは、AWS上で実行されるソフトウェアを見つけて購入し、すばやくデプロイすることができるオンラインストアです。1回クリックするだけで、インスタンスが迅速に起動します。

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

2. [Request Instances Wizard] ウィザードの「インスタンスの詳細」ページの [Instance Type] で、[Large (m1.large, 7.5 GB)] を選択します。

このページの他のデフォルトはそのまま使用して、[Continue]をクリックします。次の2ページにあるデフォルトをそのまま使用して、それぞれで [Continue] をクリックします。ウィザードで「キーペアを作成」ページが表示されたら、次のページに移動します。

3. キーペアの作成:

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

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

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

b. Create &Download your Key Pairをクリックします。

11

入門ガイド手順 4:インスタンスを起動

Page 15: 入門ガイド - Amazon Web Servicesawsdocs.s3.amazonaws.com/gettingstarted/latest/awsgsg...始するので、インスタンスを設定して起動します。手順4:インスタンスを起動(p.10)

キーペアのプライベートキーをシステムへ保存するように求められます。c. プライベートキーをシステムの安全な場所に保存し、保存場所を記録します。

Important

AmazonEC2インスタンスに接続するには、このキーペアが必要です。キーペアをなくすと、接続できません。

ウィザードに「ファイアウォールを構成」ページが表示されます。ここでセキュリティグループを作成します。

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

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

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

クリックします。

Caution

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

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

12

入門ガイド手順 4:インスタンスを起動

Page 16: 入門ガイド - Amazon Web Servicesawsdocs.s3.amazonaws.com/gettingstarted/latest/awsgsg...始するので、インスタンスを設定して起動します。手順4:インスタンスを起動(p.10)

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

セキュリティグループが作成され、ID(例:sg-48996e20)が割り当てられます。インスタンスは、この新しいセキュリティグループに起動されます。ウィザードが、設定を確認してインスタンスを起動するための「Review」ページに進みます。

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

a. 設定が望みどおりの場合、[Launch] をクリックします。インスタンスを起動していることを知らせる確認ページが表示されます。

b. 確認ページで、[Close]をクリックします。[Navigation]ペインの[Instances]をクリックして、インスタンスのステータスを表示します。インスタンスはすぐに起動します。インスタンスの起動中は、ステータスは保留中(pending)と表示されます。

この後すぐにインスタンスのステータスは実行中(running)に変わります。表示を手作業で更新するには、[Refresh] をクリックします。

c. インスタンスのパブリック DNS 名:

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

13

入門ガイド手順 4:インスタンスを起動

Page 17: 入門ガイド - Amazon Web Servicesawsdocs.s3.amazonaws.com/gettingstarted/latest/awsgsg...始するので、インスタンスを設定して起動します。手順4:インスタンスを起動(p.10)

インスタンスのステータスが実行中の場合、インスタンスに接続してアプリケーションをデプロイできます。

手順 5:アプリケーションをデプロイTopics• Windows から Amazon EC2 インスタンスに接続 (p. 14)• IIS Manager を使用してウェブサイトを開始 (p. 17)• Amazon EC2 インスタンスの設定 (p. 17)

Amazon EC2 インスタンスを起動したので、ここでインスタンスに接続しアプリケーションをデプロイします。この手順では、DotNetNukeをデプロイします。

Windows から Amazon EC2 インスタンスに接続Windows インスタンスに接続するには、管理者アカウントの初期パスワードを取得してから、そのパスワードをWindows Remote Desktop で使用する必要があります。また、手順 4:インスタンスを起動 (p. 10)で、作成したプライベートキーファイルのコンテンツも必要です(例:mykeypair.pem)。

Note

Amazon EC2 インスタンスを起動してから元のパスワードを取得するまで、最大で 30 分かかる場合があります。

14

入門ガイド手順 5:アプリケーションをデプロイ

Page 18: 入門ガイド - Amazon Web Servicesawsdocs.s3.amazonaws.com/gettingstarted/latest/awsgsg...始するので、インスタンスを設定して起動します。手順4:インスタンスを起動(p.10)

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

1. AWS 管理コンソールにサインインして Amazon EC2 コンソール(https://console.aws.amazon.com/ec2/)を開きます。

2. [Navigation] ペインの [Instances] をクリックします。3. 作成したインスタンスを右クリックして、[Continue] をクリックします。

4. [Retrieve Password] をクリックします。

Note

初回の起動時にのみ、パスワードを取得する必要があります。インスタンスに接続した後、パスワードを変更し、再びサインインする際には新しいパスワードを使用してください。

5. インスタンスを起動した時にプライベートキーファイルを保存したディレクトリに移動します。6. テキストエディタでキーペアファイルを開き、すべてのコンテンツ(BEGIN RSA PRIVATE KEY

とEND RSA PRIVATE KEYを含む、最初と最後の行を含む)をコピーします。7. [Private Key contents] フィールドに、プライベートキーファイルのコンテンツを貼り付けてから

[Decrypt Password] をクリックします。

15

入門ガイドWindows から Amazon EC2 インスタンスに接続

Page 19: 入門ガイド - Amazon Web Servicesawsdocs.s3.amazonaws.com/gettingstarted/latest/awsgsg...始するので、インスタンスを設定して起動します。手順4:インスタンスを起動(p.10)

8. パスワードをメモします。インスタンスに接続するにはこのパスワードが必要です。

Tip

パスワードはコピーして貼り付けることもできます。次の手順のために、クリップボードにコピーしておいてください。

9. [Download shortcut file] をクリックし、[Open] をクリックします。

Note

Windows XP 以降のほとんどのWindows オペレーティングシステムには、すでにリモートデスクトップアプリケーションが含まれています。Windowsの古いバージョンを使用してる場合は、Microsoftのウェブサイトからリモートデスクトップアプリケーションをダウンロードすることができます。

10. Administratorを、ユーザー名および、以前の手順でパスワードとして取得した管理者パスワードとして使用して、インスタンスにログインします。

Important

起動した新しいWindowsインスタンスに接続した後、Windows管理者パスワードをデフォルト値から変更することをお勧めします。他のWindows ベースのコンピュータと同様、パスワードの変更は、インスタンス自体にログインした状態で行います。

11. インスタンスで別のユーザーアカウントを作成してから、そのアカウントをAdministratorsグループに追加します。これは、管理者パスワードを忘れた場合や、管理者アカウントで問題が発生した場合の安全策です。

16

入門ガイドWindows から Amazon EC2 インスタンスに接続

Page 20: 入門ガイド - Amazon Web Servicesawsdocs.s3.amazonaws.com/gettingstarted/latest/awsgsg...始するので、インスタンスを設定して起動します。手順4:インスタンスを起動(p.10)

これで、普通のWindows Server コンピュータと同じようにしてインスタンスを使うことができます。IIS Manager を使用してウェブサイトを開始 (p. 17)に移動して、IIS Manager を使用してウェブサイトに接続します。

IIS Manager を使用してウェブサイトを開始DotNetNuke のデプロイに進む前に、IIS Manager を使用してウェブサイトを開始できることを確認します。

IIS Manager を使用してウェブサイトを開始

1. Amazon EC2 インスタンスから [Start] をクリックします。[Administrative Tools] をクリックしてから、[Internet Information Services(IIS) Manager] をクリックします。

2. localhost ノードを展開します。3. Sitesノードを展開します。

4. [Default Web Site]を右クリックして [ManageWeb Site]にポイントし、[Start]をクリックします。5. 手順 4:インスタンスを起動 (p. 10) に記録した Amazon EC2 インスタンスのパブリック DNS ア

ドレスをローカルコンピュータのブラウザにコピーし、サイトに接続できることを確認します。

ウェブサーバが正常に動作していることを確認した後、DotNetNuke を Amazon EC2 インスタンスにデプロイします。

Amazon EC2 インスタンスの設定このトピックでは、Microsoft Web Platform Installer をインストールしてから、Amazon EC2 インスタンスに DotNetNuke をインストールして設定します。

Server Manager 設定を指定します。

1. AmazonEC2インスタンスで[Start]をクリックします。[Administrative Tools]を右クリックして、[Server Manager] をクリックします。

2. [Security Information] パネルの [Server Manager] ボックスで、[Configure IE ESC] をクリックします。

17

入門ガイドIIS Manager を使用してウェブサイトを開始

Page 21: 入門ガイド - Amazon Web Servicesawsdocs.s3.amazonaws.com/gettingstarted/latest/awsgsg...始するので、インスタンスを設定して起動します。手順4:インスタンスを起動(p.10)

3. [Administrators] の下にある [Internet Explorer Enhanced Security Configuration] ボックスで、[Off]をクリックしてから [OK] をクリックします。

4. [Server Manager] ボックスを閉じるには、[OK] をクリックします。5. Amazon EC2 インスタンスの [Internet Explorer] ウェブアドレスボックスに、

[http://www.iis.net/download/webdeploy] と入力します。6. 最新バージョンのWebDeployをインストールするには、[DownloadExtension]ボックスで、[Install]

をクリックします。

7. [Install Now] ボタンの隣で、[license terms] をクリックし、ライセンス条件を読みます。

18

入門ガイドAmazon EC2 インスタンスの設定

Page 22: 入門ガイド - Amazon Web Servicesawsdocs.s3.amazonaws.com/gettingstarted/latest/awsgsg...始するので、インスタンスを設定して起動します。手順4:インスタンスを起動(p.10)

8. ライセンス条件に同意する場合、[Install Now] をクリックします。9. プロンプトが表示されたら [Run] をクリックしてMicrosoft Webデプロイツールをインストールし

ます。

10. [Web Platform Installer] ダイアログボックスで、[Install] をクリックします。

19

入門ガイドAmazon EC2 インスタンスの設定

Page 23: 入門ガイド - Amazon Web Servicesawsdocs.s3.amazonaws.com/gettingstarted/latest/awsgsg...始するので、インスタンスを設定して起動します。手順4:インスタンスを起動(p.10)

11. 第三者のアプリケーションソフトウェアの一覧に Microsoft 製品やコンポーネントが表示される場合、[I Accept] をクリックします。Web Platform Installer がソフトウェアのインストールを開始します。

12. インストールが完了したら、[Finish] をクリックします。次にWeb Platform Installer が起動するので、DotNetNuke をインストールする必要があります。

DotNetNuke をインストール

1. [Web Platform Installer 3.0 ] ウィンドウの上部で [Applications] をクリックします。

20

入門ガイドAmazon EC2 インスタンスの設定

Page 24: 入門ガイド - Amazon Web Servicesawsdocs.s3.amazonaws.com/gettingstarted/latest/awsgsg...始するので、インスタンスを設定して起動します。手順4:インスタンスを起動(p.10)

2. [DotNetNuke Community Edition] 行に移動し、[Add] をクリックしてから [Install] をクリックします。

3. インストールするデータベースとして、[SQL Server] を選択します。[This database engine is notinstalled] ボックスで、[Install it on my machine] をクリックしてから、[Continue] をクリックします。

4. 第三者アプリケーションの一覧にMicrosoft製品やコンポーネントが表示される場合、[I Accept]をクリックします。

21

入門ガイドAmazon EC2 インスタンスの設定

Page 25: 入門ガイド - Amazon Web Servicesawsdocs.s3.amazonaws.com/gettingstarted/latest/awsgsg...始するので、インスタンスを設定して起動します。手順4:インスタンスを起動(p.10)

5. [Mixed Mode Authentication] をクリックします。[Password] ボックスと [Confirm Password] ボックスに SQL Server Express データベースのパスワードを入力します。インストールが終了するまで、数分かかる場合があります。終了したら、新規サイトの設定を行うようプロンプトが表示されます。[Continue] をクリックします。

6. 「Enter your site information」ページの「Step 1 of 2」で、すべてのデフォルト情報をそのまま使用して [Continue] をクリックします。

7. インストールが完了したら、[Launch DotNetNuke Community Edition] をクリックします。

22

入門ガイドAmazon EC2 インスタンスの設定

Page 26: 入門ガイド - Amazon Web Servicesawsdocs.s3.amazonaws.com/gettingstarted/latest/awsgsg...始するので、インスタンスを設定して起動します。手順4:インスタンスを起動(p.10)

8. DotNetNuke Community Edition の「Welcome」ページが表示されたら、以下を実行します。

a. [Advanced Settings] ダイアログボックスで、DotNetNuke アプリケーションプールの ID をNetworkService: に設定します。

i. IIS で、[Application Pools] をクリックします。ii. [dotnetnuke] を右クリックしてから、[Advanced Settings] をクリックします。iii. [ProcessModel]の下で、IDをNetworkServiceに変更してから、[OK]をクリックします。

23

入門ガイドAmazon EC2 インスタンスの設定

Page 27: 入門ガイド - Amazon Web Servicesawsdocs.s3.amazonaws.com/gettingstarted/latest/awsgsg...始するので、インスタンスを設定して起動します。手順4:インスタンスを起動(p.10)

iv. [Advanced Settings] ダイアログボックスで、[OK] をクリックします。

b. DotNetNuke Community Edition の「Welcome」ページで、すべてのデフォルトをそのままにして[Next] をクリックします。

9. 「Configuring SuperUser Account and Website Information」ページが表示されるまで、ウィザードを続けすべてのデフォルトをそのまま使用します。

10. 「SuperUserアカウントとウェブサイト情報を設定」ページで、SuperUserアカウントとウェブサイトの情報を入力してから、[Name] をクリックします。

これで終了です。アマゾンウェブサービスを使用して、DotNetNuke のデプロイが正常に終了しました。動作を確認するには、ローカルコンピュータのウェブブラウザに、手順 4:インスタンスを起動 (p. 10) に記録した Amazon EC2 インスタンスの DNS アドレスを入力します。アドレスの末尾にdotnetnukeを追加します(例:http://ec2-107-21-89-39.compute-1.amazonaws.com/dotnetnuke)。

将来、現在以上のインスタンスを起動し、インスタンス上にアプリケーションをデプロイするとした場合、それぞれをカスタマイズする必要はありません。手順6:カスタム AMI を作成 (p. 24) では、すべての設定の変更を使用して、カスタムのAmazon Machine Image(AMI)を作成する方法が説明しています。

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

24

入門ガイド手順6:カスタム AMI を作成

Page 28: 入門ガイド - Amazon Web Servicesawsdocs.s3.amazonaws.com/gettingstarted/latest/awsgsg...始するので、インスタンスを設定して起動します。手順4:インスタンスを起動(p.10)

実行中の 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 から起動するインスタンスはルートデバイスボリュームとしてこのスナップショットを使用します。

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

25

入門ガイド手順6:カスタム AMI を作成

Page 29: 入門ガイド - Amazon Web Servicesawsdocs.s3.amazonaws.com/gettingstarted/latest/awsgsg...始するので、インスタンスを設定して起動します。手順4:インスタンスを起動(p.10)

手順 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と入力します。

26

入門ガイド手順 7:Elastic Load Balancing の作成

Page 30: 入門ガイド - Amazon Web Servicesawsdocs.s3.amazonaws.com/gettingstarted/latest/awsgsg...始するので、インスタンスを設定して起動します。手順4:インスタンスを起動(p.10)

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」ページで、以下を実行します。

27

入門ガイド手順 7:Elastic Load Balancing の作成

Page 31: 入門ガイド - Amazon Web Servicesawsdocs.s3.amazonaws.com/gettingstarted/latest/awsgsg...始するので、インスタンスを設定して起動します。手順4:インスタンスを起動(p.10)

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に設定します。他のオプションでは、デフォルト値をそのまま使用します。

28

入門ガイド手順 7:Elastic Load Balancing の作成

Page 32: 入門ガイド - Amazon Web Servicesawsdocs.s3.amazonaws.com/gettingstarted/latest/awsgsg...始するので、インスタンスを設定して起動します。手順4:インスタンスを起動(p.10)

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

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

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

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

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

29

入門ガイド手順 7:Elastic Load Balancing の作成

Page 33: 入門ガイド - Amazon Web Servicesawsdocs.s3.amazonaws.com/gettingstarted/latest/awsgsg...始するので、インスタンスを設定して起動します。手順4:インスタンスを起動(p.10)

Important

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

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

30

入門ガイド手順 7:Elastic Load Balancing の作成

Page 34: 入門ガイド - Amazon Web Servicesawsdocs.s3.amazonaws.com/gettingstarted/latest/awsgsg...始するので、インスタンスを設定して起動します。手順4:インスタンスを起動(p.10)

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

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

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

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

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

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

31

入門ガイド手順 7:Elastic Load Balancing の作成

Page 35: 入門ガイド - Amazon Web Servicesawsdocs.s3.amazonaws.com/gettingstarted/latest/awsgsg...始するので、インスタンスを設定して起動します。手順4:インスタンスを起動(p.10)

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)を介しすべてのトラフィックが AmazonEC2 インスタンスに接続することを許可するよう設定しました。Elastic Load Balancing を作成したの

32

入門ガイド現在扱っている内容

Page 36: 入門ガイド - Amazon Web Servicesawsdocs.s3.amazonaws.com/gettingstarted/latest/awsgsg...始するので、インスタンスを設定して起動します。手順4:インスタンスを起動(p.10)

で、セキュリティグループを更新し、Elastic Load Balancing から着信 HTTP トラフィックのみを許可するようにできます。手順 8: Amazon EC2 の更新 (p. 33)に移動します。

手順 8: Amazon EC2 の更新手順 4:インスタンスを起動 (p. 10) で、ポート 80 で HTTP を有効にするセキュリティグループを作成しました。セキュリティグループは、すべてのトラフィックに、HTTP/80から直接Amazon EC2にアクセスすることを許可しています。Elastic Load Balancing を作成しているので、より安全な方法として、ロードバランサーにのみ Amazon EC2 インスタンスへのアクセスを許可します。このタスクでは、セキュリティグループを更新し、ロードバランサーにのみHTTP/80からAmazon EC2インスタンスへのアクセスを許可します。

セキュリティグループを構成

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

プをクリックします。5. [Security Group] の下で、[Inbound] タブをクリックします。6. ポート 80(HTTP)を表示する行で、[Delete] をクリックします。7. 「新たな規則を作成」一覧で、[HTTP] をクリックします。8. [Source] ボックスには amazon-elb/amazon-elb-sg と入力します。これが、AWS が Elastic Load

Balancingに割り当てるセキュリティグループの名前となります。 [Add Rule] をクリックします。9. [Apply Rule Changes] をクリックします。

Note

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

33

入門ガイド手順 8: Amazon EC2 の更新

Page 37: 入門ガイド - Amazon Web Servicesawsdocs.s3.amazonaws.com/gettingstarted/latest/awsgsg...始するので、インスタンスを設定して起動します。手順4:インスタンスを起動(p.10)

これで、Amazon EC2 セキュリティグループの構成を行ったので、手順 9:Auto Scaling を使用してAmazon EC2 インスタンスを起動 (p. 34)に移動できます。Auto Scaling を使用して、トラフィックのレベルが変わった際に、実行するインスタンスの数を調整できます。

手順 9:Auto Scaling を使用して Amazon EC2 インスタンスを起動

Auto Scaling は、ユーザーが定義したポリシーやスケジュール、アラームに従い、自動的に AmazonEC2 を起動、終了します。 Auto Scaling を使用し、表示された負荷を調整可能な一連の Amazon EC2インスタンスを保持できます。Auto Scalingを使用し、1つのグループに複数のインスタンスを入れることもできます。

名前から分かるように、Auto Scaling は条件の変更に自動的に対応します。こうした変更への対応方法を指定するだけで済みます。例えば、Auto Scaling で、1 つまたは複数の既存のインスタンスでのCPU使用が10分間にわたり60%を超えた場合には常に追加のインスタンスを起動するようにしたり、トラフィックが低水準と予想される場合に、週末にかけウェブサイトのインスタンスの半分を終了するようにすることもできます。

AutoScalingを使用して、インスタンスのパフォーマンスを最適化し、アプリケーションが引き続き効率的に実行するようにできます。 Auto Scaling グループは、複数のアベイラビリティーゾーンでも動作可能なので、あるアベイラビリティーゾーンが利用できなくなった場合、AutoScalingは自動的に、トラフィックを別のアベイラビリティーゾーンに再度振り向けます。 Auto Scaling を使用して、正常なインスタンスが常に 1つ以上実行されているようにできます。詳細については、「Auto Scaling」を参照してください。

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

• 起動構成の作成。• Auto Scaling グループの作成。• Auto Scaling グループのポリシーの作成。

このチュートリアルでは、Amazon EC2 アプリケーションを、ロードバランスを取り、インスタンスの最低数を 2、最大数を 2 とするようオートスケールを行うよう設定しています。最低数と最大数を同じに設定すると、1つのインスタンスが動作しなくなっても、指定した数のインスタンスが常に動作するようにできます。実際にウェブサイトを作成する際、ベストプラクティスとして、アベイラビリティーゾーン全体で十分なインスタンスを起動し、アベイラビリティーゾーンが1つ失われても大丈夫なようにしてください。さらに、AutoScaling機能を使用するために、インスタンスの最大数を、最小数より大きくなるように増やします。

インスタンスの最大数を指定して、全体の規模を制御できます。この例では、AutoScalingは、負荷が増えるとインスタンスを1つ追加するよう設定されます。このトピックではポリシーを定義し、次のセクションではCloudWatch を作成して、NetworkOut の平均が 5 分間にわたり 6,000,000 バイトというしきい値を超えた際に、ポリシーにあるアクションを起こすようにします。 Auto Scaling と AmazonCloudWatchは連携して、作成されたポリシーに基づいて、インスタンスを起動または終了します。時間を節約するため、ポリシーは1つしか作成しませんが、負荷が減った際にインスタンスを終了するポリシーなど、複数のポリシーを作成できます。

AutoScalingコマンドラインツールをまだインストールしていない場合、インストールする必要があります。 Auto Scaling コマンドラインツールをローカルコンピュータにインストールするには、「AutoScaling コマンドラインツール」を参照してください。Auto Scaling ツールの構成の説明については、Amazon Elastic Compute CloudMicrosoft WindowsGuideの「Installing the Amazon EC2Command LineTools on Windows 」を参照してください。

34

入門ガイド手順 9:Auto Scaling を使用して Amazon EC2 インスタン

スを起動

Page 38: 入門ガイド - Amazon Web Servicesawsdocs.s3.amazonaws.com/gettingstarted/latest/awsgsg...始するので、インスタンスを設定して起動します。手順4:インスタンスを起動(p.10)

オートスケールとロードバランスのある Amazon EC2 アプリケーションを設定

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

2. 起動設定が、Auto Scaling グループで起動するインスタンスのテンプレートとなります。この例の起動設定の定義では、as-create-launch-configコマンドを使用します。次のパラメータが、起動設定を定義します。

• image-id が、AMI の IDとなります。手順6:カスタムAMIを作成 (p. 24)で作成したカスタムのAMI ID を使用。

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

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

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

• monitoring-disabled は、詳細なモニターではなく、基本的なモニターを使用するよう指定します。デフォルトでは、詳細な監視が有効になっています。基本的な監視および詳細な監視の詳細については、「Amazon CloudWatch」を参照してください。

デフォルトのリージョン(USEast(Virginia))を使用するので、リージョンは指定しません。コマンドプロンプトで、次のように入力してから [Enter] を押します。

PROMPT>as-create-launch-config MyLC --image-id ami-191dc970 --instance-type m1.large --group webappsecuritygroup --key mykeypair --monitoring-disabled

Auto Scaling が次のように返します。

OK-Created launch config

Note

この文書からコマンドをコピーし、[Command Prompt]ウィンドウに貼り付けることができます。コマンドラインウィンドウにコンテンツを貼り付けるには、[Command Prompt]ウィンドウを右クリックしてから[Paste]をクリックします。コマンドが機能しない場合、コマンドの入力が正しいことを確認してください。

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

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

• launch-configuration は、前の手順で作成した起動設定の名前です。• availability-zones は、Auto Scaling グループで Amazon EC2 インスタンスを起動するアベイラビリティーゾーンを指定します。この例では、アベイラビリティーゾーンを 2 つ指定します。

35

入門ガイド手順 9:Auto Scaling を使用して Amazon EC2 インスタン

スを起動

Page 39: 入門ガイド - Amazon Web Servicesawsdocs.s3.amazonaws.com/gettingstarted/latest/awsgsg...始するので、インスタンスを設定して起動します。手順4:インスタンスを起動(p.10)

フォールトトレラントなアプリケーションの構築のため、複数のアベイラビリティーゾーンを指定するようにしてください。一方のアベイラビリティーゾーンが停止すると、トラフィックが別のアベイラビリティーゾーンにルーティングされます。AutoScalingグループで起動されるインスタンス数は、複数のアベイラビリティーゾーンに均等に分散されます。

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

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

コマンドプロンプトで、次のように入力し、[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

4. インスタンスの集団を拡大するポリシーを作成するには、as-put-scaling-policyコマンドを使用します。このポリシーは、前の手順で作成した Auto Scaling グループに適用されます。 AutoScaling ポリシーを定義する際には、次のパラメータを使用します。

• 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つしか作成しませんでした。大半の場合、トラフィックが減少した際に1つまたは複数のインスタンスを終了するポリシーも作成します。Auto Scaling は、アプリケーションでリソースが不要な際にインスタンスの数を減らし、費用を節約することができます。インスタンスを終了するポリシーを作成するには、先ほど作成したポリシーでポリシー名を変更してから、調整の値を 1 から -1に変更します。Windows マシンでは、"--adjustment=-1"を使用します。コマンドプロンプトで、次のように入力し、[Enter] キーを押します。

36

入門ガイド手順 9:Auto Scaling を使用して Amazon EC2 インスタン

スを起動

Page 40: 入門ガイド - Amazon Web Servicesawsdocs.s3.amazonaws.com/gettingstarted/latest/awsgsg...始するので、インスタンスを設定して起動します。手順4:インスタンスを起動(p.10)

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-1c 2 2 2INSTANCE INSTANCE-ID AVAILABILITY-ZONE STATE STATUS LAUNCH-CONFIGINSTANCE i-xxxxxxxx us-east-1b InService Healthy MyLCINSTANCE i-xxxxxxxx us-east-1c InService Healthy MyLC

Amazon EC2 アプリケーションは、オートスケールとロードバランスのあるアプリケーションとして起動しています。

Auto Scaling の詳細については、「Auto Scaling Developer Guide」を参照してください。

Caution

AmazonEC2インスタンスを実行している間は、引き続き費用が発生します。このインスタンスを終了する場合は、Terminate Your Amazon EC2 Instances in Your Auto Scaling Group (p. 46)を参照してください。

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

37

入門ガイド現在扱っている内容

Page 41: 入門ガイド - Amazon Web Servicesawsdocs.s3.amazonaws.com/gettingstarted/latest/awsgsg...始するので、インスタンスを設定して起動します。手順4:インスタンスを起動(p.10)

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

手順 10:CloudWatch アラームの作成Amazon CloudWatch は、さまざまなメトリクスをモニターおよび管理、公開し、このメトリクスに基づきアラームアクションを構成できるようにするウェブサービスです。

Amazon CloudWatch を使用して、システムとアプリケーションのメトリクスを収集、分析、表示し、操作や業務上の決定を確信を持って迅速に行えます。Amazon CloudWatch は、Amazon EC2インスタンスのパフォーマンスなど、AWSリソースについてのメトリクスを自動的に収集します。独自のメトリクスを、Amazon CloudWatch に直接パブリッシュできます。

Amazon CloudWatch を使用し、問題が発生する前および発生後にシステムのパフォーマンスを検討して、問題の診断を行えます。Amazon CloudWatch は、パフォーマンスをリアルタイムで追跡するので、原因の特定や修正の確認に役立ちます。例えば、アプリケーションの速度が低下した際にただちに電子メールを送信するよう Amazon CloudWatch を設定すると、特定のデータベースの負荷が高くなっていることが分かります。問題を修正した際に、Amazon CloudWatch を使用して、反応時間が通常に戻ったことを検証できます。CloudWatchアラームの作成の詳細については、AmazonCloudWatchDeveloper Guideの「 Creating CloudWatch Alarms」を参照してください。

Amazon CloudWatch の一般的な利用として、アプリケーションとサービスを健全な状態に保ち、効率的に実行することがあります。例えば、AmazonCloudWatchを使用して、AmazonEC2インスタンスへのネットワークトラフィックが特定のしきい値を常に下回っている際にウェブサイトの実行が最適であることが分かります。 Auto Scaling ポリシーを作成し、現在のトラフィック数に見合う適切な数のインスタンスが常にあることを確認できます。

以前のタスクで、実行中のインスタンスの数を追加するためのAutoScalingポリシーを作成しました。このタスクでは、そのポリシーをアラームアクションと関連付けます。アラームが起動されると、AutoScaling に通知が行われ、リソースが適宜変更されます。

次の特性を使用してアラームを作成します。

38

入門ガイド手順 10:CloudWatch アラームの作成

Page 42: 入門ガイド - Amazon Web Servicesawsdocs.s3.amazonaws.com/gettingstarted/latest/awsgsg...始するので、インスタンスを設定して起動します。手順4:インスタンスを起動(p.10)

次の図には、AmazonCloudWatchとAutoScalingがどのように協働するかが示されています。AmazonEC2 インスタンスは、NetworkOut メトリクスを Amazon CloudWatch に報告します。 AmazonCloudWatch は、指定されたしきい値を超えた場合にアラームを発動し、Auto Scaling グループに報告します。 Auto Scaling グループは、設定されたポリシーに基づきアクションを起こします。

このトピックでは、しきい値を超えた際にアプリケーションに警告を行うCloudWatchアラームの作成を扱います。時間を節約するため、作成するアラームは 1 つだけですが、同じ手順を他のアラーム作成に適用できます。例えば、別のアラームを作成し、インスタンス終了に必要な Auto Scaling に通知を行うこともできます。AmazonCloudWatchの詳細については、「AmazonCloudWatch」の詳細ページを参照してください。

Amazon CloudWatch を作成

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

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

39

入門ガイド手順 10:CloudWatch アラームの作成

Page 43: 入門ガイド - Amazon Web Servicesawsdocs.s3.amazonaws.com/gettingstarted/latest/awsgsg...始するので、インスタンスを設定して起動します。手順4:インスタンスを起動(p.10)

b. [Navigation]ペインの [Region]一覧にある、[USEast(Virginia)]をクリックします。[Alarms]をクリックします。

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

Auto Scaling Group] を選択します。

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と入力します。自分のアプリケーションで、負荷テストを行い、どの値が最適化を確かめることができます。

40

入門ガイド手順 10:CloudWatch アラームの作成

Page 44: 入門ガイド - Amazon Web Servicesawsdocs.s3.amazonaws.com/gettingstarted/latest/awsgsg...始するので、インスタンスを設定して起動します。手順4:インスタンスを起動(p.10)

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)] ボックスに、通知の送信先の電子メールアドレスを入力します。

41

入門ガイド手順 10:CloudWatch アラームの作成

Page 45: 入門ガイド - Amazon Web Servicesawsdocs.s3.amazonaws.com/gettingstarted/latest/awsgsg...始するので、インスタンスを設定して起動します。手順4:インスタンスを起動(p.10)

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

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

42

入門ガイド手順 10:CloudWatch アラームの作成

Page 46: 入門ガイド - Amazon Web Servicesawsdocs.s3.amazonaws.com/gettingstarted/latest/awsgsg...始するので、インスタンスを設定して起動します。手順4:インスタンスを起動(p.10)

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

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

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

お疲れ様でした。AWSの必須構築ブロックの一部を使用して、ウェブアプリケーションをEC2にデプロイしました。すべてが正常に動作していることを確認するには、次の事項を行います。

43

入門ガイド現在扱っている内容

Page 47: 入門ガイド - Amazon Web Servicesawsdocs.s3.amazonaws.com/gettingstarted/latest/awsgsg...始するので、インスタンスを設定して起動します。手順4:インスタンスを起動(p.10)

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

2. 手順 7:Elastic Load Balancing の作成 (p. 26)に記録した Elastic Load Balancing のパブリック DNSアドレスを入力し、アプリケーションが表示できるかを確認します。DNS アドレスに /dotnetnukeを追加するのを忘れないでください。

Note

各 Amazon EC2 インスタンスに SQL Express をデプロイしたため、各インスタンスはデータベースのローカルコピーを実行しています。ウェブサイトを表示すると、異なるコンテンツを表示できます。このアーキテクチャを変更し、データをインスタンス全体で同期させるには、AmazonRelational Database Service (AmazonRDS)の使用を含むいくつかの方法があります。Amazon RDS を使用してのウェブアプリケーションのデプロイの詳細については、GettingStarted Guide AWS Web Application Hosting for Microsoft Windowsの「Step 10: Add AmazonRDS」を参照してください。

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

• アプリケーションを実行する Amazon EC2• インスタンスの実行全体でトラフィック負荷を均衡させる Elastic Load Balancing• 設定したポリシーに従いインスタンスを自動的に追加、終了する Auto Scaling• インスタンスをモニターし、指定のしきい値を超えた際に通知する Amazon CloudWatch

44

入門ガイド現在扱っている内容

Page 48: 入門ガイド - Amazon Web Servicesawsdocs.s3.amazonaws.com/gettingstarted/latest/awsgsg...始するので、インスタンスを設定して起動します。手順4:インスタンスを起動(p.10)

AWS サービスと使用法についての理解が深まると、アプリケーションのデプロイが簡単になります。AWS CloudFormation を使用すると、AWS サービスのプロビジョニングを行う順序や、依存関係の機能についての詳細を気にせずに、AWS でリソースをデプロイできるようになります。このチュートリアルで使用したサービスを使用してサンプルのテンプレートを構築する方法を学習するには、AWSCloudFormation User Guideの「Auto Scaling Group with LoadBalancer, Auto Scaling Policies, andCloudWatch Alarms」を参照してください。

AWS リソースの使用が終了したら、リソースを終了できます。以後は費用はかかりません。手順 11:クリーンアップ (p. 45)に移動します。

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

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

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.

45

入門ガイド手順 11: クリーンアップ

Page 49: 入門ガイド - Amazon Web Servicesawsdocs.s3.amazonaws.com/gettingstarted/latest/awsgsg...始するので、インスタンスを設定して起動します。手順4:インスタンスを起動(p.10)

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.

46

入門ガイドDelete Your Elastic Load Balancer

Page 50: 入門ガイド - Amazon Web Servicesawsdocs.s3.amazonaws.com/gettingstarted/latest/awsgsg...始するので、インスタンスを設定して起動します。手順4:インスタンスを起動(p.10)

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:

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.

47

入門ガイドTerminate Your Amazon EC2 Instances in Your Auto Scaling

Group

Page 51: 入門ガイド - Amazon Web Servicesawsdocs.s3.amazonaws.com/gettingstarted/latest/awsgsg...始するので、インスタンスを設定して起動します。手順4:インスタンスを起動(p.10)

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.

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.

48

入門ガイドインスタンスの終了

Page 52: 入門ガイド - Amazon Web Servicesawsdocs.s3.amazonaws.com/gettingstarted/latest/awsgsg...始するので、インスタンスを設定して起動します。手順4:インスタンスを起動(p.10)

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).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.

49

入門ガイドDelete an Amazon EC2 Security Group

Page 53: 入門ガイド - Amazon Web Servicesawsdocs.s3.amazonaws.com/gettingstarted/latest/awsgsg...始するので、インスタンスを設定して起動します。手順4:インスタンスを起動(p.10)

Pricing

Topics• Amazon EC2 Cost Breakdown (p. 50)• Summing It All Up (p. 53)• How To Further Save Costs (p. 54)

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

50

入門ガイドAmazon EC2 Cost Breakdown

Page 54: 入門ガイド - Amazon Web Servicesawsdocs.s3.amazonaws.com/gettingstarted/latest/awsgsg...始するので、インスタンスを設定して起動します。手順4:インスタンスを起動(p.10)

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 30 GBprovisioned storage, and 100 I/Orequests per second made to thevolume.

1 EBS Volume

Storage: 30 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.

51

入門ガイドAmazon EC2 Cost Breakdown

Page 55: 入門ガイド - Amazon Web Servicesawsdocs.s3.amazonaws.com/gettingstarted/latest/awsgsg...始するので、インスタンスを設定して起動します。手順4:インスタンスを起動(p.10)

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.115

3

x 732

-------

$252.54

Instance cost per hour

Number of instances

x Clock hours of server time

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

Instance Cost

$0.115

2

x 244

-------

$56.12

Instance cost per hour

Number of instances

x Clock hours of server time

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

Instance Cost

52

入門ガイドAmazon EC2 Cost Breakdown

Page 56: 入門ガイド - Amazon Web Servicesawsdocs.s3.amazonaws.com/gettingstarted/latest/awsgsg...始するので、インスタンスを設定して起動します。手順4:インスタンスを起動(p.10)

CalculationFormulaVariable

$0.03

1

x 91.5

-------

$2.75

Instance cost per hour

Number of instances

x Clock hours of server time

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

Instance Cost

$0.10 X 30

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

x 6

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

$174.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

$503.72Total Cost Per Month

To view a summary of the total charges including AWS Data Transfer Out and the Free Usage Tierdiscounts, move on to Summing It All Up (p. 53) .

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.

53

入門ガイドSumming It All Up

Page 57: 入門ガイド - Amazon Web Servicesawsdocs.s3.amazonaws.com/gettingstarted/latest/awsgsg...始するので、インスタンスを設定して起動します。手順4:インスタンスを起動(p.10)

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 from the calculator shows an example of your monthly estimate.

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

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 UtilizatonReserved 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. This is an ideal candidate for Heavy Utilization Reserved Instances. Two instances run onlyduring peak traffic, about one third of the time. These instances 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.

54

入門ガイドHow To Further Save Costs

Page 58: 入門ガイド - Amazon Web Servicesawsdocs.s3.amazonaws.com/gettingstarted/latest/awsgsg...始するので、インスタンスを設定して起動します。手順4:インスタンスを起動(p.10)

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 calcuated 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.

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

55

入門ガイドHow To Further Save Costs

Page 59: 入門ガイド - Amazon Web Servicesawsdocs.s3.amazonaws.com/gettingstarted/latest/awsgsg...始するので、インスタンスを設定して起動します。手順4:インスタンスを起動(p.10)

Total Cost (3 years)One-time FeeMonthly CostInstance

$17259.84n/a$479.446 On-Demand Instances

$10775.68$1112.60$268.031 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 32%. 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.

56

入門ガイドHow To Further Save Costs

Page 60: 入門ガイド - Amazon Web Servicesawsdocs.s3.amazonaws.com/gettingstarted/latest/awsgsg...始するので、インスタンスを設定して起動します。手順4:インスタンスを起動(p.10)

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

57

入門ガイド

Page 61: 入門ガイド - Amazon Web Servicesawsdocs.s3.amazonaws.com/gettingstarted/latest/awsgsg...始するので、インスタンスを設定して起動します。手順4:インスタンスを起動(p.10)

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

58

入門ガイド

Page 62: 入門ガイド - Amazon Web Servicesawsdocs.s3.amazonaws.com/gettingstarted/latest/awsgsg...始するので、インスタンスを設定して起動します。手順4:インスタンスを起動(p.10)

Document History

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

Release DateDescriptionChange

29 February2012

Created new documentNew content

59

入門ガイド