Ticker

6/recent/ticker-posts

Deploy a web application to ECS using cloudformation and Bitbucket Pipeline

 

Objective:

  • The aim of this blog is to provide simple and clear steps to deploy a web application to AWS ECS using AWS Cloudformation and Bitbucket Pipeline.
  • You will also learn how to automate infrastructure setup using nested stacks, create container, upload docker images to Amazon ECR and setup automated deployment pipeline.
  • I intentionally have chosen not to include the RDS template as part of the CI/CD pipeline, considering it as part of the architecture diagram. This decision was based on the best practice of managing it separately from the pipeline lifecycle.


Technical Diagram:



Prerequisites:

  • Setup bitbucket repository with your web application code
  • Setup runner(ref) with Tag self.hosted and linux
  • Have network resources ready before hand, You can have seperate repository for this, here is the reference that you can following to manage these resources using nested stack concepts of cloudformation, and also you need to have OIDC role created, same has been explain in the reference.

GitHub Repo Link: 


Project folder structure:




STEPS:

  1. Setup environment variable in Deployment settings of bitbucket repository
  2. Create CFT templates for ECR & ECS service
  3. Create bitbucket pipeline
  4. Run the pipeline

1. Setup environment variable in Deployment settings of bitbucket repository:




2. Create CFT templates for ECR & ECS service:

ECR and ECS resources will be created as part of the application deployment pipeline. However, networking resources must be set up in advance because they need to be added to the workspace. Alternatively, you can use AWS Systems Manager Parameter Store for this purpose.

3. Create bitbucket pipeline:

In Build stage I am installing essential tools which I am using for security checks and linting purpose essentially we can fail the pipeline however as part of this tutorial I am passing it intentionally to complete the CICD pipeline demo.

and in Deploy stage I am assuming OIDC-role and setting up few of the variables and post that I am deploying ecr cloudformation template to check if ECR repository has been created and then I am building the image and pushing it to ECR repo and then deploying ECS service.

4. Run the pipeline & browse the application with ALB dns name:





Moreover, you can use the Route 53 service to map your domain name to the ALB DNS name.


Thanks for reading!!

Post a Comment

0 Comments