Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ECS task definition cpu/memory #3267

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions moto/ecs/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1076,16 +1076,21 @@ def run_task(

@staticmethod
def _calculate_task_resource_requirements(task_definition):
resource_requirements = {"CPU": 0, "MEMORY": 0, "PORTS": [], "PORTS_UDP": []}
resource_requirements = {
"CPU": int(task_definition.cpu or "0"),
"MEMORY": int(task_definition.memory or "0"),
"PORTS": [],
"PORTS_UDP": [],
}
for container_definition in task_definition.container_definitions:
# cloudformation uses capitalized properties, while boto uses all lower case

# CPU is optional
resource_requirements["CPU"] += container_definition.get(
"cpu", container_definition.get("Cpu", 0)
"cpu", container_definition.get("Cpu", 0) or 0
)

# either memory or memory reservation must be provided
# either memory or memory reservation must be provided if not on the task level
if (
"Memory" in container_definition
or "MemoryReservation" in container_definition
Expand All @@ -1094,9 +1099,13 @@ def _calculate_task_resource_requirements(task_definition):
"Memory", container_definition.get("MemoryReservation")
)
else:
resource_requirements["MEMORY"] += container_definition.get(
"memory", container_definition.get("memoryReservation")
)
try:
resource_requirements["MEMORY"] += container_definition.get(
"memory", container_definition["memoryReservation"]
)
except KeyError:
if not task_definition.memory:
raise

port_mapping_key = (
"PortMappings"
Expand Down
2 changes: 2 additions & 0 deletions moto/ecs/responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ def delete_cluster(self):
def register_task_definition(self):
family = self._get_param("family")
container_definitions = self._get_param("containerDefinitions")
cpu = self._get_param("cpu")
memory = self._get_param("memory")
volumes = self._get_param("volumes")
tags = self._get_param("tags")
network_mode = self._get_param("networkMode")
Expand Down