Skip to content

Commit acbee58

Browse files
committed
revamp ecs
1 parent 4999a52 commit acbee58

File tree

1 file changed

+41
-32
lines changed
  • src/content/docs/aws/services

1 file changed

+41
-32
lines changed

src/content/docs/aws/services/ecs.md

Lines changed: 41 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
---
22
title: "Elastic Container Service (ECS)"
3-
linkTitle: "Elastic Container Service (ECS)"
43
tags: ["Base"]
54
description: Get started with Elastic Container Service (ECS) on LocalStack
65
persistence: supported
@@ -13,7 +12,7 @@ It allows you to run, stop, and manage Docker containers on a cluster.
1312
ECS eliminates the need for you to install, operate, and scale your own cluster management infrastructure.
1413

1514
LocalStack allows you to use the ECS APIs in your local environment to create & manage ECS clusters, tasks, and services.
16-
The supported APIs are available on our [API coverage page]({{< ref "coverage_ecs" >}}), which provides information on the extent of ECS's integration with LocalStack.
15+
The supported APIs are available on our [API coverage page](), which provides information on the extent of ECS's integration with LocalStack.
1716

1817
## Getting Started
1918

@@ -24,16 +23,20 @@ We will demonstrate how to create an ECS service using the AWS CLI
2423

2524
### Create a cluster
2625

27-
{{< callout >}}
26+
:::note
2827
By default, the **ECS Fargate** launch type is assumed, i.e., the local Docker engine is used for deployment of applications, and there is no need to create and manage EC2 virtual machines to run the containers.
29-
{{< /callout >}}
28+
:::
3029

3130
ECS tasks and services run on a cluster.
3231
Execute the following command to create an ECS cluster named `mycluster`:
3332

34-
{{< command >}}
35-
$ awslocal ecs create-cluster --cluster-name mycluster
36-
<disable-copy>
33+
```bash
34+
awslocal ecs create-cluster --cluster-name mycluster
35+
```
36+
37+
The output will be:
38+
39+
```json
3740
{
3841
"cluster": {
3942
"clusterArn": "arn:aws:ecs:us-east-1:000000000000:cluster/mycluster",
@@ -51,8 +54,7 @@ $ awslocal ecs create-cluster --cluster-name mycluster
5154
]
5255
}
5356
}
54-
</disable-copy>
55-
{{< / command >}}
57+
```
5658

5759
### Create a task definition
5860

