DEV Community

Cover image for Automate CloudFormation deployments from GitHub

Automate CloudFormation deployments from GitHub

  • AWS CloudFormation,(IaC) lets you provision, and manage AWS and third-party resources, now offers Git sync support.
  • This feature automatically triggers deployments upon updates to a tracked Git repository. The integration, compatible with GitHub, GitHub Enterprise, GitLab, and Bitbucket.
  • CloudFormation development cycles by seamlessly integrating with Git workflows, reducing time lost to context switching.

Key Highlights:

  1. Git Sync Integration: AWS CloudFormation now supports Git sync, triggering automatic deployments on Git repository updates.

  2. Compatibility: GitHub, GitHub Enterprise, GitLab, and Bitbucket are directly integrated with AWS CloudFormation.

  3. Development Experience: Explore a modern development experience utilizing GitHub's native tools and CloudFormation's Git sync integration.

  4. Cloud Development Environment: Create a cloud development environment using GitHub CodeSpaces.

  5. Integration with GitHub Actions: Integrate direct feedback into Pull Requests using GitHub Actions and the CloudFormation Linter.

Requirements:

  1. AWS Account: Ensure you have an AWS account for deploying S3 Bucket.

  2. GitHub Account: Access to GitHub Codespaces and Actions is necessary.

GIT Setup

Step 1: Creating an empty Git Repository

Image description

Step 2: Clone repository in your workspace and you can install the linter.

Image description

Next, you’ll create your template in the base directory called s3.yaml

Below template will create s3 bucket.

Image description

You can verify the template gives no errors by running cfn-lint in the terminal and verifying it returns no errors.

Image description

Please install package if cf-lint is not installed

pip3 install cfn-lint

Enter fullscreen mode Exit fullscreen mode

Step 3: Need to add the deployment file

  1. Git sync supports a deployment file to provide flexibility for managing CloudFormation stacks from within a Git repository.

  2. This config file manages the location of the template file, and any parameters or tags you may be interested in using.

  3. You’ll be creating a new file called deployment-file.yaml in your repository. Since this stack doesn’t have parameters or tags, it’ll be relatively simple:

template-file-path: ./s3.yaml

Enter fullscreen mode Exit fullscreen mode

Your code working directory look look this

Image description

AWS Setup

First, create the role that will deploy our CloudFormation template. Be sure to note the name you select for this as you’ll be using it to manage your stack later. This example uses s3-deployment-iam-role.

Image description

Creat stack.

Image description

Here, you can see the new option to select Sync from Git template source, which you can configure on the next screen. Since you already created your stack deployment file, you can select I am providing my own file in my repository.

Select GitHub, your connection, the repository, and branch, the deployment file location.

Image description

Image description

Finally, you will select New IAM Role to create a service managed role

Image description

Finally, you can see the status of your sync in the new “Git sync” tab, including the configuration you provided earlier as well as the status of your sync, your previous deployments, and the option to retry or disconnect the sync if needed.

Image description

FINAL RESULT:

Image description

I updated the GitHub repository by changing the bucket name from 'cf-s3-git-bucket-v1' to 'cf-s3-git-bucket-v2'."

Image description

"After updating the GitHub repository, the modified bucket name 'cf-s3-git-bucket-v2' will automatically trigger the deployment of your stack. This enhancement reflects a resilient and scalable CI/CD system designed for efficient management of your infrastructure as code."

Image description

Thanks for reading. Happy learning

Top comments (0)