Deploying to AWS ECS

2 minute read

To make it easy for you to deploy your application to AWS ECS, we’ve built a container that has the AWSCLI installed. We will set up a simple example showing you how to configure any deployment to AWS ECS.

CodeShip AWS Deployment Container

CloudBees CodeShip Pro uses an AWS deployment container that we maintain to authenticate with your AWS account.

Please review our AWS documentation to learn how to set up and use this authentication container.

You will need the AWS service, as well as your application itself, defined via your codeship-services.yml file so that you can execute the necessary S3 commands in your codeship-steps.yml file.

It is also advised that you review AWS’ IAM documentation to find the correct policies for your account.

Pushing To ECR

Next, you may want to push your images to the AWS Elastic Container Registry.

To do so, you will need to reference the dockercfg_generator service from the above example using the dockercfg_service option in a push step to ECR in your codeship-steps.yml file to generate the AWS authentication token GCR requires, as shown below.

You can read more in-depth instructions for pushing to an image registry, including ECR, on our image registries documentation.

- name: ECR Push service: app type: push image_name: ecr-region-url/your-image registry: ecr-region-url dockercfg_service: dockercfg_generator

Note that ecr-region-url above should be replaced with your region-specific ECR url.

Deploying To AWS Elastic Container Service

To interact with ECS, you will simply use the corresponding AWS CLI commands via the awsdeployment service defined in your codeship-services.yml file.

You will pass this service commands via the codeship-steps.yml file, as seen in the example deployment below.

If you have more complex workflows for deploying your ECS tasks you can put those commands into a script and run the script as part of your workflow.

- service: awsdeployment command: aws ecs register-task-definition --cli-input-json file:///deploy/tasks/backend.json - service: awsdeployment command: aws ecs update-service --service my-backend-service --task-definition backend - service: awsdeployment command: aws ecs register-task-definition --cli-input-json file:///deploy/tasks/process_queue.json - service: awsdeployment command: aws ecs run-task --cluster default --task-definition process_queue --count 5

Note that we’re using the task definitions from the AWSCLI ECS docs

Also note that the awsdeployment service is discussed in more detail in our AWS documentation, and that all ECS-related commands will work the same way in lieu of the above example.