2022-04-15 13:44:08 +00:00
|
|
|
---
|
|
|
|
title: "Traefik AWS ECS Documentation"
|
|
|
|
description: "Configuration discovery in Traefik is achieved through Providers. Read the technical documentation for leveraging AWS ECS in Traefik."
|
|
|
|
---
|
|
|
|
|
2020-07-15 14:28:04 +00:00
|
|
|
# Traefik & AWS ECS
|
|
|
|
|
|
|
|
A Story of Labels & Elastic Containers
|
|
|
|
{: .subtitle }
|
|
|
|
|
|
|
|
Attach labels to your ECS containers and let Traefik do the rest!
|
|
|
|
|
|
|
|
## Configuration Examples
|
|
|
|
|
|
|
|
??? example "Configuring ECS provider"
|
|
|
|
|
|
|
|
Enabling the ECS provider:
|
2021-02-11 18:04:03 +00:00
|
|
|
|
2020-07-15 14:28:04 +00:00
|
|
|
```yaml tab="File (YAML)"
|
|
|
|
providers:
|
2020-11-18 23:12:03 +00:00
|
|
|
ecs: {}
|
2020-07-15 14:28:04 +00:00
|
|
|
```
|
2021-02-11 18:04:03 +00:00
|
|
|
|
2021-06-18 22:08:08 +00:00
|
|
|
```toml tab="File (TOML)"
|
|
|
|
[providers.ecs]
|
|
|
|
```
|
|
|
|
|
2020-07-15 14:28:04 +00:00
|
|
|
```bash tab="CLI"
|
2020-11-18 23:12:03 +00:00
|
|
|
--providers.ecs=true
|
2020-07-15 14:28:04 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
## Policy
|
|
|
|
|
|
|
|
Traefik needs the following policy to read ECS information:
|
|
|
|
|
|
|
|
```json
|
|
|
|
{
|
|
|
|
"Version": "2012-10-17",
|
|
|
|
"Statement": [
|
|
|
|
{
|
|
|
|
"Sid": "TraefikECSReadAccess",
|
|
|
|
"Effect": "Allow",
|
|
|
|
"Action": [
|
|
|
|
"ecs:ListClusters",
|
|
|
|
"ecs:DescribeClusters",
|
|
|
|
"ecs:ListTasks",
|
|
|
|
"ecs:DescribeTasks",
|
|
|
|
"ecs:DescribeContainerInstances",
|
|
|
|
"ecs:DescribeTaskDefinition",
|
2022-09-14 14:22:08 +00:00
|
|
|
"ec2:DescribeInstances",
|
|
|
|
"ssm:DescribeInstanceInformation"
|
2020-07-15 14:28:04 +00:00
|
|
|
],
|
|
|
|
"Resource": [
|
|
|
|
"*"
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2022-09-14 14:22:08 +00:00
|
|
|
!!! info "ECS Anywhere"
|
|
|
|
|
|
|
|
Please note that the `ssm:DescribeInstanceInformation` action is required for ECS anywhere instances discovery.
|
|
|
|
|
2021-02-11 18:04:03 +00:00
|
|
|
## Provider Configuration
|
2020-07-15 14:28:04 +00:00
|
|
|
|
|
|
|
### `autoDiscoverClusters`
|
|
|
|
|
|
|
|
_Optional, Default=false_
|
|
|
|
|
2021-02-11 18:04:03 +00:00
|
|
|
Search for services in cluster list.
|
|
|
|
|
|
|
|
- If set to `true` service discovery is disabled on configured clusters, but enabled for all other clusters.
|
|
|
|
- If set to `false` service discovery is enabled on configured clusters only.
|
|
|
|
|
2020-07-15 14:28:04 +00:00
|
|
|
```yaml tab="File (YAML)"
|
|
|
|
providers:
|
|
|
|
ecs:
|
|
|
|
autoDiscoverClusters: true
|
|
|
|
# ...
|
|
|
|
```
|
|
|
|
|
2021-06-18 22:08:08 +00:00
|
|
|
```toml tab="File (TOML)"
|
|
|
|
[providers.ecs]
|
|
|
|
autoDiscoverClusters = true
|
|
|
|
# ...
|
|
|
|
```
|
|
|
|
|
2020-07-15 14:28:04 +00:00
|
|
|
```bash tab="CLI"
|
|
|
|
--providers.ecs.autoDiscoverClusters=true
|
|
|
|
# ...
|
|
|
|
```
|
|
|
|
|
2022-09-14 14:22:08 +00:00
|
|
|
### `ecsAnywhere`
|
|
|
|
|
|
|
|
_Optional, Default=false_
|
|
|
|
|
|
|
|
Enable ECS Anywhere support.
|
|
|
|
|
|
|
|
- If set to `true` service discovery is enabled for ECS Anywhere instances.
|
|
|
|
- If set to `false` service discovery is disabled for ECS Anywhere instances.
|
|
|
|
|
|
|
|
```yaml tab="File (YAML)"
|
|
|
|
providers:
|
|
|
|
ecs:
|
|
|
|
ecsAnywhere: true
|
|
|
|
# ...
|
|
|
|
```
|
|
|
|
|
|
|
|
```toml tab="File (TOML)"
|
|
|
|
[providers.ecs]
|
|
|
|
ecsAnywhere = true
|
|
|
|
# ...
|
|
|
|
```
|
|
|
|
|
|
|
|
```bash tab="CLI"
|
|
|
|
--providers.ecs.ecsAnywhere=true
|
|
|
|
# ...
|
|
|
|
```
|
|
|
|
|
2020-07-28 08:44:05 +00:00
|
|
|
### `clusters`
|
|
|
|
|
|
|
|
_Optional, Default=["default"]_
|
|
|
|
|
2021-02-11 18:04:03 +00:00
|
|
|
Search for services in cluster list.
|
|
|
|
|
2020-07-28 08:44:05 +00:00
|
|
|
```yaml tab="File (YAML)"
|
|
|
|
providers:
|
|
|
|
ecs:
|
|
|
|
clusters:
|
|
|
|
- default
|
|
|
|
# ...
|
|
|
|
```
|
|
|
|
|
2021-06-18 22:08:08 +00:00
|
|
|
```toml tab="File (TOML)"
|
|
|
|
[providers.ecs]
|
|
|
|
clusters = ["default"]
|
|
|
|
# ...
|
|
|
|
```
|
|
|
|
|
2020-07-28 08:44:05 +00:00
|
|
|
```bash tab="CLI"
|
|
|
|
--providers.ecs.clusters=default
|
|
|
|
# ...
|
|
|
|
```
|
|
|
|
|
2020-07-15 14:28:04 +00:00
|
|
|
### `exposedByDefault`
|
|
|
|
|
|
|
|
_Optional, Default=true_
|
|
|
|
|
2021-02-11 18:04:03 +00:00
|
|
|
Expose ECS services by default in Traefik.
|
|
|
|
|
|
|
|
If set to `false`, services that do not have a `traefik.enable=true` label are ignored from the resulting routing configuration.
|
|
|
|
|
2020-07-15 14:28:04 +00:00
|
|
|
```yaml tab="File (YAML)"
|
|
|
|
providers:
|
|
|
|
ecs:
|
|
|
|
exposedByDefault: false
|
|
|
|
# ...
|
|
|
|
```
|
|
|
|
|
2021-06-18 22:08:08 +00:00
|
|
|
```toml tab="File (TOML)"
|
|
|
|
[providers.ecs]
|
|
|
|
exposedByDefault = false
|
|
|
|
# ...
|
|
|
|
```
|
|
|
|
|
2020-07-15 14:28:04 +00:00
|
|
|
```bash tab="CLI"
|
|
|
|
--providers.ecs.exposedByDefault=false
|
|
|
|
# ...
|
|
|
|
```
|
|
|
|
|
2022-09-20 13:42:08 +00:00
|
|
|
### `healthyTasksOnly`
|
|
|
|
|
|
|
|
_Optional, Default=false_
|
|
|
|
|
|
|
|
Determines whether Traefik discovers only healthy tasks (`HEALTHY` healthStatus).
|
|
|
|
|
|
|
|
```yaml tab="File (YAML)"
|
|
|
|
providers:
|
|
|
|
ecs:
|
|
|
|
healthyTasksOnly: true
|
|
|
|
# ...
|
|
|
|
```
|
|
|
|
|
|
|
|
```toml tab="File (TOML)"
|
|
|
|
[providers.ecs]
|
|
|
|
healthyTasksOnly = true
|
|
|
|
# ...
|
|
|
|
```
|
|
|
|
|
|
|
|
```bash tab="CLI"
|
|
|
|
--providers.ecs.healthyTasksOnly=true
|
|
|
|
# ...
|
|
|
|
```
|
|
|
|
|
2020-07-15 14:28:04 +00:00
|
|
|
### `defaultRule`
|
|
|
|
|
|
|
|
_Optional, Default=```Host(`{{ normalize .Name }}`)```_
|
|
|
|
|
2021-02-11 18:04:03 +00:00
|
|
|
The `defaultRule` option defines what routing rule to apply to a container if no rule is defined by a label.
|
|
|
|
|
2021-09-10 09:42:07 +00:00
|
|
|
It must be a valid [Go template](https://pkg.go.dev/text/template/), and can use
|
2021-08-31 16:54:06 +00:00
|
|
|
[sprig template functions](https://masterminds.github.io/sprig/).
|
2021-02-11 18:04:03 +00:00
|
|
|
The container service name can be accessed with the `Name` identifier,
|
|
|
|
and the template has access to all the labels defined on this container.
|
|
|
|
|
2020-07-15 14:28:04 +00:00
|
|
|
```yaml tab="File (YAML)"
|
|
|
|
providers:
|
|
|
|
ecs:
|
|
|
|
defaultRule: "Host(`{{ .Name }}.{{ index .Labels \"customLabel\"}}`)"
|
|
|
|
# ...
|
|
|
|
```
|
|
|
|
|
2021-06-18 22:08:08 +00:00
|
|
|
```toml tab="File (TOML)"
|
|
|
|
[providers.ecs]
|
|
|
|
defaultRule = "Host(`{{ .Name }}.{{ index .Labels \"customLabel\"}}`)"
|
|
|
|
# ...
|
|
|
|
```
|
|
|
|
|
2020-07-15 14:28:04 +00:00
|
|
|
```bash tab="CLI"
|
|
|
|
--providers.ecs.defaultRule=Host(`{{ .Name }}.{{ index .Labels \"customLabel\"}}`)
|
|
|
|
# ...
|
|
|
|
```
|
|
|
|
|
|
|
|
### `refreshSeconds`
|
|
|
|
|
|
|
|
_Optional, Default=15_
|
|
|
|
|
2021-02-11 18:04:03 +00:00
|
|
|
Polling interval (in seconds).
|
|
|
|
|
2020-07-15 14:28:04 +00:00
|
|
|
```yaml tab="File (YAML)"
|
|
|
|
providers:
|
|
|
|
ecs:
|
|
|
|
refreshSeconds: 15
|
|
|
|
# ...
|
|
|
|
```
|
|
|
|
|
2021-06-18 22:08:08 +00:00
|
|
|
```toml tab="File (TOML)"
|
|
|
|
[providers.ecs]
|
|
|
|
refreshSeconds = 15
|
|
|
|
# ...
|
|
|
|
```
|
|
|
|
|
2020-07-15 14:28:04 +00:00
|
|
|
```bash tab="CLI"
|
|
|
|
--providers.ecs.refreshSeconds=15
|
|
|
|
# ...
|
|
|
|
```
|
|
|
|
|
|
|
|
### Credentials
|
|
|
|
|
|
|
|
_Optional_
|
|
|
|
|
2021-02-11 18:04:03 +00:00
|
|
|
If `region` is not provided, it is resolved from the EC2 metadata endpoint for EC2 tasks.
|
|
|
|
In a FARGATE context it is resolved from the `AWS_REGION` environment variable.
|
|
|
|
|
|
|
|
If `accessKeyID` and `secretAccessKey` are not provided, credentials are resolved in the following order:
|
|
|
|
|
|
|
|
- Using the environment variables `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY`, and `AWS_SESSION_TOKEN`.
|
|
|
|
- Using shared credentials, determined by `AWS_PROFILE` and `AWS_SHARED_CREDENTIALS_FILE`, defaults to `default` and `~/.aws/credentials`.
|
|
|
|
- Using EC2 instance role or ECS task role
|
|
|
|
|
2020-07-15 14:28:04 +00:00
|
|
|
```yaml tab="File (YAML)"
|
|
|
|
providers:
|
|
|
|
ecs:
|
|
|
|
region: us-east-1
|
|
|
|
accessKeyID: "abc"
|
|
|
|
secretAccessKey: "123"
|
|
|
|
# ...
|
|
|
|
```
|
|
|
|
|
2021-06-18 22:08:08 +00:00
|
|
|
```toml tab="File (TOML)"
|
|
|
|
[providers.ecs]
|
|
|
|
region = "us-east-1"
|
|
|
|
accessKeyID = "abc"
|
|
|
|
secretAccessKey = "123"
|
|
|
|
```
|
|
|
|
|
2020-07-15 14:28:04 +00:00
|
|
|
```bash tab="CLI"
|
|
|
|
--providers.ecs.region="us-east-1"
|
|
|
|
--providers.ecs.accessKeyID="abc"
|
|
|
|
--providers.ecs.secretAccessKey="123"
|
|
|
|
# ...
|
|
|
|
```
|