Adding a Second Service with AWS Copilot

Viewed 486

I've very familiar with doing all of this (quite tedious) stuff manually with ECS.

I'm experimenting with Copilot - which is really working - I have one service up really easily, but my solution has multiple services/containers.

How do I now add a second service/container to my cluster?

1 Answers

Short answer: change to your second service's code directory and run copilot init again! If you need to specify a different dockerfile, you can use the --dockerfile flag. If you need to use an existing image, you can use --image with the name of an existing container registry.

Long answer: Copilot stores metadata in SSM Parameter Store in the account which was used to run copilot app init or copilot init, so as long as you don't change the AWS credentials you're using when you run Copilot, everything should just work when you run copilot init in a new repository.

Some other use cases:

If it's an existing image like redis or postgres and you don't need to customize anything about the actual image or expose it, you can run

copilot init -t Backend\ Service --image redis --port 6379 --name redis

If your service lives in a separate code repository and needs to access the internet, you can cd into that directory and run

copilot init --app $YOUR_APP_NAME --type Load\ Balanced\ Web\ Service --dockerfile ./Dockerfile --port 1234 --name $YOUR_SERVICE_NAME --deploy

So all you need to do is run copilot init --app $YOUR_APP_NAME with the same AWS credentials in a new directory, and you'll be able to set up and deploy your second services.

Copilot also allows you to set up persistent storage associated with a given service by using the copilot storage init command. This specifies a new DynamoDB table or S3 bucket, which will be created when you run copilot svc deploy. It will create one storage addon per environment you deploy the service to, so as not to mix test and production data.

Related