Skip to content
fpelaezt edited this page Mar 25, 2018 · 10 revisions

InfraAsCode Pyxis Exercise

This project creates the following infrastructure using automation technologies.

Networking Layer

The networking layer includes the following components:

  • VPC
  • Availability Zones
  • IGW
  • NAT Gateway

This was achived by creating a CloudFormation template. The template file can be located in the following link: NetworkStackPyxis

The template export some properties that can be used by others CFTemplates, for instance

VPCID
SubnetsID
AvailabilitiesZonesID

Servers Layer

The servers layer includes the following components:

  • Two Bastion Servers in two different AZ with public address
  • Web Instances in two different AZ without puclick address
  • Security Group for Bastion Servers
  • Security Group for Web Servers
  • Elastic Load Balancer

This was achived by creating another CF Template SeverStackPyxis

Replication steps

Follow these steps to recreate the infrastructure in AWS

####Pre-requisistes

  • Create a KeyPair called DevOps01
  • Configure AWS SDK using Python in Region "us-west-2"

####Steps

Table

aws iam list-users --output table
---------------------------------------------------------------------
|                             ListUsers                             |
+-------------------------------------------------------------------+
||                              Users                              ||
|+-------------------+---------------------------------------------+|
||  Arn              |  arn:aws:iam::372390662882:user/fpelaezt01  ||
||  CreateDate       |  2018-02-10T00:43:11Z                       ||
||  PasswordLastUsed |  2018-02-13T00:37:05Z                       ||
||  Path             |  /                                          ||
||  UserId           |  AIDAJ32DS2W7Q4LBJTKW2                      ||
||  UserName         |  fpelaezt01                                 ||
|+-------------------+---------------------------------------------+|
  • Change to Python directory on your local computer
cd pyxis/Python
$ ls -l
total 4
-rw-r--r-- 1 Usuario 197121 1025 mar. 25 13:16 PyxisAutomation.py
  • Run the following Python Script File
$ cat PyxisAutomation.py
import boto3
import sys

def create_stack(stack_name,file_path):
    print("Starting stack creation")
    # open the test file from the current diectory
    template = open(file_path).read()
    # create the boto3 cloudformation client
    cloudformation = boto3.client("cloudformation")
    # create the new stack
    cloudformation.create_stack(StackName=stack_name,TemplateBody=template)
    # create the new waiter
    waiter = cloudformation.get_waiter('stack_create_complete')
    # wait until the stack state changes to "CREATE_COMPLETE"
    waiter.wait(StackName=stack_name)
    print("StackName '" + stack_name + "' was created sucessfully")

def main():
    #Create NetworkLayer
    print("Starting Network stack creation")
    create_stack('NetworkStackPyxis',file_path = '../CFTemplates/NetworkingLayer-Pyxis.yml')
    #Create ServerLayer
    print("Starting Server stack creation")
    create_stack('ServersStackPyxis',file_path = '../CFTemplates/ServersLayer-Pyxis.yml')

if __name__ == "__main__":
    main()
  • Running the script
    $ py PyxisAutomation.py
    Starting Network stack creation
    Starting stack creation
    StackName 'NetworkStackPyxis' was created sucessfully
    Starting Server stack creation
    Starting stack creation
    StackName 'ServersStackPyxis' was created sucessfully

Evidences

Stacks created successfully

VPC created successfully

Connect to BastionPublic

EC2Instances

ELB

To-Do

The following list shows the next-steps or improvements in the automation process.

  • Define Region
  • Define AMI in Region
  • Define KeyPair
  • Create DB Instance
  • Deploy Web application
Clone this wiki locally