This project is created to build a serverless CICD pipeline for ASG Instance refresh. We would be using HashiCorp Packer to create AMI and create notification to kick start serverless ASG Instance refresh.
Update terraform_iac/inputs.tfvars file with below details
- Your Repository Name
- Owner of the Repository
- AWS Profile which has access to deploy resources.
- Git Hub token. It can any secret string.
- Region
- Email Ids for notification (Inform of string seperated by ,)
- OauthToken generated from your Github account.
- VPC Id
- A base AMI for intial deployment of ASG. It will be used in Packer as base ami.
- Key Pair for EC2 instances.
- cd terraform_iac
- terraform init
- terraform plan -var-file="inputs.tfvars"
- terraform apply -var-file="inputs.tfvars"
- note down
Web Server URL
from Terraform Output
- update ami_build_packer/scripts/web_ami_setup.sh script with new version.
- push code into github
Once code is pushed into GitHub. GitHub Webhook will kick start AWS CodePipeline and AWS CodeBuild will start EC2 AMI creation with Packer. Once AMI Creation is complete, Serverless Lambda will start Autoscaling Group instance refresh without any downtime.
- Note: If your Codepipeline is failing connect with GitHub then login into AWS and Authenticate Github from Codepipeline source setup screen.
- Learn more:
https://learn.hashicorp.com/tutorials/packer/getting-started-install
- install
choco install packer
- Verify:
packer
- cd ami_build_packer
- packer build -var "base_ami=<BASE_AMI_HERE>" images/web_ami_image.json