{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "## Create Load Balancer Auto Scaled Apache Web Server\n", "\n", "In this workshop we will explore the basics of AWS with EC2, Amazon S3, and the components required for auto scaling that will provide elasticity and durability to tradtional web applications. Python is used extensively so you will need experience in or be comfortable reading python code. \n", "\n", "\n", "\n", "### Initialize notebook\n", "\n", "We will be using the [boto3](https://boto3.amazonaws.com/v1/documentation/api/latest/index.html) library for creation of all resources." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import boto3\n", "import sys\n", "import os\n", "import json\n", "import base64\n", "import project_path # path to helper methods\n", "import pprint\n", "\n", "from lib import workshop\n", "from botocore.exceptions import ClientError\n", "\n", "ec2_client = boto3.client('ec2')\n", "ec2 = boto3.resource('ec2')\n", "elb = boto3.client(\"elbv2\")\n", "cloudwatch = boto3.client('cloudwatch')\n", "asg = boto3.client('autoscaling')\n", "\n", "session = boto3.session.Session()\n", "region = session.region_name\n", "\n", "alb_sec_group_name = 'alb-sg'\n", "launch_config_name = 'web-lc'\n", "auto_scaling_group_name = 'web-asg'\n", "scale_up_name = 'scale_up'\n", "scale_down_name = 'scale_down'" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### [Create S3 Bucket](https://docs.aws.amazon.com/AmazonS3/latest/gsg/CreatingABucket.html)\n", "\n", "We will create an S3 bucket that will be used throughout the workshop for storing data.\n", "\n", "[s3.create_bucket](https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/s3.html#S3.Client.create_bucket) boto3 documentation" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "bucket = workshop.create_bucket_name('intro-')\n", "session.resource('s3').create_bucket(Bucket=bucket, CreateBucketConfiguration={'LocationConstraint': region})\n", "print(bucket)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### [Create VPC](https://aws.amazon.com/vpc/)\n", "\n", "Amazon Virtual Private Cloud (Amazon VPC) lets you provision a logically isolated section of the AWS Cloud where you can launch AWS resources in a virtual network that you define. You have complete control over your virtual networking environment, including selection of your own IP address range, creation of subnets, and configuration of route tables and network gateways. You can use both IPv4 and IPv6 in your VPC for secure and easy access to resources and applications." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "vpc, subnet, subnet2 = workshop.create_and_configure_vpc()\n", "vpc_id = vpc.id\n", "subnet_id = subnet.id\n", "subnet2_id = subnet2.id\n", "print(vpc_id)\n", "print(subnet_id)\n", "print(subnet2_id)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Create index.html page for the web application\n", "\n", "We will write out a simple html page to demo setting up the Apache web server using an Application Load Balancer and Auto Scaling to provide elasticity to your web application." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%%writefile index.html\n", "\n", "