Skip to main content


Showing posts from October 15, 2022

AWS CloudFormation - Parameters

Greetings! In my previous post, I talked about creating a EC2 instance using CloudFormation. However, it is not that reusable because values are hard coded. Better way to do that is by using Parameters. Parameters is an optional section in the template that enable us to get user input custom values for our template. Let's define a Parameter Parameters section has following form. Parameters: ParameterLogicalID: Type: DataType ParameterProperty: value For an example we can get our security group description as an use input. Parameters: EC2SecurityGroupDescription: Type: String Description: Allow SSH access to the EC2 instance. How to Reference a Parameter The Fn::Ref function can be leveraged to reference parameters. The shorthand for this in YAML is !Ref. !Ref EC2SecurityGroupDescription Parameter Type Parameter types are String, Number, CommaDelimetedList, List, AWS specific parameter like "AWS::EC2::VPC::Id", List, S

Let's create an EC2 instance with AWS CloudFormation

Greetings In my previous post, I talked briefly about gettings started with CloudFormation. The best way to learn anything is to do practicals. Hence, let's create an EC2 instance with CloudFormation. What are we going to do? Create an EC2 Set the KeyPair Create a SecurityGroup Add SecurityGroup to EC2 Create an EC2 with CloudFormation When we create an EC2 instance with CloudFormation, we can supply the ImageId and InstanceType. We can supply many more properties but for this example, we are not going to use them. Hence all those will default. This means our EC2 instance will be created on default VPC with default configurations. When you manually create an EC2 instance using the AWS console, you can see ImageId for your InstanceType. Copy it and paste it into the CloudFormation file. cfn-ec2.yml AWSTemplateFormatVersion: 2010-09-09 MyEC2Instance: Type: AWS::EC2::Instance Properties: InstanceType: t2.micro ImageId: ami-05fa00d4c63e32376 Step two is to

Getting Started with AWS CloudFormation

Greetings! AWS CloudFormation is an infrastructure as code (IaC) solution by AWS to model, provision, and manage AWS resources. Thus, giving us more time to focus on our applications that run in AWS. What we do is create a template in YAML or JSON format that describes all the resources we want to create, and CloudFormation takes to create it. We are free of manual work. Without too much theory, let's create an S3 bucket using CloudFormation. We don't have to worry about notations when we get started. Steps Define the CloudFormation template Upload it to AWS An IaC S3 Bucket First of all, let's create our template (cfn-s3.yml) Resources: HelloBucket: Type: AWS::S3::Bucket Step two is to upload this to AWS. Go to AWS CloudFormation Click on Stacks Click on Create stack -> with new resources Choose "Template is ready" Choose "Upload a file"