0

I have a backend service docker container which I intend to use to run alembic and update the data model in my database (an aurora serverless v1 running postgres). I have built the container and uploaded it to the ECR. The container's dockerfile looks like this:

# Pull base image
FROM --platform=linux/amd64 python:3.10.11-slim-buster

# Set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

WORKDIR /code/

# Install dependencies
COPY ../requirements_backend_service.txt requirements_backend_service.txt
RUN pip3 install -r requirements_backend_service.txt

COPY . /code/

ENV PATH="/code/venv/bin:$PATH"

EXPOSE 8000

I have tested this container locally with docker compose, and have run the alembic update with the following line in the docker-compose.yml:

command: bash -c "alembic upgrade head

Now I'm trying to do the same as a task on ECS. I created the task definition manually, as a test, though eventually I would want to do it via terraform. In the UI, I can choose between an "entrypoint" parameter and a "command" parameter. I have tried entering the above command in several different ways as a "command" parameter, but I keep getting the following error:

CannotStartContainerError: ResourceInitializationError: failed to create new container runtime task: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: exec: "["bash"": executable file not found in $PATH: unknown

The above error was for the following input:

["bash","-c","alembic","upgrade","head"]

But I have also tried these:

"bash","-c","alembic","upgrade","head"
"bash" -c alembic upgrade head" 
"alembic upgrade head" 
 alembic upgrade head

I can't figure out what format the command needs to have to be run as part of the ecs task.

Any help would be much appreciated.

Boris
  • 716
  • 1
  • 4
  • 25

1 Answers1

0

You could run a local instance of your python app, and set the remote aws database in your environment variables, that way you can apply migrations through the local app to your remote database.

Note: update the security group from your database to allow connections outside your VPC.

  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jul 16 '23 at 22:55