Introduction

Amazon ECS provides a highly scalable, high-performance container orchestration service, while CTO.ai offers robust tools for continuous integration and continuous deployment (CI/CD) workflows. In this blog post, we'll explore how to enhance container deployment by integrating Amazon ECS with CTO.ai.

Amazon ECS

Amazon ECS is a fully managed container orchestration service that makes it easy to deploy, manage, and scale containerized applications. It supports Docker containers and allows you to run and scale containerized applications on AWS easily.

Simple CI/CD Workflows

CTO.ai is a platform that simplifies the complexity of CI/CD pipelines, making it more accessible for development teams to automate their software delivery process.


Create Secrets from Settings

  • Back in your CTO.ai dashboard, create your secrets by selecting Settings and Secrets.

Secrets are encrypted environment variables that CTO.ai utilizes within your workflow to build and run your application and deployments.

You will create four secrets:

  • AWS_ACCESS_KEY_ID
  • AWS_SECRET_ACCESS_KEY
  • AWS_ACCOUNT_NUMBER
  • GITHUB_TOKEN
  • To create your AWS SECRET KEY AND ACCESS KEY . Log into your AWS Account, select the Identity and Access Management (IAM) dashboard, create a new user, copy the Access Key ID and Secret access key and paste it in your secret dashboard on CTO.ai.
  • Your AWS ACCOUNT NUMBER can be gotten from your User ID on the top right corner in your AWS Console.

Generate Github Token

Generate your GITHUB_TOKEN from Github by going to Settings → Developer settings → Personal access tokens → Generate new token on your Github profile.

  • Back in your CTO.ai Secrets dashboard create your secret key/value pairs.

Workflow for Setting up Amazon ECS Infrastructure

The following ECS workflow configuration is an example of how to set up the infrastructure using CTO.ai. This configuration uses the sample template in our open-source ECS Fargate workflow here. To build your infrastructure, run the ops build . command.

version: "1"
commands:
  - name: setup-aws-ecs-fargate:0.3.2
    run: ./node_modules/.bin/ts-node /ops/src/setup.ts
    description: "setup an environment"
    env:
      static:
        - STACK_TYPE=aws-ecs-fargate
        - AWS_REGION=us-west-1
        - JSII_DEPRECATED=quiet
      secrets:
        - AWS_ACCESS_KEY_ID
        - AWS_SECRET_ACCESS_KEY
        - AWS_ACCOUNT_NUMBER
      configs:
        - DEV_AWS_ECS_FARGATE_STATE
        - STG_AWS_ECS_FARGATE_STATE
        - PRD_AWS_ECS_FARGATE_STATE
        - DEV_AWS_ECS_FARGATE_CLUSTER_VAULT_ARN
        - STG_AWS_ECS_FARGATE_CLUSTER_VAULT_ARN
        - PRD_AWS_ECS_FARGATE_CLUSTER_VAULT_ARN
        - DEV_AWS_ECS_FARGATE_SERVICE_VAULT_ARN
        - STG_AWS_ECS_FARGATE_SERVICE_VAULT_ARN
        - PRD_AWS_ECS_FARGATE_SERVICE_VAULT_ARN
  ...

This setup script uses AWS ECS Fargate to create a serverless compute engine for containers, making the process of managing containers and applications more efficient.

Triggering Pipelines on Event Changes

Once the infrastructure is set up, developers can set up pipelines in CTO.ai to trigger when specific GitHub events occur. Here's an example: The example below is also from our open-source template you can use for your new or existing applications. Once your infrastructure is built and deployed, you can trigger your CI/CD Pipelines and services by configuring any of the event triggers below in your GitHub repository.

