How do I launch Amazon ECS-optimized AMIs?

Last updated: 2020-01-17

How do I launch Amazon Machine Images (AMIs) optimized for Amazon Elastic Container Service (Amazon ECS)?

Short Description

Choose one of the following options:

  • Launch an Amazon ECS-optimized container instance with an Amazon ECS-optimized AMI
  • 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 Elastic Compute Cloud (Amazon EC2) console.
  2. In the Create Instance section, choose Launch Instance.
  3. Choose AWS Marketplace, and 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 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 version of the Amazon Linux ECS-optimized AMI 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. Also, you can 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

Did this article help you?

Anything we could improve?


Need more help?