
Automating AWS Infra Deployment with Gitsync & CloudFormation
Dive into this step-by-step guide to seamlessly automate infrastructure deployment using Gitsync and AWS Cloudformation
Published Aug 20, 2024
Create a Connection Between AWS and GitHub:
Please follow this link to establish the connection: Step-by-Step Guide to Connecting AWS with GitHub for Automated Workflow
1.Create a Repository on GitHub

2.Create an EC2 Instance with a CloudFormation Template and Upload It to Your Repository

3. Create an IAM Role for CloudFormation: I've created it with administrator access, but restrict access when configuring the production environment

4.Go to AWS and search for CloudFormation

5.click “Create stack”

6. Select 'Choose an existing template' and set the template source to 'Sync from Git,' then click 'Next’

7. Provide the stack name and select 'Create the file using the following parameters and place it in my repository' for deployment file creation

8. Since we already have a connection between AWS and the Git repository, select 'Choose a linked Git repository,' then choose the created repository and branch. Provide the deployment file path, select 'New IAM role,' and specify the role name

9. Provide the CloudFormation (CFN) template for the stack and click 'Next’

10. Select the IAM role created for CloudFormation to use

11.Click “Next”

12.Click ‘submit’ to create the stack

13. Once the stack is created, a banner will appear indicating that pull requests have been created in your Git sync repository

14. Go to the GitHub repository, and you will see the open pull requests which created by CloudFormation stack

15.Click “Merge Pull request” to merge from aws created branch (ex:aws-sync-main-7ad76278)

16.Click “Confirm Merge”

17. Once merged, Git sync will start the provisioning process

18. Git sync has successfully provisioned the resources based on the changeset

19. Go to the EC2 console and verify that the instance has been created by the CloudFormation stack

20. An Amazon EventBridge rule has been created to monitor CloudFormation stack status changes

21. A deployment file has been created in the GitHub repository

22. Update the CloudFormation (CFN) template to include the creation of an Elastic IP and attach it to the instance

23. Commit the changes to the repository

24. After committing the changes, Git sync will automatically start provisioning the resources based on the latest commit

25. Provisioning is complete with the latest commit. You can cross-check the commit ID to verify

Validation:
26. The Elastic IP has been created by the CloudFormation stack

27. The Elastic IP has been attached to the EC2 instance

Keep Learning, Keep Deploying!!!
Feel free to reach out to me, if you have any other queries or suggestions
Stay connected on LinkedIn https://www.linkedin.com/in/mahendran-selvakumar- 36444a77
Stay connected on Medium https://devopstronaut.com/