version: "1"
pipelines:
  - name: sample-expressjs-pipeline-aws-ecs-fargate:0.1.2
    description: build a release for deployment
    env:
      static:
        - DEBIAN_FRONTEND=noninteractive
        - ORG=workflows-sh
        - REPO=sample-expressjs-aws-ecs-fargate
        - AWS_REGION=us-west-1
        - STACK_TYPE=aws-ecs-fargate
      secrets:
        - GITHUB_TOKEN
        - AWS_ACCESS_KEY_ID
        - AWS_SECRET_ACCESS_KEY
        - AWS_ACCOUNT_NUMBER
    events:
      - "github:workflows-sh/sample-expressjs-aws-ecs-fargate:pull_request.merged"
      - "github:workflows-sh/sample-expressjs-aws-ecs-fargate:pull_request.opened"
      - "github:workflows-sh/sample-expressjs-aws-ecs-fargate:pull_request.synchronize"
    jobs:
      - name: sample-expressjs-build-job-aws-ecs-fargate
        description: sample-expressjs build step
        packages:
          - git
          - unzip
          - python
        steps:
          - curl https://s3.amazonaws.com/aws-cli/awscli-bundle-1.18.200.zip -o awscli-bundle.zip
          - unzip awscli-bundle.zip && ./awscli-bundle/install -b ~/bin/aws
          - export PATH=~/bin:$PATH
          - aws --version
          - git clone https://oauth2:[email protected]/$ORG/$REPO
          - cd $REPO && ls -asl
          - git fetch && git checkout $REF
          - aws ecr get-login-password --region $AWS_REGION | docker login --username AWS --password-stdin $AWS_ACCOUNT_NUMBER.dkr.ecr.$AWS_REGION.amazonaws.com/$REPO
          - docker build -f Dockerfile -t $AWS_ACCOUNT_NUMBER.dkr.ecr.$AWS_REGION.amazonaws.com/$REPO-$STACK_TYPE:$REF .
          - docker push $AWS_ACCOUNT_NUMBER.dkr.ecr.$AWS_REGION.amazonaws.com/$REPO-$STACK_TYPE:$REF
services:
  - name: sample-expressjs-service-aws-ecs-fargate:0.1.1
    description: A sample expressjs service
    run: node /ops/index.js
    port: [ '8080:8080' ]
    sdk: off
    domain: ""
    env:
      static:
        - PORT=8080
    events:
      - "github:workflows-sh/sample-expressjs-aws-ecs-fargate:pull_request.merged"
      - "github:workflows-sh/sample-expressjs-aws-ecs-fargate:pull_request.opened"
      - "github:workflows-sh/sample-expressjs-aws-ecs-fargate:pull_request.synchronize"
    trigger:
     - build
     - publish
     - start

Pipeline Configuration

  • Version: Indicates the configuration format version.
  • Pipelines: Contains the details of the pipeline setup.

Pipeline Details

  • name: Identifier for the pipeline (sample-expressjs-pipeline-aws-ecs-fargate:0.1.2).
  • description: Describes the pipeline's purpose (building a release for deployment).
  • env: Defines environment variables, including AWS region (AWS_REGION=us-west-1) and stack type (STACK_TYPE=aws-ecs-fargate).
  • secrets: Contains sensitive data like AWS credentials and GitHub token.
  • events: Specifies GitHub events (like pull request actions) that trigger the pipeline.

Jobs in the Pipeline

  • sample-expressjs-build-job-aws-ecs-fargate: A job for building the Express.js application.
  • Involves steps like installing AWS CLI, cloning the repository, and building and pushing a Docker image to Amazon ECR.

Service Configuration

  • services: Defines the services in the pipeline, such as the Express.js service (sample-expressjs-service-aws-ecs-fargate:0.1.1).
  • run: Command to run the service, setting up a Node.js server.
  • port and env: Configure port mappings and environment variables.
  • events and trigger: Outline the GitHub events that trigger the service and actions like build and publish.

CTO.ai workflow container deployment strategy

With the power of Amazon ECS combined with the simplicity of CTO.ai, you can get started today and transform your deployment workflow for unparalleled efficiency and reliability. Click here to speak with a Platform Engineer. and take the first step towards deployment excellence with Amazon ECS and CTO.ai.