Skip to main content

django-ecsmanage

https://github.com/azavea/django-ecsmanage/workflows/CI/badge.svg?branch=develop

A Django app that provides a management command allowing you to run any other management command on an AWS Elastic Container Service (ECS) cluster.

With django-ecsmanage, you can easily run migrations and other one-off tasks on a remote cluster from the command line:

$ django-admin ecsmanage migrate

Table of Contents

Installation

Install from PyPi using pip:

$ pip install django-ecsmanage

Update INSTALLED_APPS in your Django settings to install the app:

INSTALLED_APPS = (
    ...
    'ecsmanage',
)

Configuration

Settings for the management command are kept in a single configuration dictionary in your Django settings named ECSMANAGE_ENVIRONMENTS. Each entry in ECSMANAGE_ENVIRONMENTS should be a key-value pair corresponding to a named environment (like default or production) and a set of AWS resources associated with that environment. For example:

ECSMANAGE_ENVIRONMENTS = {
    'default': {
        'TASK_DEFINITION_NAME': 'StagingAppCLI',
        'CONTAINER_NAME': 'django',
        'CLUSTER_NAME': 'ecsStagingCluster',
        'LAUNCH_TYPE': 'FARGATE',
        'PLATFORM_VERSION': '1.4.0',
        'SECURITY_GROUP_TAGS': {
            'Name': 'sgAppEcsService',
            'Environment': 'Staging',
            'Project': 'ProjectName'
        },
        'SUBNET_TAGS': {
            'Name': 'PrivateSubnet',
            'Environment': 'Staging',
            'Project': 'ProjectName'
        },
        'ASSIGN_PUBLIC_IP': 'DISABLED',
        'AWS_REGION': 'us-east-1',
    },
}

This configuration defines a single environment, named default, with associated AWS ECS resources.

Environments

The key name for an environment can be any string. You can use this name with the --env flag when running the command to run a command on a different environment. Take this ECSMANAGE_ENVIRONMENTS configuration as an example:

ECSMANAGE_ENVIRONMENTS = {
    'default': {
        'TASK_DEFINITION_NAME': 'StagingAppCLI',
        'CLUSTER_NAME': 'ecsStagingCluster',
        'SECURITY_GROUP_TAGS': {
            'Name': 'sgStagingAppEcsService',
        },
        'SUBNET_TAGS': {
            'Name': 'StagingPrivateSubnet',
        },
    },
    'production': {
        'TASK_DEFINITION_NAME': 'ProductionAppCLI',
        'CLUSTER_NAME': 'ecsProductionCluster',
        'SECURITY_GROUP_TAGS': {
            'Name': 'sgProductionAppEcsService',
        },
        'SUBNET_TAGS': {
            'Name': 'ProductionPrivateSubnet',
        },
    },
}

This configuration defines two environments, default and production. Using the above settings, you could run production migrations with the following command:

$ django-admin ecsmanage --env production migrate

If the --env argument is not present, the command will default to the environment named default.

AWS Resources

The following environment configuration keys help the management command locate the appropriate AWS resources for your cluster:

Key

Description

Default

TASK_DEFINITION_NAME

The name of your ECS task definition. The command will automatically retrieve the latest definition.

CONTAINER_NAME

The name of the Django container in your ECS task definition.

django

CLUSTER_NAME

The name of your ECS cluster.

SECURITY_GROUP_TAGS

A dictionary of tags to use to identify a security group for your task.

SUBNET_TAGS

A dictionary of tags to use to identify a subnet for your task.

ASSIGN_PUBLIC_IP

Whether to automatically assign a public IP address to your task. Can be ENABLED or DISABLED.

DISABLED

LAUNCH_TYPE

The ECS launch type for your task.

FARGATE

PLATFORM_VERSION

The Fargate platform version, if LAUNCH_TYPE is FARGATE.

LATEST

AWS_REGION

The AWS region to run your task.

us-east-1

Developing

Local development is managed with Python virtual environments. Make sure that you have Python 3.8+ and pip installed before starting.

Install the development package in a virtual environment:

$ ./scripts/update

Run the tests:

$ ./scripts/test

Metadata

Release files for django-ecsmanage 4.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-ecsmanage 4.0.1
File Size Uploaded
django_ecsmanage-4.0.1.tar.gz 14.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-ecsmanage 4.0.1
File Interpreter ABI Platform
django_ecsmanage-4.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 26.5 kB

Release files / django_ecsmanage-4.0.1.tar.gz

Download URL django_ecsmanage-4.0.1.tar.gz
Size 14.8 kB
Tags Source
SHA-256 checksum
How to use checksums
8ff0019c64cd0f79c5f2e7bfdefb1dd37eb31796ca32c70fe8b73b1dc27bc7d7
BLAKE2b-256 checksum
How to use checksums
7ac4cd85d792e8d0bc8a5113045086ce6aa37d65e297e0ca01304e2366deb944
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.0.0 CPython/3.12.3

Release files / django_ecsmanage-4.0.1-py3-none-any.whl

Download URL django_ecsmanage-4.0.1-py3-none-any.whl
Size 11.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8dab6ffdf5e57ac0fc1dc8c24dcf14286b6a3a4fe644bf2d47c5613e5f20a28e
BLAKE2b-256 checksum
How to use checksums
e90df028128ce0f89ca689a32e84ab79e79360ebc745efe313d6ee505c77d644
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.0.0 CPython/3.12.3

Release history Release notifications | RSS feed

This release

4.0.1 This release

2 release files

3.0.0

2 release files

2.0.1

2 release files

2.0.0

2 release files

1.1.0

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.1.0

2 release files

0.0.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page