Day 10: Infrastructure as Code with AWS CloudFormation
Day 10 of "30 Days of AWS"
Welcome to Day 10 of our exciting "30 Days of AWS" journey! If you've been following along from the beginning, kudos to you for getting into the world of Amazon Web Services. Your dedication and curiosity are truly commendable.
For those who might have just joined us or are specifically interested in today's topic, a warm welcome to you as well! While each article in this series delves into a different facet of AWS, rest assured that they are all interconnected, building upon the knowledge we've been cultivating day by day.
If you're here for the first time, I encourage you to take a moment to catch up on our previous discussions. This will enhance your understanding and ensure a seamless flow as we dive deeper into the fascinating journey of AWS with me.
In today's installment, we will explore "Infrastructure as Code with AWS CloudFormation".
As always, feel free to engage, ask questions, and share your thoughts in the comments. Your participation is what makes this series vibrant and valuable. I'm thrilled to have you join us on this journey. Let's get started!
What is Infrastructure as Code (IaC)?
Infrastructure as Code (IaC) means defining and managing your infrastructure using code rather than manually configuring resources.
Think of it like planning your dream vacation (mine is Paris). Instead of manually booking flights, hotels, and activities each time you travel, you create a detailed itinerary and booking system that you can reuse.
Similarly, IaC allows you to define and provision your AWS infrastructure using code, making your cloud resources as easy to manage as your travel plans.
Fun Fact #1: IaC Prevents "Luggage Mishaps"
Remember that time your luggage got lost during a flight? With IaC, you define your infrastructure, ensuring nothing gets left behind or lost in translation. No more "luggage mishaps" in the cloud!
AWS CloudFormation: Your Travel Planner
AWS CloudFormation is your trusty travel planner for creating and managing AWS resources using code. Like a travel planner organizes your trips, CloudFormation organizes your AWS infrastructure as code.
Fun Fact #2: CloudFormation, the Virtual Travel Agent
Imagine CloudFormation as a virtual travel agent (MakeMyTrip, Yatra, Goibibo) who not only books your flights and hotels but also arranges sightseeing tours, restaurant reservations, and even the weather forecast for your trip!
Creating and Deploying Stacks with CloudFormation
Now, let's get our hands dirty and explore how to create and deploy AWS resources using CloudFormation.
Step 1: Define Your "Travel Itinerary" (CloudFormation Template)
Just as you plan your trip by creating an itinerary, you define your AWS infrastructure using a CloudFormation template. This template is written in YAML or JSON and describes all the resources you want to create.
Resources:
MyUbuntuEC2Instance:
Type: AWS::EC2::Instance
Properties:
ImageId: ami-053b0d53c279acc90
InstanceType: t2.micro
Step 2: Create a CloudFormation Stack
Log in to your AWS Management Console.
Type "CloudFormation" in the search bar and click on "CloudFormation" under the "Management & Governance" section.
Click the "Create stack" button.
If you have a template already, Choose "Template is ready" and "Upload a template file." --> Upload your CloudFormation template file. --> Click "Next" to configure the stack details.
If you don't have a template, Choose "Use a sample Template" --> Select a Sample template, I'm selecting "LAMP Stack".
Specify the Stack details as follows and click on Next
Similarly, configure stack options as well. I'm leaving everything as default.
Finally, Review the template and submit
Once you click on Submit, you'll get the following screen as Stack Creation in progress
Possible Error: You may get into a database-related error while creating the stack.
Solution: While providing passwords use only alphanumeric passwords, No special characters.
After some time, you'll see Stack creation completed as follows.
Step 6: Enjoy Your "Trip"
Once the stack creation is complete, you can enjoy your AWS "vacation" with all the resources ready and waiting for you.
You can navigate to EC2, Database, and other resources to validate whether these resources are created or not.
The following is the EC2 validation.
Note: Make sure you delete the stack once the validation is completed. Or else we will end up paying bills to AWS.
With AWS CloudFormation, managing your AWS resources becomes as seamless as planning a dream vacation. You define your infrastructure as code, create CloudFormation stacks, and enjoy your AWS "journey" without any hiccups along the way.
Hope you find this blog helpful. Please share your thoughts in the comments it will help me to refine and provide more insightful content. Happy Learning!