0

I'm trying to port in python an ECS services deployment that at the moment is done with a bunch of bash script containing commands like the following:

ecs-cli compose -f foo.yml -p foo --cluster bar --ecs-params "dir/ecs-params.yml" service up

I thought that the easiest/fastest way could be using boto3 (which I already extensively use elsewhere so It's a safe spot), but I didn't understand from the documentation what would be the instruction equivalent of the formerly written command.

Thanks in advance.

UPDATE: this is the content of foo.yml:

version: '3'
services:
  my-service:
    image: ecr-image:version
    env_file:
      - ./some_envs.env
      - ./more_envs.env
    command: python3 src/main.py param1 param2
    logging:
      driver: awslogs
      options:
        awslogs-group: /my-service-log-group
        awslogs-region: my-region
        awslogs-stream-prefix: my-prefix

UPDATE2: this is the content of dir/ecs-params.yml:

version: 1
task_definition:
  task_role_arn: my-role
  services:
    my-service:
      cpu_shares: my-cpu-shares
      mem_reservation: my-mem-reservation

1 Answer 1

1

The ecs-cli is a high level construct that creates a workflow that wraps many lower level API calls. NOT the same thing but you can think of the ecs-cli compose up command the trigger to deploy what's included in your foo.yml file. Based on what's in your foo.yml file you can walk backwards and try to map to single atomic ECS API calls.

None of this answers your question but, for background, the ecs-cli is no longer what we suggest to use for deploying on ECS. Its evolution is Copilot (if you are not starting from a docker compose story) OR the new docker compose integration with ECS (if docker compose is your jam).

If you want / can post the content of your foo.yml file I can take a stab at how many lower level API calls you'd need to make to do the same (or suggest some other alternatives).

[UPDATE] Based on the content of your two files you could try this one docker compose file:

services:
  my-service:
    image: ecr-image:version
    env_file:
      - ./some_envs.env
      - ./more_envs.env
    x-aws-policies:
      - <my-role>
    deploy:
      resources:
        limits:
          cpus: '0.5'
          memory: 2048M

Some of the ECS params are interpreted off the compose spec (e.g. resource limits). Some other do not have a specific compose-ECS mapping so they are managed through x-aws extensions (e.g. IAM role). Please note that compose only deploy to Fargate so the shares do not make much sense and you'd need to use limits (to pick the right Fargate task size). As a reminder this is an alternative CLI way to deploy the service to ECS but it does not solve for how you translate ALL API calls to boto3.

Sign up to request clarification or add additional context in comments.

4 Comments

Hei @mreferre, I updated the answer. Unfortunately I am using docker compose so apparently Copilot is not a way I can choose to go.
Actually that content should be pretty straightforward to deploy with "native" docker compose. You don't even need all the logging part because that is taken care automatically by the integration (the way the integration works is by taking the compose as input and spitting/applying a CFN template out of that - the CFN templates has everything you need including logging configuration).
And how do you handle the ecs-params.yml file? Could you make an example since I didn't understand how should I do?
Thanks, I definitively learned something new that I'll keep in mind in the future, but unfortunately this doesn't solve my use case since I don't really have the choice on which type on container to run, which is not Fargate.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.