├── src ├── __init__.py ├── app │ ├── __init__.py │ ├── costs_manager.py │ └── main.py ├── requirements.txt ├── Dockerfile └── docker-compose.yml ├── tests ├── __init__.py ├── unit │ ├── __init__.py │ ├── test_costs_manager.py │ └── test_main.py └── integration │ ├── __init__.py │ └── locustfile.py ├── cdk ├── .npmignore ├── .gitignore ├── jest.config.js ├── cdk.json ├── package.json ├── tsconfig.json ├── bin │ └── cdk.ts └── lib │ └── cdk-stack.ts ├── assets ├── SantiagoGarciaArangoCDK.png ├── aws-cdk-ecs-api-architecture.png └── aws-cdk-ecs-api-architecture.drawio ├── commands_python.sh ├── pyproject.toml ├── commands_cdk.sh ├── .gitignore ├── README.md └── LICENSE /src/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/app/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/unit/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/integration/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/requirements.txt: -------------------------------------------------------------------------------- 1 | fastapi[all] 2 | boto3 3 | -------------------------------------------------------------------------------- /cdk/.npmignore: -------------------------------------------------------------------------------- 1 | *.ts 2 | !*.d.ts 3 | 4 | # CDK asset staging directory 5 | .cdk.staging 6 | cdk.out 7 | -------------------------------------------------------------------------------- /assets/SantiagoGarciaArangoCDK.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/san99tiago/aws-cdk-ecs-api/HEAD/assets/SantiagoGarciaArangoCDK.png -------------------------------------------------------------------------------- /assets/aws-cdk-ecs-api-architecture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/san99tiago/aws-cdk-ecs-api/HEAD/assets/aws-cdk-ecs-api-architecture.png -------------------------------------------------------------------------------- /cdk/.gitignore: -------------------------------------------------------------------------------- 1 | *.js 2 | !jest.config.js 3 | *.d.ts 4 | node_modules 5 | 6 | # CDK asset staging directory 7 | .cdk.staging 8 | cdk.out 9 | -------------------------------------------------------------------------------- /cdk/jest.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | testEnvironment: 'node', 3 | roots: ['/test'], 4 | testMatch: ['**/*.test.ts'], 5 | transform: { 6 | '^.+\\.tsx?$': 'ts-jest' 7 | } 8 | }; 9 | -------------------------------------------------------------------------------- /src/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM python:3.9 2 | 3 | LABEL maintainer="Santiago Garcia Arango [san99tiago]" 4 | 5 | WORKDIR /code 6 | 7 | COPY ./requirements.txt /code/requirements.txt 8 | 9 | RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt 10 | 11 | COPY ./app /code/app 12 | 13 | CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "80"] 14 | -------------------------------------------------------------------------------- /cdk/cdk.json: -------------------------------------------------------------------------------- 1 | { 2 | "app": "npx ts-node --prefer-ts-exts bin/cdk.ts", 3 | "watch": { 4 | "include": ["**"], 5 | "exclude": [ 6 | "README.md", 7 | "cdk*.json", 8 | "**/*.d.ts", 9 | "**/*.js", 10 | "tsconfig.json", 11 | "package*.json", 12 | "yarn.lock", 13 | "node_modules", 14 | "test" 15 | ] 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/docker-compose.yml: -------------------------------------------------------------------------------- 1 | # Run with: 2 | # --> docker-compose up --build 3 | 4 | version: "3.8" 5 | 6 | services: 7 | fastapi: 8 | container_name: fastapi_app 9 | build: . 10 | ports: 11 | - "8080:80" 12 | networks: 13 | - docker_apis_and_apps 14 | 15 | networks: 16 | docker_apis_and_apps: 17 | driver: bridge 18 | name: docker_apis_and_apps 19 | -------------------------------------------------------------------------------- /src/app/costs_manager.py: -------------------------------------------------------------------------------- 1 | import datetime 2 | import boto3 3 | 4 | ce = boto3.client("ce") 5 | 6 | 7 | def get_costs_ongoing_month(): 8 | today = datetime.date.today() 9 | start = today.replace(day=1).strftime("%Y-%m-%d") 10 | end = today.strftime("%Y-%m-%d") 11 | response = ce.get_cost_and_usage( 12 | TimePeriod={ 13 | "Start": start, 14 | "End": end, 15 | }, 16 | Granularity="DAILY", 17 | Metrics=["NetUnblendedCost"], 18 | GroupBy=[{"Type": "DIMENSION", "Key": "LINKED_ACCOUNT"}], 19 | ) 20 | return response["ResultsByTime"] 21 | -------------------------------------------------------------------------------- /cdk/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ecs-api", 3 | "version": "1.0.0", 4 | "bin": { 5 | "cdk": "bin/cdk.js" 6 | }, 7 | "scripts": { 8 | "build": "tsc", 9 | "watch": "tsc -w", 10 | "cdk": "cdk" 11 | }, 12 | "devDependencies": { 13 | "@types/jest": "^27.5.0", 14 | "@types/node": "10.17.27", 15 | "@types/prettier": "2.6.0", 16 | "jest": "^27.5.1", 17 | "ts-jest": "^27.1.4", 18 | "aws-cdk": "2.25.0", 19 | "ts-node": "^10.7.0", 20 | "typescript": "~3.9.7" 21 | }, 22 | "dependencies": { 23 | "aws-cdk-lib": "2.25.0", 24 | "constructs": "^10.0.0", 25 | "source-map-support": "^0.5.21" 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /cdk/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "ES2018", 4 | "module": "commonjs", 5 | "lib": [ 6 | "es2018" 7 | ], 8 | "declaration": true, 9 | "strict": true, 10 | "noImplicitAny": true, 11 | "strictNullChecks": true, 12 | "noImplicitThis": true, 13 | "alwaysStrict": true, 14 | "noUnusedLocals": false, 15 | "noUnusedParameters": false, 16 | "noImplicitReturns": true, 17 | "noFallthroughCasesInSwitch": false, 18 | "inlineSourceMap": true, 19 | "inlineSources": true, 20 | "experimentalDecorators": true, 21 | "strictPropertyInitialization": false, 22 | "typeRoots": [ 23 | "./node_modules/@types" 24 | ] 25 | }, 26 | "exclude": [ 27 | "node_modules", 28 | "cdk.out" 29 | ] 30 | } 31 | -------------------------------------------------------------------------------- /tests/integration/locustfile.py: -------------------------------------------------------------------------------- 1 | # LOAD BALANCER TESTS TO VALIDATE ECS SERVICE SCALING UP AND DOWN THE ECS TASKS 2 | # Usage: 3 | # 1) Install required library for load testing (locust): 4 | # --> "pip install -r requirements.txt" 5 | # 2) Run the Locust app as follows: 6 | # --> "python -m locust" 7 | # 3) Go to Locust Web Portal 8 | # --> http://0.0.0.0:8089 (open local window) 9 | # 4) Run the Locust testing tool with the necessary test requirements 10 | # --> Users, SpawnRate, Host, etc... 11 | # 5) Wait for the magic of the ASG alarms being activated and the ECS services 12 | # updating the total value of tasks based on load 13 | 14 | 15 | from locust import HttpUser, task 16 | 17 | 18 | class ApiConsumerUser(HttpUser): 19 | @task 20 | def default(self): 21 | self.client.get("/") 22 | self.client.get("/status") 23 | -------------------------------------------------------------------------------- /tests/unit/test_costs_manager.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | from src.app.costs_manager import get_costs_ongoing_month 3 | 4 | 5 | def test_get_costs_ongoing_month(mocker): 6 | mocker.patch( 7 | "src.app.costs_manager.ce.get_cost_and_usage", 8 | return_value={ 9 | "ResultsByTime": [ 10 | { 11 | "TimePeriod": {"Start": "2023-05-01", "End": "2023-05-02"}, 12 | "Groups": [ 13 | { 14 | "Keys": ["123456789012"], 15 | "Metrics": { 16 | "NetUnblendedCost": {"Amount": "-1.23", "Unit": "USD"} 17 | }, 18 | } 19 | ], 20 | "Total": {}, 21 | "Estimated": True, 22 | } 23 | ] 24 | }, 25 | ) 26 | costs = get_costs_ongoing_month() 27 | assert len(costs) == 1 28 | assert costs[0]["TimePeriod"]["Start"] == "2023-05-01" 29 | assert costs[0]["Groups"][0]["Keys"][0] == "123456789012" 30 | assert costs[0]["Groups"][0]["Metrics"]["NetUnblendedCost"]["Amount"] == "-1.23" 31 | -------------------------------------------------------------------------------- /src/app/main.py: -------------------------------------------------------------------------------- 1 | # SAMPLE PYTHON FAST-API APP FOR ECS DOCKER IMAGE TESTS 2 | # - Santiago Garcia Arango 3 | # - Fredy Andres Montano 4 | 5 | import os 6 | from fastapi import FastAPI, Response, status 7 | 8 | from .costs_manager import get_costs_ongoing_month 9 | 10 | app = FastAPI( 11 | description="Simple FastAPI to demo AWS integrations", 12 | version="0.1.0", 13 | ) 14 | 15 | os_env_json = {} 16 | for key, value in os.environ.items(): 17 | os_env_json[key] = value 18 | 19 | 20 | @app.get("/") 21 | def get_root() -> dict: 22 | return { 23 | "Message": "Hello from Santi. This is a simple API to return current cost of AWS of the ongoing month", 24 | "OS Details": os_env_json, 25 | } 26 | 27 | 28 | @app.get("/status") 29 | def get_status() -> dict: 30 | return {"Status": "Healthy"} 31 | 32 | 33 | @app.get("/costs", status_code=status.HTTP_200_OK) 34 | def get_costs_month(response: Response) -> dict: 35 | try: 36 | costs = get_costs_ongoing_month() 37 | except Exception as e: 38 | response.status_code = status.HTTP_500_INTERNAL_SERVER_ERROR 39 | return { 40 | "Message": "There was a handled exception in the processing of the request", 41 | "Details": str(e), 42 | } 43 | return { 44 | "Message": "This response corresponds to the monthly costs of this AWS account so far", 45 | "Costs": costs, 46 | } 47 | -------------------------------------------------------------------------------- /cdk/bin/cdk.ts: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | import 'source-map-support/register'; 3 | import * as cdk from 'aws-cdk-lib'; 4 | import { CdkEcsApi } from '../lib/cdk-stack'; 5 | 6 | // Ensure environment variable called "DEPLOYMENT_ENVIRONMENT" is defined 7 | if (process.env.DEPLOYMENT_ENVIRONMENT == undefined) { 8 | console.error("ERROR: you MUST provide as an environment variable"); 9 | process.exit(1); 10 | } 11 | 12 | const DEPLOYMENT_ENVIRONMENT = process.env.DEPLOYMENT_ENVIRONMENT; 13 | const MAIN_RESOURCES_NAME = "ecs-api"; 14 | 15 | 16 | const app = new cdk.App(); 17 | const myCdkStack = new CdkEcsApi( 18 | app, 19 | MAIN_RESOURCES_NAME, 20 | DEPLOYMENT_ENVIRONMENT, 21 | MAIN_RESOURCES_NAME, 22 | { 23 | stackName: `cdk-${MAIN_RESOURCES_NAME}-${DEPLOYMENT_ENVIRONMENT}`, 24 | env: { account: process.env.CDK_DEFAULT_ACCOUNT, region: process.env.CDK_DEFAULT_REGION }, 25 | description: `Stack with the infrastructure for ${MAIN_RESOURCES_NAME} in ${DEPLOYMENT_ENVIRONMENT} environment` 26 | } 27 | ); 28 | 29 | cdk.Tags.of(myCdkStack).add('Environment', DEPLOYMENT_ENVIRONMENT); 30 | cdk.Tags.of(myCdkStack).add('MainResourcesName', MAIN_RESOURCES_NAME); 31 | cdk.Tags.of(myCdkStack).add('RepositoryUrl', 'https://github.com/san99tiago/aws-cdk-ecs-api') 32 | cdk.Tags.of(myCdkStack).add('Source', 'aws-cdk-ecs-api') 33 | cdk.Tags.of(myCdkStack).add('Owner', 'Santiago Garcia Arango - Andres Montano'); 34 | cdk.Tags.of(myCdkStack).add('Usage', 'Simple API deployed on top of Docker container with ECS'); 35 | -------------------------------------------------------------------------------- /commands_python.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | ################################################################################ 4 | # ------------------------------------------------------------------------------ 5 | # | PYTHON COMMANDS (FOR EXPLAINING ITS USAGE) 6 | # ------------------------------------------------------------------------------ 7 | ################################################################################ 8 | 9 | # Install Python 10 | # --> https://www.python.org/downloads/ 11 | 12 | # Verify that Python is installed correctly 13 | python --version 14 | 15 | # Install Poetry for managing Python dependencies 16 | pip install poetry 17 | 18 | # Configure Poetry to create virtual environments in the same folder 19 | poetry config virtualenvs.in-project true 20 | 21 | # Install Python dependencies using Poetry 22 | poetry install 23 | 24 | # Initialize interactive shell with Poetry 25 | poetry shell 26 | 27 | # Add/remove Python main code dependency 28 | poetry add dependency_name 29 | poetry remove dependency_name 30 | 31 | # Add/remove Python specific group dependency (for testing or other purpose) 32 | poetry add dependency_name --group test-unit 33 | poetry remove dependency_name --group test-unit 34 | 35 | # Run poetry tasks for testing the source code (unit/integration tests) 36 | # --> Search inside "pyproject.toml" the poe tasks for details 37 | poe test-unit 38 | poe test-unit-html 39 | poe test-integration-load-manual 40 | poe test-integration-load-auto 41 | 42 | # Finish/Exit the interactive shell with Poetry 43 | deactivate 44 | -------------------------------------------------------------------------------- /tests/unit/test_main.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | from fastapi.testclient import TestClient 3 | from src.app.main import app 4 | 5 | 6 | @pytest.fixture 7 | def client(): 8 | return TestClient(app) 9 | 10 | 11 | def test_get_root(client): 12 | response = client.get("/") 13 | assert response.status_code == 200 14 | assert b"Hello from Santi" in response.content 15 | 16 | 17 | def test_get_status(client): 18 | response = client.get("/status") 19 | assert response.status_code == 200 20 | assert b"Healthy" in response.content 21 | 22 | 23 | def test_get_costs_month_success(client, mocker): 24 | mocker.patch( 25 | "src.app.main.get_costs_ongoing_month", 26 | return_value=[ 27 | { 28 | "TimePeriod": {"Start": "2023-05-01", "End": "2023-05-02"}, 29 | # More fields here... 30 | } 31 | ], 32 | ) 33 | response = client.get("/costs") 34 | assert response.status_code == 200 35 | assert b"This response corresponds to the monthly costs" in response.content 36 | assert b"TimePeriod" in response.content 37 | 38 | 39 | def test_get_costs_month_failure(client, mocker): 40 | mocker.patch( 41 | "src.app.main.get_costs_ongoing_month", side_effect=Exception("Some Exception") 42 | ) 43 | response = client.get("/costs") 44 | assert response.status_code == 500 45 | assert ( 46 | b"There was a handled exception in the processing of the request" 47 | in response.content 48 | ) 49 | assert b"Some Exception" in response.content 50 | -------------------------------------------------------------------------------- /pyproject.toml: -------------------------------------------------------------------------------- 1 | [tool.poetry] 2 | name = "aws-cdk-ecs-api" 3 | version = "0.1.0" 4 | description = "AWS FastAPI CDK deployment on top of ALB and ECS with Docker containers implementing ECS as the orchestration tool for an AWS-managed infrastructure" 5 | authors = ["Santiago Garcia Arango "] 6 | license = "Apache License 2.0" 7 | readme = "README.md" 8 | packages = [{include = "src"}] 9 | 10 | [tool.poetry.dependencies] 11 | python = "^3.9" 12 | fastapi = {extras = ["all"], version = "^0.95.1"} 13 | uvicorn = {extras = ["standard"], version = "^0.22.0"} 14 | boto3 = "^1.26.133" 15 | 16 | [tool.poetry.group.test-unit.dependencies] 17 | pytest-mock = "^3.10.0" 18 | pytest = "^7.3.1" 19 | 20 | [tool.poetry.group.test-integration.dependencies] 21 | locust = "^2.15.1" 22 | 23 | [tool.poetry.group.dev.dependencies] 24 | poethepoet = "^0.20.0" 25 | coverage = "^7.2.5" 26 | 27 | [build-system] 28 | requires = ["poetry-core"] 29 | build-backend = "poetry.core.masonry.api" 30 | 31 | [tool.poe.tasks] 32 | test-unit = "coverage run -m pytest tests/unit" 33 | test-unit-html = "coverage html" 34 | test-integration-load-manual = "locust -f tests/integration/locustfile.py" 35 | test-integration-load-auto = "locust -f tests/integration/locustfile.py --headless --host https://ecs-api.dev.san99tiago.com --users 20 --spawn-rate 1 --run-time 1m --csv=load_test_results" 36 | 37 | [tool.pytest.ini_options] 38 | minversion = "7.0" 39 | addopts = "--junitxml=junit.xml" 40 | testpaths = [ 41 | "tests/unit", 42 | "tests/integration", 43 | ] 44 | 45 | [tool.coverage.run] 46 | branch = true 47 | source = ["src"] 48 | omit = [ 49 | "**/__init__.py" 50 | ] 51 | 52 | [tool.coverage.report] 53 | show_missing = false 54 | exclude_lines =[ 55 | 'pragma: no cover', 56 | 'def __repr__', 57 | 'if __name__ == .__main__.:', 58 | ] 59 | -------------------------------------------------------------------------------- /commands_cdk.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | ################################################################################ 4 | # ------------------------------------------------------------------------------ 5 | # |CDK COMMANDS (FOR EXPLAINING ITS USAGE) 6 | # ------------------------------------------------------------------------------ 7 | ################################################################################ 8 | 9 | 10 | ################################################################################ 11 | # PART 1: Configure NodeJs and CDK libraries 12 | ################################################################################ 13 | 14 | # Install NodeJs 15 | # --> https://nodejs.org/en/download/ 16 | 17 | # Verify that NodeJs/npm is installed correctly 18 | node --version 19 | npm --version 20 | 21 | # Install AWS-CDK (on NodeJs) 22 | sudo npm install -g aws-cdk 23 | 24 | # Verify correct install of AWS-CDK 25 | npm list --global | grep aws-cdk 26 | 27 | 28 | ################################################################################ 29 | # PART 2: Initial Project Setup (Only run these at the beginning) 30 | ################################################################################ 31 | 32 | # Configure AWS credentials (follow steps, or use your preferred method) 33 | aws configure 34 | 35 | # Bootstrap CDK (provision initial resources to work with CDK.. S3, roles, etc) 36 | #! Change "ACCOUNT-NUMBER-1" and "REGION-1" to your needed values 37 | cdk bootstrap aws://ACCOUNT-NUMBER-1/REGION-1 38 | 39 | # Create the CDK project's folder 40 | mkdir cdk 41 | cd cdk || echo "Make sure that the folder exists" 42 | 43 | # Initialize project 44 | cdk init --language python 45 | 46 | # Install Node/TypeScript modules 47 | npm install . 48 | 49 | 50 | ################################################################################ 51 | # PART 3: Main CDK commands (most used) 52 | ################################################################################ 53 | 54 | # Move to "cdk" folder (where the CDK config and deployment files are located) 55 | cd ./cdk || exit 56 | cdk deploy 57 | 58 | # CDK commands 59 | cdk synthesize 60 | cdk diff 61 | cdk deploy 62 | cdk destroy 63 | 64 | 65 | ################################################################################ 66 | # PART 4: Other CDK usefull commands 67 | ################################################################################ 68 | 69 | # Help 70 | cdk --help 71 | cdk command --help 72 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # OWN IGNORES 3 | ################################################################################ 4 | # Temp files 5 | temp.* 6 | .DS_Store 7 | 8 | # Poetry lock file (not all projects ignore it, but for this scenario, better) 9 | poetry.lock 10 | 11 | # CDK context 12 | cdk.context.json 13 | 14 | # Coverage reports 15 | junit.xml 16 | 17 | # Load test files (CSV files of load testing) 18 | load_test_results*.csv 19 | 20 | 21 | ################################################################################ 22 | # PYTHON GITIGNORE 23 | # https://github.com/github/gitignore/blob/main/Python.gitignore 24 | ################################################################################ 25 | # Byte-compiled / optimized / DLL files 26 | __pycache__/ 27 | *.py[cod] 28 | *$py.class 29 | 30 | # C extensions 31 | *.so 32 | 33 | # Distribution / packaging 34 | .Python 35 | build/ 36 | develop-eggs/ 37 | dist/ 38 | downloads/ 39 | eggs/ 40 | .eggs/ 41 | # lib/ 42 | lib64/ 43 | parts/ 44 | sdist/ 45 | var/ 46 | wheels/ 47 | share/python-wheels/ 48 | *.egg-info/ 49 | .installed.cfg 50 | *.egg 51 | MANIFEST 52 | 53 | # PyInstaller 54 | # Usually these files are written by a python script from a template 55 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 56 | *.manifest 57 | *.spec 58 | 59 | # Installer logs 60 | pip-log.txt 61 | pip-delete-this-directory.txt 62 | 63 | # Unit test / coverage reports 64 | htmlcov/ 65 | .tox/ 66 | .nox/ 67 | .coverage 68 | .coverage.* 69 | .cache 70 | nosetests.xml 71 | coverage.xml 72 | *.cover 73 | *.py,cover 74 | .hypothesis/ 75 | .pytest_cache/ 76 | cover/ 77 | 78 | # Translations 79 | *.mo 80 | *.pot 81 | 82 | # Django stuff: 83 | *.log 84 | local_settings.py 85 | db.sqlite3 86 | db.sqlite3-journal 87 | 88 | # Flask stuff: 89 | instance/ 90 | .webassets-cache 91 | 92 | # Scrapy stuff: 93 | .scrapy 94 | 95 | # Sphinx documentation 96 | docs/_build/ 97 | 98 | # PyBuilder 99 | .pybuilder/ 100 | target/ 101 | 102 | # Jupyter Notebook 103 | .ipynb_checkpoints 104 | 105 | # IPython 106 | profile_default/ 107 | ipython_config.py 108 | 109 | # pyenv 110 | # For a library or package, you might want to ignore these files since the code is 111 | # intended to run in multiple environments; otherwise, check them in: 112 | # .python-version 113 | 114 | # pipenv 115 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 116 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 117 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 118 | # install all needed dependencies. 119 | #Pipfile.lock 120 | 121 | # poetry 122 | # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. 123 | # This is especially recommended for binary packages to ensure reproducibility, and is more 124 | # commonly ignored for libraries. 125 | # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control 126 | #poetry.lock 127 | 128 | # pdm 129 | # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. 130 | #pdm.lock 131 | # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it 132 | # in version control. 133 | # https://pdm.fming.dev/#use-with-ide 134 | .pdm.toml 135 | 136 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm 137 | __pypackages__/ 138 | 139 | # Celery stuff 140 | celerybeat-schedule 141 | celerybeat.pid 142 | 143 | # SageMath parsed files 144 | *.sage.py 145 | 146 | # Environments 147 | .env 148 | .venv 149 | env/ 150 | venv/ 151 | ENV/ 152 | env.bak/ 153 | venv.bak/ 154 | 155 | # Spyder project settings 156 | .spyderproject 157 | .spyproject 158 | 159 | # Rope project settings 160 | .ropeproject 161 | 162 | # mkdocs documentation 163 | /site 164 | 165 | # mypy 166 | .mypy_cache/ 167 | .dmypy.json 168 | dmypy.json 169 | 170 | # Pyre type checker 171 | .pyre/ 172 | 173 | # pytype static type analyzer 174 | .pytype/ 175 | 176 | # Cython debug symbols 177 | cython_debug/ 178 | 179 | # PyCharm 180 | # JetBrains specific template is maintained in a separate JetBrains.gitignore that can 181 | # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore 182 | # and can be added to the global gitignore or merged into this file. For a more nuclear 183 | # option (not recommended) you can uncomment the following to ignore the entire idea folder. 184 | #.idea/ -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # :trident: AWS-CDK-ECS-API :trident: 2 | 3 | AWS FastAPI CDK deployment on top of ALB and ECS with Docker containers implementing ECS as the orchestration tool for an AWS-managed infrastructure. 4 | 5 | ## Summary/Overview :memo: 6 | 7 | - Deployed on AWS with Infrastructure as Code on [CDK-TypeScript](https://aws.amazon.com/cdk/). 8 | - API developed with [FastAPI](https://fastapi.tiangolo.com/lo/). 9 | - Unit and Integration Tests for the source code with [PyTest](https://docs.pytest.org/en/latest). 10 | - Containerized solution with [Docker](https://www.docker.com) orchestrated by [Amazon ECS](https://aws.amazon.com/ecs/) (Fargate). 11 | - Load Balancing managed with [ELB - Application Load Balancer](https://docs.aws.amazon.com/elasticloadbalancing/latest/application/introduction.html) with listener ECS Service as target group. 12 | - Public DNS records on top of [Route 53](https://aws.amazon.com/route53/) with Certificates on [AWS Certificate Manager](https://aws.amazon.com/certificate-manager/). 13 | 14 | ## AWS Architecture Diagram :trophy: 15 | 16 | The AWS infrastructure solution is deployed with CDK-TypeScript with the resources defined on the `cdk` folder: 17 | 18 |
19 | 20 | ## Folders Explained :scroll: 21 | 22 | This repository consists of multiple folders/files, which are explained as follows: 23 | 24 | - Infrastructure as Code ([`./cdk/`](./cdk/)). 25 | - Source Code ([`./src/app/`](./src/app/)). 26 | - Tests ([`./tests/`](./tests/)) 27 | - Docker containerization ([`./src/Dockerfile`](./src/Dockerfile)). 28 | 29 | ## Usage :white_check_mark: 30 | 31 | Follow these steps to configure the project locally: 32 | 33 | ### Clone the repository 34 | 35 | First, clone the repository: 36 | 37 | ```bash 38 | git clone https://github.com/san99tiago/aws-cdk-ecs-api 39 | cd aws-cdk-ecs-api 40 | ``` 41 | 42 | ### Configure Python 43 | 44 | Review the step by step commands for the source code (Python) development and testing at: 45 | 46 | - [`./commands_python.sh`](./commands_python.sh) 47 | 48 | > Note: python dependencies for this project are managed by [Poetry](https://python-poetry.org). Review [`./pyproject.toml`](pyproject.toml) for details. 49 | 50 | ### Configure CDK 51 | 52 | Review the step by step commands for configuring the CDK at: 53 | 54 | - [`./commands_cdk.sh`](./commands_cdk.sh) 55 | 56 | > Note: for deploying or destroying the solution, see ("part 3") inside [`./commands_cdk.sh`](./commands_cdk.sh). 57 | 58 | ## Dependencies :100: 59 | 60 | ### Software 61 | 62 | - [Visual Studio Code](https://code.visualstudio.com/)
63 | Visual Studio Code is my main code editor for high-level programming. This is not absolutely necessary, but from my experience, it gives us a great performance and we can link it with Git and GitHub easily.
64 | 65 | - [NodeJs](https://nodejs.org/en/)
66 | NodeJs is a JavaScript runtime built on Chrome's V8 JavaScript engine programming language. The community is amazing and lets us handle async functionalities in elegant ways.
67 | 68 | - [Python](https://www.python.org/)
69 | Python is an amazing dynamic programming language that let us work fast, with easy and powerful integration of different software solutions.
70 | 71 | ### Tools 72 | 73 | - [CDK CLI (Toolkit)](https://docs.aws.amazon.com/cdk/v2/guide/cli.html)
74 | To work with the CDK, it is important to install the main toolkit as a NodeJs global dependency. Please refer to the official AWS [Getting started with the AWS CDK](https://docs.aws.amazon.com/cdk/v2/guide/getting_started.html)
75 | 76 | - [AWS CLI](https://aws.amazon.com/cli/)
77 | The AWS Command Line Interface (AWS CLI) is a unified tool to manage your AWS services. We will use it for connecting to our AWS account from the terminal (authentication and authorization towards AWS).
78 | 79 | ## Special thanks :beers: 80 | 81 | - I am grateful to the talented individuals who have dedicated their time and effort to develop the exceptional open-source projects that have been used in the creation of this solution.
82 | 83 | ## Author :musical_keyboard: 84 | 85 | **Santiago Garcia Arango** 86 | 87 | 88 | 89 | 92 | 96 | 97 |
90 |

91 |
93 |

As a curious DevOps Engineer, I am deeply passionate about implementing cutting-edge cloud-based solutions on AWS.
I firmly believe that today's greatest challenges must be solved by the expertise of individuals who are truly passionate about their work. 94 |

95 |
98 | 99 | ## LICENSE 100 | 101 | Copyright 2023 Santiago Garcia Arango 102 | -------------------------------------------------------------------------------- /cdk/lib/cdk-stack.ts: -------------------------------------------------------------------------------- 1 | import { CfnOutput, Stack, StackProps } from 'aws-cdk-lib'; 2 | import { Construct } from 'constructs'; 3 | import * as iam from 'aws-cdk-lib/aws-iam'; 4 | import * as ssm from 'aws-cdk-lib/aws-ssm'; 5 | import * as ec2 from 'aws-cdk-lib/aws-ec2'; 6 | import * as ecs from 'aws-cdk-lib/aws-ecs'; 7 | import * as route53 from 'aws-cdk-lib/aws-route53'; 8 | import * as route53targets from 'aws-cdk-lib/aws-route53-targets'; 9 | import * as elasticloadbalancing from 'aws-cdk-lib/aws-elasticloadbalancingv2' 10 | import * as acm from 'aws-cdk-lib/aws-certificatemanager'; 11 | import * as cloudwatch from 'aws-cdk-lib/aws-cloudwatch'; 12 | 13 | 14 | export class CdkEcsApi extends Stack { 15 | constructor( 16 | scope: Construct, 17 | id: string, 18 | deploymentEnvironment: string, 19 | mainResourcesName: string, 20 | props?: StackProps 21 | ) { 22 | super(scope, id, props); 23 | 24 | // Main variables based on environment variables and fixed values 25 | const ecsClusterName = deploymentEnvironment == 'prod' ? mainResourcesName : `${deploymentEnvironment}-${mainResourcesName}`; 26 | const hostedZoneName = deploymentEnvironment == 'prod' ? "san99tiago.com" : `${deploymentEnvironment}.san99tiago.com`; // Example: "availia.io" 27 | const domainName = `ecs-api.${hostedZoneName}`; 28 | const applicationPort = 80; 29 | 30 | // Obtain extra IDs/variables from SSM Parameters 31 | const vpcId = ssm.StringParameter.valueFromLookup(this, `/${mainResourcesName}/${deploymentEnvironment}/vpc-id`); 32 | 33 | // TODO: uncomment if ALB already exists, otherwise, it's created bellow 34 | // const loadBalancerArn = ssm.StringParameter.valueFromLookup(this, `/${mainResourcesName}/${deploymentEnvironment}/alb-arn`);; 35 | 36 | // Obtain resource from existing VPC 37 | const vpc = ec2.Vpc.fromLookup(this, "VPC", { 38 | region: 'us-east-1', 39 | vpcId: vpcId, 40 | }); 41 | 42 | // Obtain account R53 Hosted Zone for specific domain (previously created in account) 43 | const hostedZone = route53.HostedZone.fromLookup(this, 'HostedZone', { 44 | domainName: hostedZoneName 45 | }); 46 | 47 | // Add SSL certificate 48 | // ! IMPORTANT: this is currently automatic, but if the R53 Hosted Zone is 49 | // ! ... in another account, this has to be done manually by DNS validation 50 | const certificate = new acm.DnsValidatedCertificate(this, 'Certificate', { 51 | domainName: domainName, 52 | hostedZone: hostedZone, 53 | subjectAlternativeNames: [`www.${domainName}`], // To also allow the common 'www' prefix 54 | region: 'us-east-1', 55 | }); 56 | certificate.metricDaysToExpiry().createAlarm(this, 'AlarmCertificateExpiration', { 57 | comparisonOperator: cloudwatch.ComparisonOperator.LESS_THAN_THRESHOLD, 58 | evaluationPeriods: 1, 59 | threshold: 45, // Automatic rotation happens between 60 and 45 days before expiry 60 | }); 61 | 62 | // TODO: uncomment if ALB already exists, otherwise, it's created bellow 63 | // // Get Application load balancer (ALB) resource (previously created in account) 64 | // const alb = elasticloadbalancing.ApplicationLoadBalancer.fromLookup(this, 'ALB', { 65 | // loadBalancerArn: loadBalancerArn 66 | // }); 67 | 68 | // Create Application load balancer (ALB) resource (previously created in account) 69 | const alb = new elasticloadbalancing.ApplicationLoadBalancer(this, 'ALB', { 70 | vpc: vpc, 71 | vpcSubnets: { subnets: vpc.publicSubnets }, 72 | internetFacing: true, 73 | }); 74 | 75 | // ALB Security Group to provide a secure connection to the ALB on 443 76 | const albSG = new ec2.SecurityGroup(this, "SG-ALB", { 77 | vpc: vpc, 78 | allowAllOutbound: true, 79 | }); 80 | 81 | albSG.addIngressRule( 82 | ec2.Peer.anyIpv4(), 83 | ec2.Port.tcp(443), 84 | "Allow HTTPS traffic" 85 | ); 86 | 87 | alb.connections.addSecurityGroup(albSG); 88 | 89 | // Create ECS Cluster for service/tasks deployments 90 | const cluster = new ecs.Cluster(this, "ECS-Cluster", { 91 | clusterName: ecsClusterName, 92 | vpc: vpc, 93 | }); 94 | 95 | // Role assumed by the task and its containers 96 | const taskRole = new iam.Role(this, "ECS-TaskRole", { 97 | assumedBy: new iam.ServicePrincipal("ecs-tasks.amazonaws.com"), 98 | description: "Role that the task definitions will use to run the code", 99 | }); 100 | 101 | // TODO: Update role based on Containers needs (e.g. cost-explorer actions) 102 | taskRole.attachInlinePolicy( 103 | new iam.Policy(this, "ECS-TaskPolicy", { 104 | statements: [ 105 | new iam.PolicyStatement({ 106 | effect: iam.Effect.ALLOW, 107 | actions: ["ce:GetCostAndUsage", "ce:GetDimensionValues"], 108 | resources: ["*"], 109 | }), 110 | ], 111 | }) 112 | ); 113 | 114 | // Task definition for ECS container 115 | const taskDefinition = new ecs.TaskDefinition(this, "ECS-TaskDefinition", { 116 | family: `${mainResourcesName}-task`, 117 | compatibility: ecs.Compatibility.EC2_AND_FARGATE, 118 | cpu: "256", 119 | memoryMiB: "512", 120 | networkMode: ecs.NetworkMode.AWS_VPC, 121 | taskRole: taskRole, 122 | }); 123 | 124 | // The Docker container for the task definition 125 | const container = taskDefinition.addContainer("ECS-Container", { 126 | image: ecs.ContainerImage.fromAsset("../src/"), // build and upload an image directly from a Dockerfile in "src" directory. 127 | memoryLimitMiB: 512, 128 | environment: { 129 | EXAMPLE_KEY: "EXAMPLE_VALUE", 130 | OWNERS: "SantiagoGarcia_AndresMontano", 131 | ENVIRONMENT: deploymentEnvironment, 132 | }, 133 | // Store logs in CloudWatch Logs 134 | logging: ecs.LogDriver.awsLogs({ streamPrefix: mainResourcesName }), 135 | }); 136 | 137 | // Docker container port mappings within the container 138 | container.addPortMappings( 139 | { 140 | containerPort: applicationPort 141 | } 142 | ); 143 | 144 | // Security groups to allow connections from the application load balancer to the containers 145 | const ecsSG = new ec2.SecurityGroup(this, "SG-ECS", { 146 | vpc: vpc, 147 | allowAllOutbound: true, 148 | }); 149 | ecsSG.connections.allowFrom( 150 | albSG, 151 | ec2.Port.tcp(applicationPort), 152 | "ALB to ECS containers" 153 | ); 154 | 155 | // The ECS Service used for deploying tasks 156 | const service = new ecs.FargateService(this, "ECS-Service", { 157 | cluster, 158 | desiredCount: 1, 159 | taskDefinition, 160 | securityGroups: [ecsSG], 161 | assignPublicIp: true, 162 | }); 163 | 164 | // Target group to make resources containers discoverable by the ALB 165 | const targetGroupHttp = new elasticloadbalancing.ApplicationTargetGroup( 166 | this, 167 | "ALB-TargetGroup", 168 | { 169 | port: applicationPort, 170 | vpc: vpc, 171 | protocol: elasticloadbalancing.ApplicationProtocol.HTTP, 172 | targetType: elasticloadbalancing.TargetType.IP, 173 | } 174 | ); 175 | 176 | // Health check for containers to check they were deployed correctly 177 | targetGroupHttp.configureHealthCheck({ 178 | path: "/status", 179 | protocol: elasticloadbalancing.Protocol.HTTP, 180 | }); 181 | 182 | // Only allow HTTPS connections 183 | const listener = alb.addListener("ALB-Listener", { 184 | open: true, 185 | port: 443, 186 | certificates: [certificate], 187 | }); 188 | 189 | listener.addTargetGroups("ALB-Listener-TargetGroup", { 190 | targetGroups: [targetGroupHttp], 191 | }); 192 | 193 | // Add the ECS service to the target group of the ALB 194 | service.attachToApplicationTargetGroup(targetGroupHttp); 195 | 196 | // ASG automatic configuration based on memory and CPU usage 197 | const scalableTaget = service.autoScaleTaskCount({ 198 | minCapacity: 1, 199 | maxCapacity: 2, 200 | }); 201 | 202 | scalableTaget.scaleOnMemoryUtilization("ECS-ScaleUpMem", { 203 | targetUtilizationPercent: 70, 204 | }); 205 | 206 | scalableTaget.scaleOnCpuUtilization("ECS-ScaleUpCPU", { 207 | targetUtilizationPercent: 70, 208 | }); 209 | 210 | // After ALB is configured, add an "A Record" in the R53 HZ for the domain 211 | const hostedZoneARecod = new route53.ARecord(this, 'ARecord', { 212 | comment: `A type Record target for ${mainResourcesName} solution in ${deploymentEnvironment} env`, 213 | target: route53.RecordTarget.fromAlias(new route53targets.LoadBalancerTarget(alb)), 214 | recordName: domainName, 215 | zone: hostedZone, 216 | }); 217 | 218 | // CloudFormation outputs for the deployment 219 | new CfnOutput(this, 'AlbDns', { 220 | value: alb.loadBalancerDnsName, 221 | description: 'API ALB DNS', 222 | }); 223 | 224 | new CfnOutput(this, 'MainDns', { 225 | value: domainName, 226 | description: 'API public DNS', 227 | }); 228 | 229 | } 230 | } 231 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /assets/aws-cdk-ecs-api-architecture.drawio: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | --------------------------------------------------------------------------------