Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Follow these steps to launch a container in ECS using an image stored in AWS Elastic Container Registry (ECR):

  1. Download the docker image Docker image using the docker pull command from Admin Manager as shown below.
    docker pull <image_name>:<tag>

    download-docker-img.png

     

  2. Push the Docker Image to ECR.

  3. Create an ECS Cluster.

    1. In the AWS Management Console, navigate to ECS.

    2. In the Create cluster page, configure a new cluster.

    3. Select AWS Fargate (serverless) under Infrastructure.

      Image Modified
  4. Click Create.

  5. Create an IAM role.

  6. Create a new Task definition.

    1. In the AWS Management Console, navigate to ECS Console.

    2. Click Task Definitions and select Create a new task definition with JSON.

    3. Choose the Launch type compatibility as Fargate (serverless).

    4. Configure the task definition:

      • Task name: Provide a name, for example, demo-ecs-td

      • Add a container:

        • Container name: Specify a meaningful name.

        • Image: Provide the Docker image URL, for example, snaplogic/snaplex:latest. You can copy the URL from ECR (step 2).

        • Memory Limits: Set memory and CPU resources as per your use case.

      • Add the global.properties and keys.properties in the JSON file of the task definition (as shown below) or upload the slpropz file to the S3 bucket.

Code Block
"yum update -y && yum install -y wget unzip && wget 'https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip' -O 'awscliv2.zip' 
                 && unzip awscliv2.zip && ./aws/install && aws s3 cp s3://bucket_name/folder_name/global.properties/opt/snaplogic/etc/ 
                 && aws s3 cp s3://bucket_name/folder_name/keys.properties/opt/snaplogic/etc/ && chown -R snapuser:snapuser /opt/snaplogic/etc/ 
                 && /opt/snaplogic/bin/jcc.sh start && tail -f /dev/null"
  1. Save the task definition.

    Image Modified
  2. Create a Service.

  3. Select the cluster from the Existing cluster dropdown list.

  4. Select the task definition (demo-ecs-td) you created.

  5. Navigate to your ECS cluster (demo-ecs-cluster) and create a service (demo-ecs-service).

    Image Modified
  6. Run the Service in the ECS console.
    ECS will launch the containers using the task definition and the ECR image.

  7. Monitor the Service.
    Use the ECS Console or AWS CloudWatch to monitor your service's status and performance.

 

JSON file

Code Block
{
    "taskDefinitionArn": "arn:aws:ecs:us-west-2:123456789012:task-definition/my-task:1",                    
    "containerDefinitions": [
        {
            "name": "testcontainer",
            "image": "123456789012.dkr.ecr.us-west-2.amazonaws.com/test-image:ecr",
            "cpu": 2048,
            "memory": 4096,
            "memoryReservation": 2048,
            "portMappings": [
                {
                    "name": "testcontainer-80-tcp",
                    "containerPort": 8081,
                    "hostPort": 8081,
                    "protocol": "tcp"
                },
                {
                    "name": "testcontainer1-80-tcp2",
                    "containerPort": 8090,
                    "hostPort": 8090,
                    "protocol": "tcp"
                }
            ],
            "essential": true,
            "command": [
                "sh",
                "-c",
                "yum update -y && yum install -y wget unzip && wget 'https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip' -O 'awscliv2.zip' 
                 && unzip awscliv2.zip && ./aws/install && aws s3 cp s3://bucket_name/folder_name/global.properties/opt/snaplogic/etc/ 
                 && aws s3 cp s3://bucket_name/folder_name/keys.properties/opt/snaplogic/etc/ && chown -R snapuser:snapuser /opt/snaplogic/etc/ 
                 && /opt/snaplogic/bin/jcc.sh start && tail -f /dev/null"
            ],
            "environment": [
                {
                    "name": "LANG",
                    "value": "en_US.UTF-8"
                },
                {
                    "name": "LC_ALL",
                    "value": "en_US.UTF-8"
                },
                {
                    "name": "JAVA_TOOL_OPTIONS",
                    "value": "-Dfile.encoding=UTF-8 -Dsun.jnu.encoding=UTF-8"
                }
            ],
            "mountPoints": [
                {
                    "sourceVolume": "app-config",
                    "containerPath": "/opt/snaplogic/etc/",
                    "readOnly": false
                },
                {
                    "sourceVolume": "tmp-volume",
                    "containerPath": "/tmp",
                    "readOnly": false
                }
            ],
            "volumesFrom": [],
            "logConfiguration": {
                "logDriver": "awslogs",
                "options": {
                    "awslogs-group": "/ecs/loggroup-name",
                    "awslogs-create-group": "true",
                    "awslogs-region": "us-west-2",
                    "awslogs-stream-prefix": "ecs"
                }
            },
            "systemControls": []
        }
    ],
    "family": "test-ecs",
    "taskRoleArn": "arn:aws:iam::123456789012:role/ecsTaskExecutionRole",
    "executionRoleArn": "arn:aws:iam::123456789012:role/ecsTaskExecutionRole",
    "networkMode": "awsvpc",
    "revision": 1,
    "volumes": [
        {
            "name": "app-config",
            "host": {}
        },
        {
            "name": "tmp-volume",
            "host": {}
        }
    ],
    "status": "ACTIVE",
    "requiresAttributes": [
        {
            "name": "com.amazonaws.ecs.capability.logging-driver.awslogs"
        },
        {
            "name": "ecs.capability.execution-role-awslogs"
        },
        {
            "name": "com.amazonaws.ecs.capability.ecr-auth"
        },
        {
            "name": "com.amazonaws.ecs.capability.docker-remote-api.1.19"
        },
        {
            "name": "com.amazonaws.ecs.capability.docker-remote-api.1.21"
        },
        {
            "name": "com.amazonaws.ecs.capability.task-iam-role"
        },
        {
            "name": "ecs.capability.execution-role-ecr-pull"
        },
        {
            "name": "com.amazonaws.ecs.capability.docker-remote-api.1.18"
        },
        {
            "name": "ecs.capability.task-eni"
        },
        {
            "name": "com.amazonaws.ecs.capability.docker-remote-api.1.29"
        }
    ],
    "placementConstraints": [],
    "compatibilities": [
        "EC2",
        "FARGATE"
    ],
    "requiresCompatibilities": [
        "EC2",
        "FARGATE"
    ],
    "cpu": "2048",
    "memory": "8192",
    "runtimePlatform": {
        "cpuArchitecture": "X86_64",
        "operatingSystemFamily": "LINUX"
    },
    "registeredAt": "2025-01-10T11:03:11.429Z",
    "registeredBy": "arn:aws:iam::123456789012:assumed-role/aws-reserved-sso_3mk8fa2kc89w1/john.doe@example.com",
    "enableFaultInjection": false,
    "tags": []
}

...