{"id":18573177,"url":"https://github.com/localstack-samples/ecs-code-mounting-python-cdk","last_synced_at":"2026-02-18T19:31:47.814Z","repository":{"id":232599984,"uuid":"784751820","full_name":"localstack-samples/ecs-code-mounting-python-cdk","owner":"localstack-samples","description":"Sample application showcasing how to use the ECS Code Mounting feature with AWS CDK in Python.","archived":false,"fork":false,"pushed_at":"2025-03-09T01:13:49.000Z","size":40624,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-07-30T03:03:20.464Z","etag":null,"topics":["aws","cdk","cdk-python","ecs","ecs-code-mounting","localstack"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/localstack-samples.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2024-04-10T13:39:08.000Z","updated_at":"2025-03-09T01:13:52.000Z","dependencies_parsed_at":"2024-04-10T15:34:58.189Z","dependency_job_id":"f6fcc0ab-dfbf-4514-b27b-47c5acaa2eac","html_url":"https://github.com/localstack-samples/ecs-code-mounting-python-cdk","commit_stats":{"total_commits":8,"total_committers":3,"mean_commits":"2.6666666666666665","dds":0.5,"last_synced_commit":"dd5c49176e46a36a03edb51d623647d8277af316"},"previous_names":["localstack-samples/ecs-code-mounting-python-cdk"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/localstack-samples/ecs-code-mounting-python-cdk","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/localstack-samples%2Fecs-code-mounting-python-cdk","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/localstack-samples%2Fecs-code-mounting-python-cdk/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/localstack-samples%2Fecs-code-mounting-python-cdk/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/localstack-samples%2Fecs-code-mounting-python-cdk/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/localstack-samples","download_url":"https://codeload.github.com/localstack-samples/ecs-code-mounting-python-cdk/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/localstack-samples%2Fecs-code-mounting-python-cdk/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29591914,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-18T18:54:29.675Z","status":"ssl_error","status_checked_at":"2026-02-18T18:50:50.517Z","response_time":162,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aws","cdk","cdk-python","ecs","ecs-code-mounting","localstack"],"created_at":"2024-11-06T23:08:15.922Z","updated_at":"2026-02-18T19:31:47.779Z","avatar_url":"https://github.com/localstack-samples.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ECS Code Mounting with AWS CDK in Python\n\n| Key          | Value                                                                                 |\n| ------------ | ------------------------------------------------------------------------------------- |\n| Environment  | \u003cimg src=\"https://img.shields.io/badge/LocalStack-deploys-4D29B4.svg?logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAAABHNCSVQIC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AAAABJRU5ErkJggg==\"\u003e \u003cimg src=\"https://img.shields.io/badge/AWS-deploys-F29100.svg?logo=amazon\"\u003e                                                                     |\n| Services     | Elastic Container Service, Elastic Container Registry                                 |\n| Integrations | CDK                                                                            |\n| Categories   | Containers                                                  |\n| Level        | Beginner                                                                            |\n| GitHub       | [Repository link](https://github.com/localstack-samples/ecs-code-mounting-python-cdk)   |\n\n## Introduction\n\nThe ECS Code Mounting feature allows you to mount code from your host filesystem into the ECS container. This enables a quick debugging loop where you can test changes without having to build and redeploy the ECS task’s Docker image and push it to ECR each time. Internally, LocalStack uses the [AWS Bind Mounts](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/bind-mounts.html) to implement the ECS Code Mounting feature.\n\nThe sample code in this repository demonstrates how to use the ECS Code Mounting feature with AWS CDK in Python. The ECS task uses a simple Flask application that returns a simple message. The code is mounted from the host filesystem into the ECS container, and the ECS task is deployed to a LocalStack environment.\n\n![image](images/demo.gif)\n\n## Prerequisites\n\n- LocalStack Pro with the [`localstack` CLI](https://docs.localstack.cloud/getting-started/installation/#localstack-cli).\n- [Cloud Development Kit](https://docs.localstack.cloud/user-guide/integrations/aws-cdk/) with the [`cdklocal`](https://www.npmjs.com/package/aws-cdk-local) installed.\n- [Python 3.9+](https://www.python.org/downloads/) \u0026 `pip` package manager.\n- [`virtualenv`](https://pypi.org/project/virtualenv/) for creating isolated Python environments.\n- `cURL` or any other tool to send HTTP requests.\n\nStart LocalStack Pro with the `LOCALSTACK_AUTH_TOKEN` pre-configured:\n\n```shell\nexport LOCALSTACK_AUTH_TOKEN=\u003cyour-auth-token\u003e\nlocalstack start\n```\n\n## Instructions\n\nIn this section, you'll learn how to deploy the CDK stack to LocalStack and test the ECS Code Mounting feature.\n\n### Installing dependencies\n\nTo install the dependencies, run the following command:\n\n```bash\nvirtualenv env\nsource env/bin/activate # On Windows, use `env\\Scripts\\activate`\npip install -r requirements.txt\n```\n\n### Deploying the CDK stack\n\nTo bootstrap the CDK, run the following command:\n\n```shell\ncdklocal bootstrap\n```\n\nTo deploy the infrastructure, run the following command:\n\n```shell\ncdklocal deploy\n```\n\nYou are expected to see the following output:\n\n```bash\n ✅  CdkEcsExample\n\n✨  Deployment time: 16.8s\n\nOutputs:\nCdkEcsExample.DemoServiceLoadBalancerDNS00F01F2F = lb-2cf5d58c.elb.localhost.localstack.cloud\nCdkEcsExample.DemoServiceServiceURL823541D5 = http://lb-2cf5d58c.elb.localhost.localstack.cloud\nStack ARN:\narn:aws:cloudformation:us-east-1:000000000000:stack/CdkEcsExample/c8aa4bea\n\n✨  Total time: 18.08s\n```\n\n### Testing the ECS deployment\n\nNavigate to the LocalStack logs and you would be able to see the following logs:\n\n```bash\n2024-04-10T15:32:47.025  WARN --- [   asgi_gw_1] l.s.e.t.docker             : Updating hostPort for ECS task to 19344, as requested host port 28099 seems unavailable\n```\n\nTo test the ECS deployment, run the following command:\n\n```shell\ncurl localhost:28099\n```\n\nYou are expected to see the following output:\n\n```bash\nHello, LocalStack!\n```\n\n### Testing the ECS Code Mounting feature\n\nGo to the `service/main.py` file and change the message on line 8 to `Hello, ECS Code Mounting!`. Save the file.\n\n```python3\n@app.route(\"/\")\ndef hello_world():\n    return \"Hello, ECS Code Mounting!\"\n```\n\nSave the file and run the following command to test the code mounting feature:\n\n```shell\ncurl localhost:28099\n```\n\nYou are expected to see the following output:\n\n```bash\nHello, ECS Code Mounting!\n```\n\n### Cleaning up\n\nTo clean up the resources, run the following command:\n\n```shell\nlocalstack stop\n```\n\n## How do I set up the ECS Code Mounting feature?\n\nTo use this example, you need to set up the ECS Code Mounting feature in the ECS task definition. The following code snippet demonstrates how to set up the ECS Code Mounting feature in the CDK stack:\n\n```python\ntask_definition = ecs.FargateTaskDefinition(\n    self,\n    \"DemoServiceTask\",\n    family=\"DemoServiceTask\",\n    volumes=[\n        ecs.Volume(\n            name=\"test-volume\",\n            host=ecs.Host(\n                source_path=os.path.join(os.getcwd(), \"service\")\n            ),\n        )\n    ],\n)\n...\ncontainer.add_mount_points(\n    ecs.MountPoint(\n        container_path=\"/app\",\n        source_volume=\"test-volume\",\n        read_only=True\n    ),\n)\n```\n\nIn the above snippet, you need to create a volume with the `source_path` pointing to the directory containing the code that you want to mount (in this case, the `service` directory). Then, you need to add a mount point to the container with the `container_path` pointing to the directory inside the container where you want to mount the code (in this case, the `/app` directory).\n\n## License\n\nThis library is licensed under the Apache 2.0 License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flocalstack-samples%2Fecs-code-mounting-python-cdk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flocalstack-samples%2Fecs-code-mounting-python-cdk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flocalstack-samples%2Fecs-code-mounting-python-cdk/lists"}