@@ -90,9 +92,13 @@ To create a task definition that runs an `ubuntu` container forever (by running
9092

9193
and then run the following command:
9294

93-
{{< command >}}
94-
$ awslocal ecs register-task-definition --cli-input-json file://task_definition.json
95-
<disable-copy>
95+
```bash
96+
awslocal ecs register-task-definition --cli-input-json file://task_definition.json
97+
```
98+
99+
The output will be:
100+
101+
```json
96102
{
97103
"taskDefinition": {
98104
"taskDefinitionArn": "arn:aws:ecs:us-east-1:000000000000:task-definition/myfamily:1",
@@ -136,8 +142,7 @@ $ awslocal ecs register-task-definition --cli-input-json file://task_definition.
136142
"registeredAt": 1713364207.068659
137143
}
138144
}
139-
</disable-copy>
140-
{{< / command >}}
145+
```
141146

142147
Task definitions are immutable, and are identified by their `family` field, and calling `register-task-definition` again with the same `family` value creates a new _version_ of a task definition.
143148

@@ -149,9 +154,13 @@ Finally we launch an ECS service using the task definition above.
149154
This will create a number of containers in replica mode meaning they are distributed over the nodes of the cluster, or in the case of Fargate, over availability zones within the region of the cluster.
150155
To create a service, execute the following command:
151156

152-
{{< command >}}
153-
$ awslocal ecs create-service --service-name myservice --cluster mycluster --task-definition myfamily --desired-count 1
154-
<disable-copy>
157+
```bash
158+
awslocal ecs create-service --service-name myservice --cluster mycluster --task-definition myfamily --desired-count 1
159+
```
160+
161+
The output will be:
162+
163+
```json
155164
{
156165
"service": {
157166
"serviceArn": "arn:aws:ecs:us-east-1:000000000000:service/mycluster/myservice",
@@ -196,8 +205,7 @@ $ awslocal ecs create-service --service-name myservice --cluster mycluster --tas
196205
"createdBy": "arn:aws:iam::000000000000:user/test"
197206
}
198207
}
199-
</disable-copy>
200-
{{< / command >}}
208+
```
201209

202210
You should see a new docker container has been created, using the `ubuntu:latest` image, and running the infinite loop command:
203211

@@ -212,9 +220,13 @@ CONTAINER ID IMAGE COMMAND CREATED
212220

213221
To access the generated logs from the container, run the following command:
214222

215-
{{< command >}}
223+
```bash
216224
awslocal logs filter-log-events --log-group-name myloggroup --query 'events[].message'
217-
<disable-copy>
225+
```
226+
227+
The output will be:
228+
229+
```json
218230
$ awslocal logs filter-log-events --log-group-name myloggroup | head -n 20
219231
{
220232
"events": [
@@ -236,10 +248,9 @@ $ awslocal logs filter-log-events --log-group-name myloggroup | head -n 20
236248
"logStreamName": "myprefix/ls-ecs-mycluster-75f0515e-0364-4ee5-9828-19026140c91a-0-a1afaa9d/75f0515e-0364-4ee5-9828-19026140c91a",
237249
"timestamp": 1713364216505,
238250
"message": "running",
239-
</disable-copy>
240-
{{< / command >}}
251+
```
241252

242-
See our [CloudWatch Logs user guide]({{< ref "user-guide/aws/logs" >}}) for more details.
253+
See our [CloudWatch Logs user guide](/aws/services/cloudwatchlogs) for more details.
243254

244255
## LocalStack ECS behavior
245256

@@ -250,7 +261,7 @@ If your ECS containers depend on LocalStack services, your ECS task network shou
250261
If you are running LocalStack through a `docker run` command, do not forget to enable the communication from the container to the Docker Engine API.
251262
You can provide the access by adding the following option `-v /var/run/docker.sock:/var/run/docker.sock`.
252263

253-
For more information regarding the configuration of LocalStack, please check the [LocalStack configuration]({{< ref "configuration" >}}) section.
264+
For more information regarding the configuration of LocalStack, please check the [LocalStack configuration](/aws/capabilities/config/configuration) section.
254265

255266
## Remote debugging
256267

@@ -261,7 +272,7 @@ Or if you are working with a single container, you can set `ECS_DOCKER_FLAGS="-p
261272
## Mounting local directories for ECS tasks
262273

263274
In some cases, it can be useful to mount code from the host filesystem into the ECS container.
264-
For example, to enable a quick debugging loop where you can test changes without having to build and redeploy the task's Docker image each time - similar to the [Lambda Hot Reloading]({{< ref "hot-reloading" >}}) feature in LocalStack.
275+
For example, to enable a quick debugging loop where you can test changes without having to build and redeploy the task's Docker image each time - similar to the [Lambda Hot Reloading](/aws/services/lambda#hot-reloading) feature in LocalStack.
265276

266277
In order to leverage code mounting, we can use the ECS bind mounts feature, which is covered in the [AWS Bind mounts documentation](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/bind-mounts.html).
267278

@@ -336,14 +347,14 @@ services:
336347
- ~/.docker/config.json:/config.json:ro
337348
```
338349

339-
Alternatively, you can download the image from the private registry before using it or employ an [Initialization Hook]({{< ref "/references/init-hooks" >}}) to install the Docker client and use these credentials to download the image.
350+
Alternatively, you can download the image from the private registry before using it or employ an [Initialization Hook](/aws/capabilities/config/initalization-hooks) to install the Docker client and use these credentials to download the image.
340351

341352
## Firelens for ECS Tasks
342353

343-
{{< callout >}}
354+
:::note
344355
Firelens emulation is currently available as part of the **LocalStack Enterprise** plan.
345356
If you'd like to try it out, please [contact us](https://www.localstack.cloud/demo) to request access.
346-
{{< /callout >}}
357+
:::
347358

348359
LocalStack's ECS emulation supports custom log routing via FireLens.
349360
FireLens allows the ECS service to manage the configuration of the logging driver of application containers, and to create the proper configuration for the `fluentbit`/`fluentd` logging layer.
@@ -356,9 +367,7 @@ Additionally, you cannot use ECS on Kubernetes with FireLens.
356367
The LocalStack Web Application provides a Resource Browser for managing ECS clusters & task definitions.
357368
You can access the Resource Browser by opening the LocalStack Web Application in your browser, navigating to the **Resource Browser** section, and then clicking on **ECS** under the **Compute** section.
358369

359-
<img src="ecs-resource-browser.png" alt="ECS Resource Browser" title="ECS Resource Browser" width="900" />
360-
<br>
361-
<br>
370+
![ECS Resource Browser](/images/aws/ecs-resource-browser.png)
362371

363372
The Resource Browser allows you to perform the following actions:
364373

0 commit comments

Comments
 (0)