Exposing long-running tasks with ECS – Running Containers in AWS
- Blog
- Exposing long-running tasks with ECS – Running Containers in AWS
Often, you will want to have long-running versions of your tasks. This is a common use case for web applications. ECS has a scheduler component that monitors your running tasks and reschedules them automatically when they fail.
ECS also allows you to configure placement strategies and constraints if you like to customize how the scheduler places and terminates a task.
ECS launch types to support different ownership models
Depending on the level of control that you want on the underlying infrastructure that hosts your application containers, you can configure specific launch types with ECS. They come in two flavors:
Tip
From a security standpoint, it’s important to keep your EC2 nodes updated (when not using the Fargate launch type) with recent patch upgrades. AWS makes this information available as an SSM parameter in your account:
aws ssm get-parameters –names /aws/service/ecs/optimized-ami/ amazon-linux-2/recommended –region eu-central-1
Having covered the primary constructs in ECS, let’s also discuss some security best practices that will help you ensure a good cloud posture for your organization.
Ensuring a good security posture with ECS
Security guardrails can have multiple dimensions. AWS offers services that cater to most of these needs – be they Route53 DNS, firewall, network packet inspection through a network firewall, network access control lists for subnets, or security groups for managing traffic at the interface level. In the context of ECS (and containers in general), let’s discuss some low-hanging fruits that can provide big security benefits.
Locking down permissions with IAM roles
IAM is what defines everything around authentication and authorization in AWS. ECS is no different. The service allows you to define and map IAM roles at the ECS agent level, as well as the application task level. They are known as ECS Task Execution Roleand ECS Task Role. The ECS task agent will typically require access to the ECR registry, SSM parameters, and CloudWatch logs. In addition to this, you can restrict the permissions for the application running inside the ECS container. When the application container bootstraps, ECS ensures that dynamic credentials are injected into it. This helps you avoid having to manage long-term static security credentials, which can be a security risk.
© Copyright 2024 morningfun.org