# Best way to set up multiple dev 'environments' in ECS?

**URL:** <https://awshq.com/t/best-way-to-set-up-multiple-dev-environments-in-ecs/15126>\
**Category:** AWS Compute Discussion\
**Tags:** ecs\
**Created:** [June 18, 2022, 4:11pm UTC](https://awshq.com/t/best-way-to-set-up-multiple-dev-environments-in-ecs/15126 "2022-06-18T16:11:46Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![Marodox1](https://awshq.com/letter_avatar_proxy/v4/letter/m/a3d4f5/32.png) [@Marodox1](https://awshq.com/u/Marodox1)\
**Post date:** [June 18, 2022, 4:11pm UTC](https://awshq.com/t/best-way-to-set-up-multiple-dev-environments-in-ecs/15126/1 "2022-06-18T16:11:46Z")

</div>

Hey all

Was wondering if anyone else currently does this in ECS. Looking to start using ECS, and I will need to be able to configure multiple ‘environments’ with different urls each with their own postgres/redis instance as well as custom environment variables.

I have done some research but there isn’t much clear and recent consensus on the best way to accomplish this. Would it be best to create totally separate clusters for each environment? We wouldn’t auto deploy through CI but I’d need a way to make a script that would update the container image and maybe some environment variables.

Thank you!

* * *

**Related discussions:**

- [API Gateway to EKS](https://awshq.com/t/api-gateway-to-eks/21583)
- [EC2 instance (t3.medium) keeps crashing every 6-8 days](https://awshq.com/t/ec2-instance-t3-medium-keeps-crashing-every-6-8-days/18950)
- [Dissapearing messages in Kinesis/EventBridge/SQS](https://awshq.com/t/dissapearing-messages-in-kinesis-eventbridge-sqs/21226)
- [AWS infrastructure visibility and drift detection.](https://awshq.com/t/aws-infrastructure-visibility-and-drift-detection/11522)
- [What is a cluster trying to abstract exactly?](https://awshq.com/t/what-is-a-cluster-trying-to-abstract-exactly/20967)

---

<div class="post-metadata">

**Author:** ![Scarface74](https://awshq.com/letter_avatar_proxy/v4/letter/s/df705f/32.png) [@Scarface74](https://awshq.com/u/Scarface74)\
**Post date:** [June 18, 2022, 6:02pm UTC](https://awshq.com/t/best-way-to-set-up-multiple-dev-environments-in-ecs/15126/3 "2022-06-18T18:02:09Z")

</div>

Parameterize as needed

[https://github.com/1Strategy/fargate-cloudformation-example/blob/master/fargate.yaml](https://github.com/1Strategy/fargate-cloudformation-example/blob/master/fargate.yaml)

Only one command needed - aws cloudformation deploy

---

<div class="post-metadata">

**Author:** ![iPushToProduction](https://awshq.com/letter_avatar_proxy/v4/letter/i/22d042/32.png) [@iPushToProduction](https://awshq.com/u/iPushToProduction)\
**Post date:** [June 18, 2022, 6:29pm UTC](https://awshq.com/t/best-way-to-set-up-multiple-dev-environments-in-ecs/15126/4 "2022-06-18T18:29:38Z")

</div>

Could also just create a terraform module for your environment and then have the image tag and env vars added per dev / environment when you apply. When your done just destroy.

---

<div class="post-metadata">

**Author:** ![nonFungibleHuman](https://awshq.com/letter_avatar_proxy/v4/letter/n/ba9def/32.png) [@nonFungibleHuman](https://awshq.com/u/nonFungibleHuman)\
**Post date:** [June 18, 2022, 6:47pm UTC](https://awshq.com/t/best-way-to-set-up-multiple-dev-environments-in-ecs/15126/5 "2022-06-18T18:47:27Z")

</div>

> [@iPushToProduction](#):
>
> Could also just create a terraform module for your environment and then have the image tag and env vars added per dev / environment when you apply. When your done just destroy.

Or the same using a CDK stack with params

---

<div class="post-metadata">

**Author:** ![AnySherbet](https://awshq.com/letter_avatar_proxy/v4/letter/a/848f3c/32.png) [@AnySherbet](https://awshq.com/u/AnySherbet)\
**Post date:** [June 18, 2022, 6:56pm UTC](https://awshq.com/t/best-way-to-set-up-multiple-dev-environments-in-ecs/15126/6 "2022-06-18T18:56:35Z")

</div>

> [@iPushToProduction](#):
>
> Could also just create a terraform module for your environment and then have the image tag and env vars added per dev / environment when you apply. When your done just destroy.

This is how I do it, except I use AWS Secrets for any sensitive env vars.

---

<div class="post-metadata">

**Author:** ![Marodox1](https://awshq.com/letter_avatar_proxy/v4/letter/m/a3d4f5/32.png) [@Marodox1](https://awshq.com/u/Marodox1)\
**Post date:** [June 18, 2022, 7:02pm UTC](https://awshq.com/t/best-way-to-set-up-multiple-dev-environments-in-ecs/15126/7 "2022-06-18T19:02:24Z")

</div>

> [@iPushToProduction](#):
>
> Could also just create a terraform module for your environment and then have the image tag and env vars added per dev / environment when you apply. When your done just destroy.

sorry i’m newish to terraform…could I create one module with all my vpcs/db/redid/ecs cluster and just somehow instantiate it multiple times with different config?

---

<div class="post-metadata">

**Author:** ![Saint762](https://awshq.com/letter_avatar_proxy/v4/letter/s/9fc348/32.png) [@Saint762](https://awshq.com/u/Saint762)\
**Post date:** [June 18, 2022, 7:05pm UTC](https://awshq.com/t/best-way-to-set-up-multiple-dev-environments-in-ecs/15126/8 "2022-06-18T19:05:13Z")

</div>

> [@Marodox1](#):
>
> sorry i’m newish to terraform…could I create one module with all my vpcs/db/redid/ecs cluster and just somehow instantiate it multiple times with different config?

Yes

---

<div class="post-metadata">

**Author:** ![iPushToProduction](https://awshq.com/letter_avatar_proxy/v4/letter/i/22d042/32.png) [@iPushToProduction](https://awshq.com/u/iPushToProduction)\
**Post date:** [June 18, 2022, 7:06pm UTC](https://awshq.com/t/best-way-to-set-up-multiple-dev-environments-in-ecs/15126/9 "2022-06-18T19:06:57Z")

</div>

> [@Marodox1](#):
>
> sorry i’m newish to terraform…could I create one module with all my vpcs/db/redid/ecs cluster and just somehow instantiate it multiple times with different config?

Yes you can. But I would be careful to separate your account setup and global (VPC, networking) from your app and database. For example I would personally provision my VPC with subnets, etc. in its own module then just pass those as parameters into the module for your ecs,db,redis module that you want to provision multiple times. There’s a lot of ways to do it but depending on your needs idk if you want that many VPCs and networking items being created if you don’t need it.

---

<div class="post-metadata">

**Author:** ![Dilfer](https://awshq.com/letter_avatar_proxy/v4/letter/d/e99b99/32.png) [@Dilfer](https://awshq.com/u/Dilfer)\
**Post date:** [June 18, 2022, 7:07pm UTC](https://awshq.com/t/best-way-to-set-up-multiple-dev-environments-in-ecs/15126/10 "2022-06-18T19:07:44Z")

</div>

> [@Marodox1](#):
>
> sorry i’m newish to terraform…could I create one module with all my vpcs/db/redid/ecs cluster and just somehow instantiate it multiple times with different config?

You absolutely can. Although im not sure you want a new vpc for every environment.

You can have a module which you use to create baseline infrastructure and then another more for your applications/dev environments which you use multiple times.

---

<div class="post-metadata">

**Author:** ![boy\_named\_su](https://awshq.com/letter_avatar_proxy/v4/letter/b/58f4c7/32.png) [@boy\_named\_su](https://awshq.com/u/boy_named_su)\
**Post date:** [June 18, 2022, 7:35pm UTC](https://awshq.com/t/best-way-to-set-up-multiple-dev-environments-in-ecs/15126/11 "2022-06-18T19:35:09Z")

</div>

Choose one:

1. environment by Namespace (same VPC, different names)
2. environment by VPC (each in own VPC)
3. environment by Account (each in own AWS Account)

more secure, but more complex, moving down

Then configure them using Parameter Store / Secrets Manager, which you can assign to environment variables in ECS

[https://docs.aws.amazon.com/AmazonECS/latest/developerguide/specifying-sensitive-data-parameters.html](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/specifying-sensitive-data-parameters.html)

---

<div class="post-metadata">

**Author:** ![GeorgeRNorfolk](https://awshq.com/letter_avatar_proxy/v4/letter/g/4bbf92/32.png) [@GeorgeRNorfolk](https://awshq.com/u/GeorgeRNorfolk)\
**Post date:** [June 18, 2022, 9:21pm UTC](https://awshq.com/t/best-way-to-set-up-multiple-dev-environments-in-ecs/15126/12 "2022-06-18T21:21:25Z")

</div>

If you use Fargate you can have multiple services with unique names running in one ECS cluster in a VPC. We’re planning on having multiple dev environments with the unique identifier being the Jira ticket ID in this kinda setup.

---

<div class="post-metadata">

**Author:** ![Saadzaman0](https://awshq.com/letter_avatar_proxy/v4/letter/s/53a042/32.png) [@Saadzaman0](https://awshq.com/u/Saadzaman0)\
**Post date:** [June 18, 2022, 10:46pm UTC](https://awshq.com/t/best-way-to-set-up-multiple-dev-environments-in-ecs/15126/13 "2022-06-18T22:46:08Z")

</div>

We recently did this .using terraform and workspaces on terraform .. it has worked very smoothly for us

---

<div class="post-metadata">

**Author:** ![SonOfSofaman](https://awshq.com/letter_avatar_proxy/v4/letter/s/82dd89/32.png) [@SonOfSofaman](https://awshq.com/u/SonOfSofaman)\
**Post date:** [June 19, 2022, 12:41am UTC](https://awshq.com/t/best-way-to-set-up-multiple-dev-environments-in-ecs/15126/14 "2022-06-19T00:41:10Z")

</div>

You could create multiple AWS accounts, organized under one AWS organization, one account per environment. You can create as many accounts as you want for dev, sandbox, test, staging, production … whatever you need. It’s a bit complicated, but you get the value of true isolation. This approach costs you nothing monetarily, just a bit of keeping track of things. If you’re using an Infrastructure as Code solution (Terraform for example) then you can easily provision all your resources in as many accounts/environments as you like and easily tear down resources in the accounts you’re not actively using to avoid accruing charges.

If you find yourself needing other resources besides ECS, multiple accounts will solve that problem, too. Except for S3 buckets whose names need to be globally unique.

I can’t overstate this comes with complexity, but the benefits might be worth it.

---

<div class="post-metadata">

**Author:** ![ephemeral\_resource](https://awshq.com/letter_avatar_proxy/v4/letter/e/b487fb/32.png) [@ephemeral\_resource](https://awshq.com/u/ephemeral_resource)\
**Post date:** [June 19, 2022, 1:29am UTC](https://awshq.com/t/best-way-to-set-up-multiple-dev-environments-in-ecs/15126/15 "2022-06-19T01:29:45Z")

</div>

This project deploys an ecs cluster for a django project that takes a variable to create a whole environment. I wrote it, thought it isn’t super well documented it should be pretty readable:

[https://gitlab.com/uptimepros/uptimepros-oss/cdk-www-uptimepros](https://gitlab.com/uptimepros/uptimepros-oss/cdk-www-uptimepros)

Command ends up looking like `inv deploy --environment=dev`. Setup to run from CI optionally.

---

<div class="post-metadata">

**Author:** ![informity](https://awshq.com/letter_avatar_proxy/v4/letter/i/f475e1/32.png) [@informity](https://awshq.com/u/informity)\
**Post date:** [June 19, 2022, 2:38am UTC](https://awshq.com/t/best-way-to-set-up-multiple-dev-environments-in-ecs/15126/16 "2022-06-19T02:38:25Z")

</div>

I would suggest to use multiple accounts (one for each environment) and AWS CDK for deployment. You can setup a pipeline in each account and then associate GitHub branches such as `develop`, `stage`, and `master`, in GitHub actions to trigger pipeline in each corresponding environment. Full automation, just write your app code and enjoy. Just don’t forget to use non-overlapping CIDRs in each account VPC(s) in case you would ever want to connect those with VPC peering or Transit Gateway.

---

<div class="post-metadata">

**Author:** ![debian\_miner](https://awshq.com/letter_avatar_proxy/v4/letter/d/9fc348/32.png) [@debian\_miner](https://awshq.com/u/debian_miner)\
**Post date:** [June 19, 2022, 3:46pm UTC](https://awshq.com/t/best-way-to-set-up-multiple-dev-environments-in-ecs/15126/17 "2022-06-19T15:46:07Z")

</div>

> [@Marodox1](#):
>
> sorry i’m newish to terraform…could I create one module with all my vpcs/db/redid/ecs cluster and just somehow instantiate it multiple times with different config?

While VPCs are free, each one with a private subnet will need a NAT gateway to access the internet, which costs around $30/mo as a base.

---

<div class="post-metadata">

**Author:** ![gamprin](https://awshq.com/letter_avatar_proxy/v4/letter/g/67e7ee/32.png) [@gamprin](https://awshq.com/u/gamprin)\
**Post date:** [June 19, 2022, 9:18pm UTC](https://awshq.com/t/best-way-to-set-up-multiple-dev-environments-in-ecs/15126/18 "2022-06-19T21:18:29Z")

</div>

I wrote an article about this and posted it here last week, here a link to that post: [https://www.reddit.com/r/aws/comments/v9ycwh/my\_approach\_to\_building\_ad\_hoc\_developer/](https://www.reddit.com/r/aws/comments/v9ycwh/my_approach_to_building_ad_hoc_developer/)

Here’s the original article I wrote on my blog: [https://briancaffey.github.io/2022/03/27/ad-hoc-developer-environments-for-django-with-aws-ecs-terraform-and-github-actions](https://briancaffey.github.io/2022/03/27/ad-hoc-developer-environments-for-django-with-aws-ecs-terraform-and-github-actions)

I think my article will answer the different features you are looking for in your post:

- different urls  
- postgres+ redis per environment  
- custom environment variables per environment  
- totally separate clusters for each environment? Yes.  
- We wouldn’t auto deploy through CI - My example repo does this as a GitHub Action  
- script that would update the container image: I also include a discussion of the script I made for doing this  
- maybe some environment variables: I would try to keep all environment variables (that are not secrets/sensitive data) in \*.tfvars files or TF\_VAR\_ values that you can set when you run your script to update the environment. To keep things simple, the script that runs the application update should ONLY change the image tag and env vars should be managed as infra, in my opinion.

Happy to answer any questions about this if you have any

---

<div class="post-metadata">

**Author:** ![DingusFamilyVacation](https://awshq.com/letter_avatar_proxy/v4/letter/d/8dc957/32.png) [@DingusFamilyVacation](https://awshq.com/u/DingusFamilyVacation)\
**Post date:** [January 26, 2024, 12:10am UTC](https://awshq.com/t/best-way-to-set-up-multiple-dev-environments-in-ecs/15126/19 "2024-01-26T00:10:09Z")

</div>

> [@gamprin](#):
>
> I wrote an article about this and posted it here last week, here a link to that post: …

I realize you wrote this two years ago, but this post is EXCELLENT. Thank you so much.

---

<div class="post-metadata">

**Author:** ![gamprin](https://awshq.com/letter_avatar_proxy/v4/letter/g/67e7ee/32.png) [@gamprin](https://awshq.com/u/gamprin)\
**Post date:** [January 26, 2024, 12:29am UTC](https://awshq.com/t/best-way-to-set-up-multiple-dev-environments-in-ecs/15126/20 "2024-01-26T00:29:42Z")

</div>

> [@DingusFamilyVacation](#):
>
> I realize you wrote this two years ago, but this post is EXCELLENT. Thank you so much.

Thank you! Here is a more recent article on the same topic: [https://briancaffey.github.io/2023/01/07/i-deployed-the-same-containerized-serverless-django-app-with-aws-cdk-terraform-and-pulumi](https://briancaffey.github.io/2023/01/07/i-deployed-the-same-containerized-serverless-django-app-with-aws-cdk-terraform-and-pulumi)
