Skip to main content

Cloudlift makes it easier to launch dockerized services in AWS ECS

Project description

Cloudlift

Cloudlift is built by Simpl developers to make it easier to launch dockerized services in AWS ECS.

Cloudlift is a command-line tool for dockerized services to be deployed in AWS ECS. It's very simple to use. That's possible because this is heavily opinionated. Under the hood, it is a wrapper to AWS cloudformation templates. On creating/updating a service or a cluster this creates/updates a cloudformation in AWS.

Demo videos

Installing cloudlift

1. Pre-requisites

  • pip
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py | python get-pip.py

2. Install cloudlift

pip install cloudlift

2. Configure AWS

aws configure

Enter the AWS Access Key ID, AWS Secret Access Key. You can find instructions here on how to get Access Key ID and Secret Access Key here at http://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_access-keys.html

Using AWS Profiles

If you are using AWS profiles, set the desired profile name in the environment before invoking Cloudlift.

AWS_DEFAULT_PROFILE=<profile name> cloudlift <command>

OR

export AWS_DEFAULT_PROFILE=<profile name>
cloudlift <command>
cloudlift <command>

Usage

Create a new environment

Create a new environment for services to be deployed. Cloudlift creates a new VPC for the given CIDR and sets up the required networking infrastructure for services to run in ECS.

cloudlift create_environment -e <environment-name>

This starts a prompt for required details to create an environment, which includes -

  • AWS region for the environment
  • VPC CIDR
  • NAT Elastic IP allocation ID
  • 2 Public Subnet CIDRs
  • 2 Private Subnet CIDRs
  • Minimum instances for cluster
  • Maximum instances for cluster
  • SSH key name
  • SNS ARN for notifications
  • AWS ACM ARN for SSL certificate

Once the configuration is saved, this is opened in the default VISUAL editor. Here configurations can be changed if required.

Update an environment

cloudlift update_environment -e <environment-name>

This opens the environment configuration in the VISUAL editor. Update this to make changes to the environment.

Create a new service

1. Upload configuration to Parameter Store

During create_service and deployment cloudlift pulls the config from AWS Parameter Store to apply it on the task definition. Configurations are stored in path with the convention /<environment>/<service>/<key>

cloudlift edit_config -e <environment-name>

NOTE: This is not required for every deployment. It's required only when config needs to be changed.

2. Create service

In the repository for the application, run -

  cloudlift create_service -e <environment-name>

This opens the VISUAL editor with default config similar to -

  {
      "services": {
          "Test123": {
              "command": null,
              "custom_metrics": {
                  "metrics_port": "8005",
                  "metrics_path": "/metrics"
              },
              "http_interface": {
                  "container_port": 80,
                  "internal": false,
                  "restrict_access_to": [
                      "0.0.0.0/0"
                  ]
              },
              "memory_reservation": 100
          }
      }
  }

Definitions -

services: Map of all ECS services with configuration for current application

command: Override command in Dockerfile

custom_metrics: Configuration for custom metrics if required, do not include this if the service does not write/export custom metrics

NOTE: If you use custom metrics, Your ECS container Network mode will be awsvpc.

⚠ WARNING: If you are adding custom metrics to your existing service, there will be a downtime.

http_interface: Configuration for HTTP interface if required, do not include this if the services does not require a HTTP interface

container_port: Port in which the process is exposed inside container

internal: Scheme of loadbalancer. If internal, the loadbalancer is accessible only within the VPC

restrict_access_to: List of CIDR to which HTTP interface is restricted to.

memory_reservation: Memory size reserved for each task in MBs. This is a soft limit, i.e. at least this much memory will be available, and upto whatever memory is free in running container instance. Minimum: 10 MB, Maximum: 8000 MB

volume: Configuration for EFS volume mount if required, do not include this if the service does not required volume mount

