How do I launch ECS instances with Amazon ECS-optimized AMIs?

2 minuti di lettura
0

I want to launch instances with Amazon Machine Images (AMIs) optimized for Amazon Elastic Container Service (Amazon ECS). How can I do that?

Short description

To launch Amazon ECS-optimized AMIs, you can choose from the following options:

  • Launch an Amazon ECS-optimized container instance with an Amazon ECS-optimized AMI from the Amazon Elastic Compute Cloud (Amazon EC2) console
  • Automate the creation of your Amazon ECS-optimized AMIs

Resolution

Launch an Amazon ECS-optimized container instance with an Amazon ECS-optimized AMI

  1. Open the Amazon EC2 console.
  2. In the Create Instance section, choose Launch Instance.
  3. From the left navigation pane, choose AWS Marketplace. Then, enter ecs-optimized in the search bar.
  4. Choose one of the following AMI versions based on your needs: Amazon Linux AMI, Amazon Linux 2 AMI, Windows Server 2016, or Amazon Linux 2 AMI (ARM).
    Important: To get your Amazon ECS-optimized instance to join your Amazon ECS cluster, see Launching an Amazon ECS Linux container instance.

Automate the creation of your Amazon ECS-optimized AMIs

Use AWS Systems Manager parameters to automate and retrieve Amazon ECS-optimized AMI metadata.

In the following example, the image_id sub-parameter returns the machine image AMI ID for only the current recommended Amazon Linux EC2-optimized AMI version in us-east-1.

aws ssm get-parameters --names /aws/service/ecs/optimized-ami/amazon-linux/recommended/image_id --region us-east-1 --query "Parameters[0].Value"

You can use the AMI ID to launch your Amazon Linux container instance in us-east-1. You can also modify the command to return the machine image for a specific version and AWS Region.

Important: To use SSM parameters, run the most up-to-date version of the AWS Command Line Interface (AWS CLI).

You can use SSM parameters as input parameters for AWS CloudFormation templates. See the following example:

AWSTemplateFormatVersion: '2010-09-09'
Parameters:
  ImageId:
    Type: AWS::SSM::Parameter::Value<AWS::EC2::Image::Id>
    Description: Use an Image from SSM Parameter Store
    Default: /aws/service/ecs/optimized-ami/amazon-linux-2/recommended/image_id
Resources:
  EC2Instance:
    Type: AWS::EC2::Instance
    Properties:
      InstanceType: t3.micro
      SecurityGroups: [!Ref 'EC2SecurityGroup']
      ImageId: !Ref ImageId
  EC2SecurityGroup:
    Type: AWS::EC2::SecurityGroup
    Properties:
      GroupDescription: SSH access
      SecurityGroupIngress:
      - IpProtocol: tcp
        FromPort: '22'
        ToPort: '22'
        CidrIp: 0.0.0.0/0

Related information

Amazon Machine Images (AMI)

AWS UFFICIALE
AWS UFFICIALEAggiornata 2 anni fa