...
Follow these steps to launch a container in ECS using an image stored in AWS Elastic Container Registry (ECR):
Download the docker image Docker image using the docker pull command from Admin Manager as shown below.
docker pull <image_name>:<tag
>Push the Docker Image to ECR.
Create an ECS Cluster.
In the AWS Management Console, navigate to ECS.
In the Create cluster page, configure a new cluster.
Select AWS Fargate (serverless) under Infrastructure.
Click Create.
Create a new Task definition.
In the AWS Management Console, navigate to ECS Console.
Click Task Definitions and select Create a new task definition with JSON.
Choose the Launch type compatibility as Fargate (serverless).
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
andkeys.properties
in the JSON file of the task definition (as shown below) or upload theslpropz
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" |
Save the task definition.
Create a Service.
Select the cluster from the Existing cluster dropdown list.
Select the task definition (demo-ecs-td) you created.
Navigate to your ECS cluster (demo-ecs-cluster) and create a service (demo-ecs-service).
Run the Service in the ECS console.
ECS will launch the containers using the task definition and the ECR image.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": [] } |
...