Lab Infrastructure Automation using AWS CloudFormation

Sample Template:

Template1.yaml

AWSTemplateFormatVersion: 2010-09-09
Parameters:
KeyName:
Description: Name of existing EC2 KeyPair to enable SSH access into the Server
Type: AWS::EC2::KeyPair::KeyName
Mappings:
RegionMap:
us-east-1:
AMI: ami-1853ac65
us-west-1:
AMI: ami-bf5548df
eu-west-1:
AMI: ami-bf5548df
Resources:
VPC:
Type: AWS::EC2::VPC
Properties:
CidrBlock: 10.0.0.0/16
EnableDnsHostnames: true
Tags:
- Key: Name
Value: Lab VPC

WebServerSG:
Type: 'AWS::EC2::SecurityGroup'
Properties:
GroupDescription: Enable SSH access via port 22 and 80
VpcId: !Ref VPC
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: '22'
ToPort: '22'
CidrIp: 0.0.0.0/0
- IpProtocol: tcp
FromPort: '80'
ToPort: '80'
CidrIp: 0.0.0.0/0

EC2Instance:
Type: 'AWS::EC2::Instance'
Properties:
InstanceType: t2.micro
ImageId:
Fn::FindInMap:
- RegionMap
- !Ref AWS::Region
- AMI
SecurityGroupIds:
- !Ref WebServerSG
Tags:
-Key:"Name"
Value: Lab EC2
KeyName: !Ref KeyName
Outputs:
Website:
Description: Public DNS for EC2 EC2Instance
Value: !Sub 'http://${EC2Instance.PublicDnsName}'

Step 1:

For Windows(64-bit) download the AWS CLI MSI installer from the link below:

Step 2:

To configure the AWS CLI you need Access Key ID and Secret Access Key. To generate Access Key ID and Secret Access Key login to your AWS Console. In the navigation pane choose Users. Click on Security Credentials tab and in Access Keys section click on Create New Access Key and download the CSV file.

Step 3:

Next step, in the command prompt write command aws configure and press enter which is shown below.

AWS Access Key: AKIAIOSFODNN7EXAMPLE 
AWS Secret Access Key ID: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
Default region name: us-east-1
Default output format: json
aws cloudformation create-stack --stack-name RDS --template-body file://C:\ AWS\Template1.yaml –parameters ParameterKey=KeyName,ParameterValue=demo
aws cloudformation delete-stack --stack-name YourStackName

Final Outcome of the Project

In this part I would be showing you the final result of the project and how users can use it to have hands-on practice for the various AWS resources.

Homepage of the AWSLAB
Instructions page for lab of Hosting WordPress
Snapshot of the resources been created in the backend
The created resources been deleted

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Nidhi Gajjar

Nidhi Gajjar

26 Followers

2X AWS Certified, Student at Charotar University of Science and Technology, AWS Cloud Enthusiastic