{"id":16143128,"url":"https://github.com/johnbedeir/aws_codedeploy","last_synced_at":"2025-04-06T19:24:39.461Z","repository":{"id":253860344,"uuid":"844746474","full_name":"johnbedeir/AWS_CodeDeploy","owner":"johnbedeir","description":"This project demonstrates a complete CI/CD pipeline using AWS CodeDeploy and Terraform. The repository contains Terraform configurations that automate the provisioning and deployment process, including the creation of an S3 bucket, EC2 instances, and a load balancer, as well as setting up an AWS CodeDeploy application and deployment group.","archived":false,"fork":false,"pushed_at":"2024-08-20T19:26:02.000Z","size":52,"stargazers_count":3,"open_issues_count":1,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-13T01:28:57.511Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"HCL","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/johnbedeir.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":"2024-08-19T22:24:01.000Z","updated_at":"2024-11-05T05:27:46.000Z","dependencies_parsed_at":null,"dependency_job_id":"8dbf7bf4-ba49-4c7c-b1f2-4fa9ca5222ce","html_url":"https://github.com/johnbedeir/AWS_CodeDeploy","commit_stats":null,"previous_names":["johnbedeir/aws_codedeploy"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/johnbedeir%2FAWS_CodeDeploy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/johnbedeir%2FAWS_CodeDeploy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/johnbedeir%2FAWS_CodeDeploy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/johnbedeir%2FAWS_CodeDeploy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/johnbedeir","download_url":"https://codeload.github.com/johnbedeir/AWS_CodeDeploy/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247536857,"owners_count":20954834,"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":[],"created_at":"2024-10-10T00:08:41.409Z","updated_at":"2025-04-06T19:24:39.440Z","avatar_url":"https://github.com/johnbedeir.png","language":"HCL","funding_links":[],"categories":[],"sub_categories":[],"readme":"# AWS CodeDeploy with Terraform\n\n\u003cimg src=cover.png\u003e\n\nThis project demonstrates how to deploy a Node.js application to an EC2 instance using AWS CodeDeploy with Terraform and GitHub Actions. The setup includes automatic provisioning of AWS resources and deployment of the application using a simple CI/CD pipeline.\n\n## Project Structure\n\n```\n.\n├── appspec.yml                     # AWS CodeDeploy configuration file\n├── myapp/                          # Node.js application files\n│   ├── index.js\n│   └── ...                         # Other application files\n├── scripts/                        # Deployment scripts\n│   ├── install_dependencies.sh     # Script to install dependencies\n│   └── start_application.sh        # Script to start the Node.js application\n├── terraform/                      # Terraform configuration files\n│   ├── main.tf\n│   ├── variables.tf\n│   └── outputs.tf\n└── README.md                       # Project documentation\n```\n\n## Prerequisites\n\n- AWS CLI configured with appropriate access.\n- Terraform installed on your local machine.\n- An AWS account with permissions to create and manage EC2, S3, IAM, and CodeDeploy resources.\n\n## Setup Instructions\n\n### 1. Configure Terraform\n\n1. **Navigate to the `terraform/` directory:**\n\n   ```bash\n   cd terraform/\n   ```\n\n2. **Initialize Terraform:**\n\n   ```bash\n   terraform init\n   ```\n\n3. **Edit the `variables.tf` file:**\n\n   - Define your desired settings for the deployment, such as the AWS region, EC2 instance type, and AMI ID.\n\n4. **Create `terraform.tfvars` file:**\n\n   - That include your public ssh key to be able to access the EC2.\n\n5. **Apply the Terraform configuration:**\n   ```bash\n   terraform apply\n   ```\n   - This command will provision the necessary AWS resources, including an EC2 instance, S3 bucket, and IAM roles.\n\n### 2. Prepare the Application for Deployment\n\n1. **Zip your application files:**\n\n   - Include the `appspec.yml`, `myapp/`, and `scripts/` directories in the root of the zip file.\n\n   ```bash\n   zip -r myapp.zip appspec.yml myapp/ scripts/\n   ```\n\n2. **Upload the zip file to S3:**\n   - Use the AWS CLI to upload the deployment package to your S3 bucket.\n   ```bash\n   aws s3 cp myapp.zip s3://\u003cyour-s3-bucket\u003e/myapp.zip\n   ```\n\n### 3. Deploy the Application with CodeDeploy\n\n1. **Create a deployment using AWS CLI:**\n\n   ```bash\n   aws deploy create-deployment \\\n     --application-name MyCodeDeployApp \\\n     --deployment-config-name CodeDeployDefault.OneAtATime \\\n     --deployment-group-name MyDeploymentGroup \\\n     --s3-location bucket=\u003cyour-s3-bucket\u003e,bundleType=zip,key=myapp.zip\n   ```\n\n2. **Monitor the Deployment:**\n   - Use the AWS Management Console or the AWS CLI to monitor the progress of the deployment.\n   - Check the logs if the deployment fails to troubleshoot issues.\n\n### 4. Access Your Application\n\n- Once the deployment is successful, access your application using the public IP or DNS of the EC2 instance:\n  ```bash\n  http://\u003cpublic-ip-or-dns\u003e\n  ```\n\n## Continuous Deployment with GitHub Actions\n\nThis project includes a GitHub Actions workflow to automate the deployment of a Node.js application to an EC2 instance using AWS CodeDeploy. The workflow is triggered on every push to the `main` branch, creating a deployment package, uploading it to S3, and then deploying it using CodeDeploy.\n\n### GitHub Actions Workflow\n\nThe workflow is defined in `.github/workflows/deploy.yml` and includes the following steps:\n\n1. **Checkout Code**:\n\n   - The workflow checks out the latest version of the code from the `main` branch.\n\n2. **Zip the Application**:\n\n   - The application files are zipped into a single deployment package named `myapp.zip`.\n\n3. **Upload to S3**:\n\n   - The deployment package (`myapp.zip`) is uploaded to an S3 bucket (`dev-codedeploy-bucket-ajkgr8mu`).\n\n4. **Deploy with CodeDeploy**:\n   - A deployment is created using AWS CodeDeploy, specifying the application name, deployment group, and S3 location of the deployment package.\n\n### Prerequisites\n\nTo use this workflow, you need to have the following in place:\n\n- **AWS Credentials**: Store your `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY` in the GitHub repository's secrets. These will be used by the workflow to authenticate with AWS.\n- **S3 Bucket**: Ensure that the S3 bucket (`dev-codedeploy-bucket-ajkgr8mu`) exists in the specified AWS region (`eu-central-1`).\n- **AWS CodeDeploy Setup**: An AWS CodeDeploy application and deployment group must be configured and ready to receive deployments.\n\n2. **Configure AWS Secrets**:\n\n   - In your GitHub repository, go to **Settings \u003e Secrets and variables \u003e Actions**.\n   - Add the following secrets:\n     - `AWS_ACCESS_KEY_ID`\n     - `AWS_SECRET_ACCESS_KEY`\n     - Ensure these credentials have the necessary permissions to upload to S3 and create deployments in CodeDeploy.\n\n3. **Trigger the Deployment**:\n   - Push any changes to the `main` branch of your repository to trigger the workflow.\n   - The workflow will automatically package the application, upload it to S3, and deploy it to your EC2 instances using AWS CodeDeploy.\n\n## Troubleshooting\n\n- **Deployment Failures:** Check the CodeDeploy logs at `/var/log/aws/codedeploy-agent/codedeploy-agent.log` on the EC2 instance for detailed error messages.\n\n```\nsudo service codedeploy-agent status\n```\n\n```\nsudo tail -f /var/log/aws/codedeploy-agent/codedeploy-agent.log\n```\n\n- **IAM Role Issues:** Ensure the IAM role attached to the EC2 instance has the correct permissions for S3, CodeDeploy, and CloudWatch.\n  `Make sure the CodeDeploy is using the same IAM role assigned with the EC2`:\n\n```\ncurl http://169.254.169.254/latest/meta-data/iam/security-credentials/\n```\n\n- **AppSpec Issues:** Verify that the `appspec.yml` file is correctly formatted and that all file paths and scripts are correctly referenced.\n\n## Clean Up\n\nTo clean up all AWS resources created by this project, run the following Terraform command:\n\n```bash\nterraform destroy\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjohnbedeir%2Faws_codedeploy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjohnbedeir%2Faws_codedeploy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjohnbedeir%2Faws_codedeploy/lists"}