Install LAMP Stack Using Cloud Formation

01 / Jul / 2014 by Vikash Jha 0 comments
AWS Cloud formation  is a service used to create and manage a collection of other AWS services. This service is used to automate the infrastructure setup and deployment.

In this article, we will be launching a LAMP Stack Instance using Cloud Formation. For this we are using Ubuntu Server 14.04 LTS (PV) – ami-9a7724c8 (64-bit)


Steps to Launch:


1) Create a .json file
2) Open AWS Console
3) Browse to Cloudformation, CREATE STACK and upload the .json file


Create a .json file

{
 "Resources" :
    {
    "WebServer":{

      "Type": "AWS::EC2::Instance",
         "Properties":{
         "ImageId" : "ami-9a7724c8",
         "KeyName" : "demo",
         "InstanceType":"t1.micro",
         "SecurityGroups" : [ "demo" ],
         "UserData" : {"Fn::Base64" : {"Fn::Join" : ["", [
           "#!/bin/bash\n",
           "# Launching Instance",
           "apt-get -y install apache2 \n",
           "apt-get -y install mysql \n",
           "apt-get -y install mysql-server \n",
           "apt-get -y install php php5-mysql \n"
            ] ] } }
        }
    }
 },
 "Outputs":{
    "WebsiteURL" : {
      "Value" : { "Fn::Join" : ["", ["http://", { "Fn::GetAtt" : [        "WebServer", "PublicDnsName" ]}]] },
        "Description" : "URL for newly created LAMP stack"
   }
 }
}
 **Note: Keyname and Security groups must exists on your account 

Open AWS Console > Browse to Cloud Formation >Create Stack

cloudformation2

Once you click Create Stack button, it will ask for the Stack Name and the .json file.

cloudformation3

Upload the .json file and Follow the wizard. The next wizard ask you to enter the Key Value name for the Instance:

cloudfomration4

Click the Next Button and the launch the stack. Once you launch the stack, you will get the following screen with launching process events.

cloudformation6

If everything goes well, you will get the the CREATE_COMPLETE message in the Status Tab. If any error occurs then a ROLLBACK event is invoked which will delete the stack.

Since we got the CREATE_COMPLETE message with a output parameter that we have defined in our json which returns the public DNS name of the Instance.

cloudformation7

By Clicking on the output URL, it takes us to the apache default page:

cloudformation12

We can check the Console to see our running Instances:

cloudformation10

We can see the Public DNS is same.

To Terminate this Instance we can delete the stack from the Cloud Formation Wizard. Deleting the stack will terminate all the instances launched by that stack.

cloudformation11

cloudformation13

FOUND THIS USEFUL? SHARE IT

Leave a comment -