Skip to content

Commit fc931ed

Browse files
authored
ECS Fargate Terraform and CDK docs (#20108)
* ECS Fargate Terraform and CDK docs * Grammatical updates * Fix broken links * Update terraform version source
1 parent b2e2dad commit fc931ed

File tree

1 file changed

+173
-2
lines changed

1 file changed

+173
-2
lines changed

ecs_fargate/README.md

Lines changed: 173 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,89 @@ Lastly, include your other application containers within the `ContainerDefinitio
146146

147147
For more information on CloudFormation templating and syntax, see the [AWS CloudFormation task definition documentation][43].
148148

149+
<!-- xxz tab xxx -->
150+
151+
<!-- xxx tab "CDK" xxx -->
152+
##### Datadog CDK Task Definition
153+
154+
You can use the [Datadog CDK Constructs][72] to configure your ECS Fargate task definition. Use the `DatadogECSFargate` construct to instrument your containers for desired Datadog features. This is supported in TypeScript, JavaScript, Python, and Go.
155+
156+
<!-- partial
157+
{{< site-region region="us,us3,us5,eu,ap1,gov" >}}
158+
Update this construct definition below with your [Datadog API Key][41]. In addition, include the appropriate `DD_SITE` ({{< region-param key="dd_site" code="true" >}}) property if necessary, as this defaults to `datadoghq.com` if you don't set it.
159+
160+
[41]: https://app.datadoghq.com/organization-settings/api-keys
161+
{{< /site-region >}}
162+
partial -->
163+
164+
```typescript
165+
const ecsDatadog = new DatadogECSFargate({
166+
apiKey: <DATADOG_API_KEY>
167+
site: <DATADOG_SITE>
168+
});
169+
```
170+
171+
Then, define your task definition using [`FargateTaskDefinitionProps`][65].
172+
173+
```typescript
174+
const fargateTaskDefinition = ecsDatadog.fargateTaskDefinition(
175+
this,
176+
<TASK_ID>,
177+
<FARGATE_TASK_DEFINITION_PROPS>
178+
);
179+
```
180+
181+
Lastly, include your other application containers by adding your [`ContainerDefinitionOptions`][66].
182+
183+
```typescript
184+
fargateTaskDefinition.addContainer(<CONTAINER_ID>, <CONTAINER_DEFINITION_OPTIONS>);
185+
```
186+
187+
For more information on the `DatadogECSFargate` construct instrumentation and syntax, see the [Datadog ECS Fargate CDK documentation][67].
188+
189+
<!-- xxz tab xxx -->
190+
191+
<!-- xxx tab "Terraform" xxx -->
192+
##### Datadog Terraform Task Definition
193+
194+
You can use the [Datadog ECS Fargate Terraform module][71] to configure your containers for Datadog. This Terraform module wraps the [`aws_ecs_task_definition`][68] resource and automatically instruments your task definition for Datadog. Pass your input arguments into the Datadog ECS Fargate Terraform module in a similiar manner as to the `aws_ecs_task_definition`. Make sure to include your task `family` and `container_definitions`.
195+
196+
<!-- partial
197+
{{< site-region region="us,us3,us5,eu,ap1,gov" >}}
198+
Update this Terraform module below with your [Datadog API Key][41]. As well as include the appropriate `DD_SITE` ({{< region-param key="dd_site" code="true" >}}) environment variable if necessary, as this defaults to `datadoghq.com` if you don't set it.
199+
200+
[41]: https://app.datadoghq.com/organization-settings/api-keys
201+
{{< /site-region >}}
202+
partial -->
203+
204+
```hcl
205+
module "ecs_fargate_task" {
206+
source = "https://registry.terraform.io/modules/DataDog/ecs-datadog/aws/latest"
207+
version = "1.0.0"
208+
209+
# Configure Datadog
210+
dd_api_key = <DATADOG_API_KEY>
211+
dd_site = <DATADOG_SITE>
212+
dd_dogstatsd = {
213+
enabled = true,
214+
}
215+
dd_apm = {
216+
enabled = true,
217+
}
218+
219+
# Configure Task Definition
220+
family = <TASK_FAMILY>
221+
container_definitions = <CONTAINER_DEFINITIONS>
222+
cpu = 256
223+
memory = 512
224+
network_mode = "awsvpc"
225+
requires_compatibilities = ["FARGATE"]
226+
}
227+
```
228+
229+
Lastly, include your other application containers within the `ContainerDefinitions` and deploy through Terraform.
230+
231+
For more information on the Terraform module, see the [Datadog ECS Fargate Terraform documentation][43].
149232

150233
<!-- xxz tab xxx -->
151234

@@ -223,6 +306,41 @@ For more information on CloudFormation templating and syntax, see the [AWS Cloud
223306

224307
<!-- xxz tab xxx -->
225308

309+
<!-- xxx tab "CDK" xxx -->
310+
##### AWS CDK Replica Service
311+
312+
In the CDK code you can reference the `fargateTaskDefinition` resource created in the previous example into the `FargateService` resource being created. After this, specify your `Cluster`, `DesiredCount`, and any other parameters necessary for your application in your replica service.
313+
314+
```typescript
315+
const service = new ecs.FargateService(this, <SERVICE_ID>, {
316+
<CLUSTER>,
317+
fargateTaskDefinition,
318+
desiredCount: 1
319+
});
320+
```
321+
322+
For more information on the CDK ECS service construct and syntax, see the [AWS CDK ECS Service documentation][69].
323+
324+
<!-- xxz tab xxx -->
325+
326+
<!-- xxx tab "Terraform" xxx -->
327+
##### AWS Terraform Replica Service
328+
329+
In the Terraform code you can reference the `aws_ecs_task_definition` resource created in the previous example within the `aws_ecs_service` resource being created. Then, specify your `Cluster`, `DesiredCount`, and any other parameters necessary for your application in your replica service.
330+
331+
```hcl
332+
resource "aws_ecs_service" <SERVICE_ID> {
333+
name = <SERVICE_NAME>
334+
cluster = <CLUSTER_ID>
335+
task_definition = module.ecs_fargate_task.arn
336+
desired_count = 1
337+
}
338+
```
339+
340+
For more information on the Terraform ECS service module and syntax, see the [AWS Terraform ECS service documentation][70].
341+
342+
<!-- xxz tab xxx -->
343+
226344
<!-- xxz tabs xxx -->
227345

228346
To provide your Datadog API key as a secret, see [Using secrets](#using-secrets).
@@ -894,6 +1012,51 @@ partial -->
8941012

8951013
For more information on CloudFormation templating and syntax, see the [AWS CloudFormation documentation][43].
8961014

1015+
<!-- xxz tab xxx -->
1016+
1017+
<!-- xxx tab "CDK" xxx -->
1018+
##### Datadog ECS Fargate CDK Construct
1019+
1020+
To enable logging through the [Datadog ECS Fargate CDK][67] construct, configure the `logCollection` property as seen below:
1021+
1022+
```typescript
1023+
const ecsDatadog = new DatadogECSFargate({
1024+
apiKey: <DATADOG_API_KEY>,
1025+
site: <DATADOG_SITE>,
1026+
logCollection: {
1027+
isEnabled: true,
1028+
}
1029+
});
1030+
```
1031+
1032+
<!-- xxz tab xxx -->
1033+
1034+
<!-- xxx tab "Terraform" xxx -->
1035+
##### Datadog ECS Fargate Terraform Module
1036+
1037+
To enable logging through the [Datadog ECS Fargate Terraform][71] module, configure the `dd_log_collection` input argument as seen below:
1038+
1039+
```hcl
1040+
module "ecs_fargate_task" {
1041+
source = "https://registry.terraform.io/modules/DataDog/ecs-datadog/aws/latest"
1042+
version = "1.0.0"
1043+
1044+
# Configure Datadog
1045+
dd_api_key = <DATADOG_API_KEY>
1046+
dd_site = <DATADOG_SITE>
1047+
dd_log_collection = {
1048+
enabled = true,
1049+
}
1050+
1051+
# Configure Task Definition
1052+
family = <TASK_FAMILY>
1053+
container_definitions = <CONTAINER_DEFINITIONS>
1054+
cpu = 256
1055+
memory = 512
1056+
network_mode = "awsvpc"
1057+
requires_compatibilities = ["FARGATE"]
1058+
}
1059+
```
8971060

8981061
<!-- xxz tab xxx -->
8991062

@@ -1018,7 +1181,7 @@ Need help? Contact [Datadog support][18].
10181181
- Blog post: [Monitor AWS Fargate for Windows containerized apps][40]
10191182
- Blog post: [Monitor processes running on AWS Fargate with Datadog][58]
10201183
- Blog post: [Monitor AWS Batch on Fargate with Datadog][63]
1021-
- Documentation: [Trace API Gateway when proxying requests to ECS Fargate][65]
1184+
- Documentation: [Trace API Gateway when proxying requests to ECS Fargate][73]
10221185

10231186
[1]: http://docs.datadoghq.com/integrations/eks_fargate
10241187
[2]: https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task-metadata-endpoint.html
@@ -1084,4 +1247,12 @@ Need help? Contact [Datadog support][18].
10841247
[62]: https://docs.datadoghq.com/containers/guide/aws-batch-ecs-fargate
10851248
[63]: https://www.datadoghq.com/blog/monitor-aws-batch-on-fargate/
10861249
[64]: https://docs.datadoghq.com/getting_started/tagging/unified_service_tagging/?tab=ecs#full-configuration
1087-
[65]: https://docs.datadoghq.com/tracing/trace_collection/proxy_setup/apigateway
1250+
[65]: https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_ecs.FargateTaskDefinitionProps.html
1251+
[66]: https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_ecs.ContainerDefinitionOptions.html
1252+
[67]: https://github.com/DataDog/datadog-cdk-constructs/blob/main/src/ecs/fargate/README.md
1253+
[68]: https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ecs_task_definition
1254+
[69]: https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_ecs.FargateService.html
1255+
[70]: https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ecs_service
1256+
[71]: https://registry.terraform.io/modules/DataDog/ecs-datadog/aws/latest
1257+
[72]: https://github.com/datadog/datadog-cdk-constructs/
1258+
[73]: https://docs.datadoghq.com/tracing/trace_collection/proxy_setup/apigateway

0 commit comments

Comments
 (0)