Examples:

  1. Service configuration with custom metrics:
  {
      "services": {
          "Test123": {
              "command": null,
              "custom_metrics": {
                  "metrics_port": "8005",
                  "metrics_path": "/metrics"
              },
              "http_interface": {
                  "container_port": 80,
                  "internal": false,
                  "restrict_access_to": [
                      "0.0.0.0/0"
                  ]
              },
              "memory_reservation": 100
          }
      }
  }
  1. Service configuration with volume mount:
  {
      "services": {
          "Test123": {
              "command": null,
              "volume": {
                  "efs_id" : "fs-XXXXXXX",
                  "efs_directory_path" : "/",
                  "container_path" : "/"
              },
              "http_interface": {
                  "container_port": 80,
                  "internal": false,
                  "restrict_access_to": [
                      "0.0.0.0/0"
                  ]
              },
              "memory_reservation": 100
          }
      }
  }
  1. Service configuration with http interface only:
  {
      "services": {
          "Test123": {
              "command": null,
              "http_interface": {
                  "container_port": 80,
                  "internal": false,
                  "restrict_access_to": [
                      "0.0.0.0/0"
                  ]
              },
              "memory_reservation": 100
          }
      }
  }

3. Deploy service

This command build the image (only if the version is unavailable in ECR), pushes to ECR and updates the ECS service task definition. It supports --build-arg argument of docker build command as well to pass custom build time arguments

  cloudlift deploy_service -e <environment-name>

For example, you can pass your SSH key as a build argument to docker build

  cloudlift deploy_service --build-arg SSH_KEY "\"`cat ~/.ssh/id_rsa`\"" -e <environment-name>

This example is bit comprehensive to show

  • it can execute shell commands with "`".
  • It's wrapped with double quotes to avoid line-breaks in SSH keys breaking the command.

6. Starting shell on container instance for service

You can start a shell on a container instance which is running a task for given application using the start_session command. One pre-requisite for this is installing the session manager plugin for awscli. To install session manager plugin follow the guide

  cloudlift start_session -e <environment-name>

MFA code can be passed as parameter --mfa or you will be prompted to enter the MFA code.

Contributing to cloudlift

Setup

Use the latest git master

git clone git@github.com:GetSimpl/cloudlift.git
cd cloudlift
./install-cloudlift.sh

To ensure the tests use the development version and not the installed version run (refer here)

pip install -e .

Tests

First level of tests have been added to assert cloudformation template generated vs expected one.

py.test test/deployment/

To run high level integration tests

pytest -s test/test_cloudlift.py

This tests expects to have an access to AWS console. Since there's no extensive test coverage, it's better to manually test the impacted areas whenever there's a code change.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cloudlift-1.5.0.tar.gz (41.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cloudlift-1.5.0-py3-none-any.whl (52.4 kB view details)

Uploaded Python 3

File details

Details for the file cloudlift-1.5.0.tar.gz.

File metadata

  • Download URL: cloudlift-1.5.0.tar.gz
  • Upload date:
  • Size: 41.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/28.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.54.1 importlib-metadata/4.8.3 keyring/21.5.0 rfc3986/1.4.0 colorama/0.4.3 CPython/3.6.9

File hashes

Hashes for cloudlift-1.5.0.tar.gz
Algorithm Hash digest
SHA256 342ded3ce259c3836aea8e47a2bdbb63d6c3e738e92721937e064b9a8a2b58c1
MD5 6046d101027e59c05ac6c6a260881ed6
BLAKE2b-256 f0f1b7055fac57f5710bc5ca2b21cbfab1f3c935bd8214628519a6b622e1188a

See more details on using hashes here.

File details

Details for the file cloudlift-1.5.0-py3-none-any.whl.

File metadata

  • Download URL: cloudlift-1.5.0-py3-none-any.whl
  • Upload date:
  • Size: 52.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/28.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.54.1 importlib-metadata/4.8.3 keyring/21.5.0 rfc3986/1.4.0 colorama/0.4.3 CPython/3.6.9

File hashes

Hashes for cloudlift-1.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4e3d709147aef070dcdcc83bf2e839b3ffd23dc65adc9b300d52b48636be6eaa
MD5 574c3d2dcbf1a71936e3036f806db42e
BLAKE2b-256 3b10e25dc1a139067be6f8048a206426faf79288d4e2dd48cd343048bd65c641

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page