{"id":13286981,"url":"https://github.com/shreyassrinath/Deploy--AWS-ECS--Task-And--Service","last_synced_at":"2025-03-10T05:31:37.583Z","repository":{"id":79697197,"uuid":"94336545","full_name":"shreyassrinath/Deploy--AWS-ECS--Task-And--Service","owner":"shreyassrinath","description":"Automated deployment of ECS task and service to pre existing AWS ECS cluster using Ansible.","archived":false,"fork":false,"pushed_at":"2023-03-26T12:08:27.000Z","size":141,"stargazers_count":9,"open_issues_count":0,"forks_count":12,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-07-29T16:54:07.100Z","etag":null,"topics":["ansible","aws-ecs","mysql","vagrant","wordpress"],"latest_commit_sha":null,"homepage":"","language":"Shell","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/shreyassrinath.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}},"created_at":"2017-06-14T13:55:11.000Z","updated_at":"2024-07-07T21:22:43.000Z","dependencies_parsed_at":"2024-10-23T08:54:43.817Z","dependency_job_id":"e20e350b-6f08-49c1-bfc6-f4400e15cfca","html_url":"https://github.com/shreyassrinath/Deploy--AWS-ECS--Task-And--Service","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shreyassrinath%2FDeploy--AWS-ECS--Task-And--Service","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shreyassrinath%2FDeploy--AWS-ECS--Task-And--Service/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shreyassrinath%2FDeploy--AWS-ECS--Task-And--Service/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shreyassrinath%2FDeploy--AWS-ECS--Task-And--Service/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shreyassrinath","download_url":"https://codeload.github.com/shreyassrinath/Deploy--AWS-ECS--Task-And--Service/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242797805,"owners_count":20186798,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["ansible","aws-ecs","mysql","vagrant","wordpress"],"created_at":"2024-07-29T16:51:41.056Z","updated_at":"2025-03-10T05:31:37.577Z","avatar_url":"https://github.com/shreyassrinath.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Deploy AWS ECS Task and Service via Ansible\n\n## Description\n\nAutomated deployment of ECS task and service to pre existing AWS ECS cluster using Ansible. \n\n### Architecture\n\n![Alt](/resources/AWS-ECS-Deploy.jpg \"Architecture Diagram\")\n\n### Definitions\n\n#### What is Amazon EC2 Container Service?\n\nAmazon EC2 Container Service (Amazon ECS) is a highly scalable, fast, container management service that makes it easy to run, stop, and manage Docker containers on a cluster of Amazon Elastic Compute Cloud (Amazon EC2) instances. \n\n#### What is Task Definition?\n\nTo prepare your application to run on Amazon ECS, you create a task definition. The task definition is a text file in JSON format that describes one or more containers that form your application. It can be thought of as a blueprint for your application.\n\n#### What are Clusters?\n\nWhen you run tasks using Amazon ECS, you place them on a cluster, which is a logical grouping of EC2 instances.\n\n#### What is Container Agent?\n\nThe container agent runs on each instance within an Amazon ECS cluster. It sends information about the instance's current running tasks and resource utilization to Amazon ECS, and starts and stops tasks whenever it receives a request from Amazon ECS. \n\n#### What is a AWS ECS Service?\n\nAmazon ECS allows you to run and maintain a specified number (the \"desired count\") of instances of a task definition simultaneously in an ECS cluster. This is called a service. If any of your tasks should fail or stop for any reason, the Amazon ECS service scheduler launches another instance of your task definition to replace it and maintain the desired count of tasks in the service.\n\n#### What is [Ansible](https://github.com/ansible/ansible)?\n\nAnsible is a radically simple IT automation platform that makes your applications and systems easier to deploy. Avoid writing scripts or custom code to deploy and update your applications, automate in a language that approaches plain English, using SSH, with no agents to install on remote systems.\n\n## Installation requirements\n\n* Install [VirtualBox](https://www.virtualbox.org/wiki/Downloads) and [Vagrant](https://www.vagrantup.com/downloads.html)\n* Clone this repo\n* Drop in AWS Credentials @ config/.aws/credentials folder. The aws credentials need to have permissions to create ecs tasks and services. For more information on AWS IAM refer [here](http://docs.aws.amazon.com/IAM/latest/UserGuide/introduction.html)\n\n## Commands\n\nStart:\n\n`$ vagrant up`\n\nThis does the following:\n\n* Copies AWS credentials from host to VM\n* Installs [Ansible](https://www.ansible.com/)\n* Backs up Ansible hosts file and updates with the one that is provided with the repo.\n* Gathers SSH public keys by executing ssh-keyscan on localhost.\n* Installs python-pip and necessary aws packages.\n\nSSH into the server\n\n`$ vagrant ssh`\n\n### Establish SSH trust\n\nIn order to establish password less access to nodes(and host) we need to establish SSH trust. The ssh-addkey.yml playbook uses authorized_key module which will help in configuring ssh password less logins on remote machines. More details  on authorized_key module can be found [here](http://docs.ansible.com/ansible/authorized_key_module.html).\n\nCheck to make sure we do not have public RSA key.   \n`$ ls -l .ssh/`\n\nWe will create a RSA key by the following command\n\n`$ ssh-keygen -t rsa -b 2048`\n\nCheck to make sure we have the id_rsa.pub file present as specified in the ssh-addkey.yml playbook.\n\nRun the ansible play book - ssh-addkey.yml with ask pass option to make sure we are deploying the key to all machines- in this case there is only one machine- localhost.\n\n`$ ansible-playbook deploytoECS/playbooks/ssh-addkey.yml --ask-pass`\n\nNow try the ansible ping module to ping the local server with the ask password option.\n\n`$ ansible all -m ping`\n\nThis is should provide the following output.\n\n```\nlocalhost | SUCCESS =\u003e {\n    \"changed\": false,\n    \"ping\": \"pong\"\n}\n```\n### Deploy ECS task and service to AWS ECS cluster\n\nCd to playbooks directory\n\n`$ cd deploytoECS/playbooks`\n\nRun the ansible playbook to deploy Wordpress website to ECS task and start a service\n\n`$ ansible-playbook deploy-ecs-task\\\u0026service.yml`\n\nThis does the following: \n\n* Creates a task definition using wordpress,phpmyadmin and mysql docker images \n* Creates a ECS service in pre existing cluster(update cluster name in deploy-ecs-task\u0026service.yml file in the \"set_fact\" task).\n* If there are no errors, Wordpress should now be accessible at the Public DNS of the Cluster's Container instance. PHP My admin should be available on the same host at 8181. (Port 8181 needs to be made accesible via security group of the EC2 instance.)\n\n\n## Reference\n[AWS ECS](http://docs.aws.amazon.com/AmazonECS/latest/developerguide/Welcome.html)\n\n[ECS services](http://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs_services.html)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshreyassrinath%2FDeploy--AWS-ECS--Task-And--Service","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshreyassrinath%2FDeploy--AWS-ECS--Task-And--Service","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshreyassrinath%2FDeploy--AWS-ECS--Task-And--Service/lists"}