Movatterモバイル変換


[0]ホーム

URL:


Learn how to create an Amazon ECS Windows task for EC2 - Amazon Elastic Container Service
DocumentationAmazon ECSDeveloper Guide
PrerequisitesStep 1: Create a clusterStep 2: Register a task definitionStep 3: Create a ServiceStep 4: View your ServiceStep 5: Clean Up

Learn how to create an Amazon ECS Windows task for EC2

Get started with Amazon ECS using EC2 by registering a task definition, creating a cluster, and creating a service in the console.

Complete the following steps to get started with Amazon ECS using the EC2 launch type.

Prerequisites

Before you begin, complete the steps inSet up to use Amazon ECS and that your IAM user has the permissions specified in theAdministratorAccess IAM policy example.

The console attempts to automatically create the task execution IAM role, which is required for Fargate tasks. To ensure that the console is able to create this IAM role, one of the following must be true:

Step 1: Create a cluster

An Amazon ECS cluster is a logical grouping of tasks, services, and container instances.

The following steps walk you through creating a cluster with one Amazon EC2 instance registered to it which will enable us to run a task on it. If a specific field is not mentioned, leave the default console values.

To create a new cluster (Amazon ECS console)

Before you begin, assign the appropriate IAM permission. For more information, seeAmazon ECS cluster examples.

  1. Open the console athttps://console.aws.amazon.com/ecs/v2.

  2. From the navigation bar, select the Region to use.

  3. In the navigation pane, chooseClusters.

  4. On theClusters page, chooseCreate cluster.

  5. UnderCluster configuration, forCluster name, enter a unique name.

    The name can contain up to 255 letters (uppercase and lowercase), numbers, and hyphens.

  6. (Optional) To change the VPC and subnets where your tasks and services launch, underNetworking, perform any of the following operations:

    • To remove a subnet, underSubnets, chooseX for each subnet that you want to remove.

    • To change to a VPC other than thedefault VPC, underVPC, choose an existingVPC, and then underSubnets, select each subnet.

  7. To add Amazon EC2 instances to your cluster, expandInfrastructure, and then selectAmazon EC2 instances. Next, configure the Auto Scaling group which acts as the capacity provider:

    1. To using an existing Auto Scaling group, fromAuto Scaling group (ASG), select the group.

    2. To create a Auto Scaling group, fromAuto Scaling group (ASG), selectCreate new group, and then provide the following details about the group:

      • ForOperating system/Architecture, choose the Amazon ECS-optimized AMI for the Auto Scaling group instances.

      • ForEC2 instance type, choose the instance type for your workloads. For more information about the different instance types, seeAmazon EC2 Instances.

        Managed scaling works best if your Auto Scaling group uses the same or similar instance types.

      • ForSSH key pair, choose the pair that proves your identity when you connect to the instance.

      • ForCapacity, enter the minimum number and the maximum number of instances to launch in the Auto Scaling group. Amazon EC2 instances incur costs while they exist in your AWS resources. For more information, seeAmazon EC2 Pricing.

  8. (Optional) To turn on Container Insights, expandMonitoring, and then turn onUse Container Insights.

  9. (Optional) To manage the cluster tags, expandTags, and then perform one of the following operations:

    [Add a tag] ChooseAdd tag and do the following:

    • ForKey, enter the key name.

    • ForValue, enter the key value.

    [Remove a tag] ChooseRemove to the right of the tag’s Key and Value.

  10. ChooseCreate.

Step 2: Register a task definition

To register the sample task definition with the AWS Management Console
  1. In the navigation pane, chooseTask Definitions.

  2. ChooseCreate new task definition,Create new task definition with JSON.

  3. Copy and paste the following example task definition into the box, and then chooseSave.

    { "containerDefinitions": [{ "command": ["New-Item -Path C:\\inetpub\\wwwroot\\index.html -Type file -Value '<html> <head> <title>Amazon ECS Sample App</title> <style>body{margin-top: 40px; background-color: #333;} </style> </head><body> <div style=color:white;text-align:center> <h1>Amazon ECS Sample App</h1> <h2>Congratulations!</h2> <p>Your application is now running on a container in Amazon ECS.</p>'; C:\\ServiceMonitor.exe w3svc"], "entryPoint": [ "powershell", "-Command" ], "essential": true, "cpu": 2048, "memory": 4096, "image": "mcr.microsoft.com/windows/servercore/iis:windowsservercore-ltsc2019", "name": "sample_windows_app", "portMappings": [{ "hostPort": 443, "containerPort": 80, "protocol": "tcp" } ] } ], "memory": "4096", "cpu": "2048", "family": "windows-simple-iis-2019-core", "executionRoleArn": "arn:aws:iam::012345678910:role/ecsTaskExecutionRole", "runtimePlatform":{"operatingSystemFamily": "WINDOWS_SERVER_2019_CORE"}, "requiresCompatibilities": ["EC2"]}
  4. Verify your information and chooseCreate.

Step 3: Create a Service

An Amazon ECS service helps you to run and maintain a specified number of instances of a task definition simultaneously in an Amazon ECS cluster. If any of your tasks should fail or stop for any reason, the Amazon ECS service scheduler launches another instance of your task definition to replace it in order to maintain the desired number of tasks in the service. For more information on services, seeAmazon ECS services.

To create a service
  1. In the navigation pane, chooseClusters.

  2. Select the cluster you created inStep 1: Create a cluster.

  3. On theServices tab, chooseCreate.

  4. In theEnvironment section, do the following:

    1. ForCompute options, choose Launch type.

    2. ForLaunch type, selectEC2

  5. In theDeployment configuration section, do the following:

    1. ForFamily, choose the task definition you created inStep 2: Register a task definition.

    2. ForService name, enter a name for your service.

    3. ForDesired tasks, enter1.

  6. Review the options and chooseCreate.

  7. ChooseView service to review your service.

Step 4: View your Service

The service is a web-based application so you can view its containers with a web browser.

  1. Open the console athttps://console.aws.amazon.com/ecs/v2.

  2. In the navigation pane, chooseClusters.

  3. Choose the cluster where you ran the service.

  4. In theServices tab, under Service name, choose the service you created inStep 3: Create a Service.

  5. Choose theTasks tab, and then choose the task in your service.

  6. On the task page, in theConfiguration section, underPublic IP, chooseOpen address. The screen shot below is the expected output.

    Screen shot of the Amazon ECS sample application. The output indicates that "Your application is now running on Amazon ECS".

Step 5: Clean Up

When you are finished using an Amazon ECS cluster, you should clean up the resources associated with it to avoid incurring charges for resources that you are not using.

Some Amazon ECS resources, such as tasks, services, clusters, and container instances, are cleaned up using the Amazon ECS console. Other resources, such as Amazon EC2 instances, Elastic Load Balancing load balancers, and Auto Scaling groups, must be cleaned up manually in the Amazon EC2 console or by deleting the AWS CloudFormation stack that created them.

  1. In the navigation pane, chooseClusters.

  2. On theClusters page, select the cluster cluster you created for this tutorial.

  3. Choose theServices tab.

  4. Select the service, and then chooseDelete.

  5. At the confirmation prompt, enterdelete and then chooseDelete.

    Wait until the service is deleted.

  6. ChooseDelete Cluster. At the confirmation prompt, enterdeletecluster-name, and then chooseDelete. Deleting the cluster cleans up the associated resources that were created with the cluster, including Auto Scaling groups, VPCs, or load balancers.

Learn how to create a Windows task for Fargate
Using the AWS CDK

[8]
ページ先頭

©2009-2025 Movatter.jp