Skip to content

nsbno/terraform-aws-ecs-service

Repository files navigation

ECS Service Module

About

This module helps you get up and running with an ECS Service. It sets up your service, and links it with VPCs, load balancers, monitoring, and more.

You can focus on your application, and the module takes care of getting it running 🎉

Examples

The examples folder is the home of example usages of this module. These are the examples you can find there.

Simple

The minimum usage of this module.

On Prem

Run your service directly in an on-prem datacenter using ECS Anywhere.

Autoscaling

A simple service using autoscaling to handle increased load.

Autoscaling with custom metrics

A service using autoscaling to handle increased load based on custom metrics.

Arguments

These are the arguments that can not be expressed by the terraform module

application_container and sidecar_containers

These arguments are where you specify everything ECS needs to know about your container and how to run it.

Both use the same format, but application_container will automatically be set as an essential container, while sidecar_container will not be set as essential.

Name Description Required Default

name

The name of the container, must be unique.

yes

n/a

image

The image (and tag) of the container to run

yes

n/a

command

A command to run on the container

no

null

essential

If the container is essential for the service

no

true if application_container, false otherwise

environment

A map of environment variables

no

Empty map

secrets

A map of secrets

no

Empty map

port

A port to expose from the container.

depends (required for application_container)

null

protocol

The application layer protocol for the exposed port.

depends (required for application_container)

null

health_check

Container health checks. Not to be confused with LB health checks.

no

null

cpu

The number of CPU units reserved for this container.

no

null

memory_hard_limit

The max amount of memory that the specific container can consume.

no

null

memory_soft_limit

A soft memory limit, that ECS will do best effort to follow when memory is lacking for the service.

no

null

extra_options

Configure any other options for container definitions

no

None (Though log_configuration is automatically configured for CloudWatch)

lb_health_check

These are health checks that will be executed by the loadbalancer.

Considerations

Platform differences

The different platforms are quite similar, but some considerations have to be taken.

Fargate

You must make sure that the following arguments are present:

  • lb_listeners

  • private_subnet_ids

  • vpc_id

ECS Anywhere

Please keep the considerations from AWS in mind. Only use ECS Anywhere if it is really neccessary. https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs-anywhere.html#ecs-anywhere-considerations

Main things to note:

  • There is no VPC networking

  • No loadbalancers

Migrating from terraform-aws-ecs-fargate and terraform-aws-ecs-anywhere

A guide is available if you were previously using terraform-aws-ecs-fargate or terraform-aws-ecs-anywhere.