diff --git a/06-auto-scaling/.gitignore b/06-auto-scaling/.gitignore new file mode 100644 index 00000000..dc477e95 --- /dev/null +++ b/06-auto-scaling/.gitignore @@ -0,0 +1 @@ +fidelis.pem diff --git a/06-auto-scaling/asg-6-1-1.yaml b/06-auto-scaling/asg-6-1-1.yaml new file mode 100644 index 00000000..6e851877 --- /dev/null +++ b/06-auto-scaling/asg-6-1-1.yaml @@ -0,0 +1,26 @@ +AWSTemplateFormatVersion: 2010-09-09 +Description: Create basic ec2 instance + +Parameters: + LinuxAMI: + Type: String + Description: AMI ID for ec2 instance + + Ec2InstanceType: + Type: String + Description: Instance Type for ec2 + +Resources: + myEc2Instance: + Type: AWS::EC2::Instance + Properties: + ImageId: !Ref LinuxAMI + InstanceType: t2.micro + KeyName: fidelis + SubnetId: !ImportValue fidelisPubSubnet + SecurityGroupIds: + - !ImportValue InstancegroupID +Outputs: + InstanceID: + Description: Instance ID of ec2 instance + Value: !Ref myEc2Instance diff --git a/06-auto-scaling/asg-6-1-2.yaml b/06-auto-scaling/asg-6-1-2.yaml new file mode 100644 index 00000000..9fce003f --- /dev/null +++ b/06-auto-scaling/asg-6-1-2.yaml @@ -0,0 +1,44 @@ +AWSTemplateFormatVersion: 2010-09-09 +Description: Create basic ec2 instance + +Parameters: + LinuxAMI: + Type: String + Description: AMI ID for ec2 instance + + Ec2InstanceType: + Type: String + Description: Instance Type for ec2 + + LaunchTemplateVersionNumber: + Default: 1 + Type: String + +Resources: + + MyLaunchTemplate: + Type: AWS::EC2::LaunchTemplate + Properties: + LaunchTemplateData: + KeyName: fidelis + InstanceType: !Ref Ec2InstanceType + ImageId: !Ref LinuxAMI + TagSpecifications: + - ResourceType: instance + Tags: + - Key: user + Value: fidelis.ogunsanmi.labs + - Key: "stelligent-u-lesson" + Value: "6" + + MyAutoScalingGroup: + Type: AWS::AutoScaling::AutoScalingGroup + Properties: + MinSize: '1' + MaxSize: '1' + DesiredCapacity: '1' + LaunchTemplate: + LaunchTemplateId: !Ref MyLaunchTemplate + Version: !Ref LaunchTemplateVersionNumber + VPCZoneIdentifier: + - !ImportValue fidelisPubSubnet diff --git a/06-auto-scaling/asg-6-1-3.yaml b/06-auto-scaling/asg-6-1-3.yaml new file mode 100644 index 00000000..78f42c66 --- /dev/null +++ b/06-auto-scaling/asg-6-1-3.yaml @@ -0,0 +1,45 @@ +AWSTemplateFormatVersion: 2010-09-09 +Description: Create basic ec2 instance + +Parameters: + LinuxAMI: + Type: String + Description: AMI ID for ec2 instance + + Ec2InstanceType: + Type: String + Description: Instance Type for ec2 + + LaunchTemplateVersionNumber: + Default: 1 + Type: String + +Resources: + + MyLaunchTemplate: + Type: AWS::EC2::LaunchTemplate + Properties: + LaunchTemplateData: + KeyName: fidelis + InstanceType: t2.small + ImageId: !Ref LinuxAMI + TagSpecifications: + - ResourceType: instance + Tags: + - Key: user + Value: fidelis.ogunsanmi.labs + - Key: "stelligent-u-lesson" + Value: "6" + + MyAutoScalingGroup: + Type: AWS::AutoScaling::AutoScalingGroup + Properties: + MinSize: '1' + MaxSize: '1' + DesiredCapacity: '1' + LaunchTemplate: + LaunchTemplateId: !Ref MyLaunchTemplate + Version: !Ref LaunchTemplateVersionNumber + VPCZoneIdentifier: + - !ImportValue fidelisPubSubnet + diff --git a/06-auto-scaling/asg-6-1-4.yaml b/06-auto-scaling/asg-6-1-4.yaml new file mode 100644 index 00000000..7ab6daed --- /dev/null +++ b/06-auto-scaling/asg-6-1-4.yaml @@ -0,0 +1,55 @@ +AWSTemplateFormatVersion: 2010-09-09 +Description: Create basic ec2 instance + +Parameters: + LinuxAMI: + Type: String + Description: AMI ID for ec2 instance + + Ec2InstanceType: + Type: String + Description: Instance Type for ec2 + + LaunchTemplateVersionNumber: + Default: 1 + Type: String + +Resources: + + MyLaunchTemplate: + Type: AWS::EC2::LaunchTemplate + Properties: + LaunchTemplateData: + KeyName: fidelis + InstanceType: t2.medium + ImageId: !Ref LinuxAMI + TagSpecifications: + - ResourceType: instance + Tags: + - Key: user + Value: fidelis.ogunsanmi.labs + - Key: "stelligent-u-lesson" + Value: "6" + + MyAutoScalingGroup: + Type: AWS::AutoScaling::AutoScalingGroup + UpdatePolicy: + AutoScalingReplacingUpdate: + WillReplace: true + Properties: + MinSize: '1' + MaxSize: '1' + DesiredCapacity: '1' + LaunchTemplate: + LaunchTemplateId: !Ref MyLaunchTemplate + Version: !Ref LaunchTemplateVersionNumber + VPCZoneIdentifier: + - !ImportValue fidelisPubSubnet + Tags: + - Key: user + Value: fidelis.ogunsanmi.labs + PropagateAtLaunch: true + - Key: "stelligent-u-lesson" + Value: "6" + PropagateAtLaunch: true + diff --git a/06-auto-scaling/asg-6-2-2.yaml b/06-auto-scaling/asg-6-2-2.yaml new file mode 100644 index 00000000..7781113a --- /dev/null +++ b/06-auto-scaling/asg-6-2-2.yaml @@ -0,0 +1,54 @@ +AWSTemplateFormatVersion: 2010-09-09 +Description: Create basic ec2 instance + +Parameters: + LinuxAMI: + Type: String + Description: AMI ID for ec2 instance + + Ec2InstanceType: + Type: String + Description: Instance Type for ec2 + + LaunchTemplateVersionNumber: + Default: 1 + Type: String + +Resources: + + MyLaunchTemplate: + Type: AWS::EC2::LaunchTemplate + Properties: + LaunchTemplateData: + KeyName: fidelis + InstanceType: t2.medium + ImageId: !Ref LinuxAMI + TagSpecifications: + - ResourceType: instance + Tags: + - Key: user + Value: fidelis.ogunsanmi.labs + - Key: "stelligent-u-lesson" + Value: "6" + + MyAutoScalingGroup: + Type: AWS::AutoScaling::AutoScalingGroup + UpdatePolicy: + AutoScalingReplacingUpdate: + WillReplace: true + Properties: + MinSize: '1' + MaxSize: '3' + DesiredCapacity: '2' + LaunchTemplate: + LaunchTemplateId: !Ref MyLaunchTemplate + Version: !Ref LaunchTemplateVersionNumber + VPCZoneIdentifier: + - !ImportValue fidelisPubSubnet + Tags: + - Key: user + Value: fidelis.ogunsanmi.labs + PropagateAtLaunch: true + - Key: "stelligent-u-lesson" + Value: "6" + PropagateAtLaunch: true \ No newline at end of file diff --git a/06-auto-scaling/exec.sh b/06-auto-scaling/exec.sh new file mode 100755 index 00000000..fd0686db --- /dev/null +++ b/06-auto-scaling/exec.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +PROFILE="labmfa" +STACK_NAME="fidelisvPC" +TEMPLATE="vpc.yaml" +PARAMETER="file://params.json" +KEY_NAME="fidelis" +REGION="us-east-1" + +# deploy stack +aws cloudformation deploy --template-file $TEMPLATE \ + --stack-name $STACK_NAME --profile $PROFILE \ + --parameter-overrides $PARAMETER \ + --region $REGION + +# create ec2 keypair +# aws ec2 create-key-pair --key-name $KEY_NAME \ +# --query 'KeyMaterial' \ +# --region $REGION --profile $PROFILE \ +# --output text > fidelis.pem + diff --git a/06-auto-scaling/params.json b/06-auto-scaling/params.json new file mode 100644 index 00000000..035a037a --- /dev/null +++ b/06-auto-scaling/params.json @@ -0,0 +1,6 @@ +{ + "Parameters": { + "LinuxAMI": "ami-052efd3df9dad4825", + "Ec2InstanceType": "t2.small" + } +} \ No newline at end of file diff --git a/06-auto-scaling/vpc.yaml b/06-auto-scaling/vpc.yaml new file mode 100644 index 00000000..ea7868ae --- /dev/null +++ b/06-auto-scaling/vpc.yaml @@ -0,0 +1,124 @@ +AWSTemplateFormatVersion: "2010-09-09" + +Description: This template creates an autoscaling group with EC2 instances in a VPC with 2 public subnets. The instances have an apache web server installed. + +Parameters: + + SSHLocation: + AllowedPattern: '(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})/(\d{1,2})' + ConstraintDescription: must be a valid IP CIDR range of the form x.x.x.x/x. + Default: 0.0.0.0/0 + Description: The IP address range that can be used to access the web server using SSH. + MaxLength: '18' + MinLength: '9' + Type: String + +Resources: + VPC: + Type: AWS::EC2::VPC + Properties: + CidrBlock: 192.168.0.0/16 + EnableDnsHostnames: True + EnableDnsSupport: True + InstanceTenancy: default + + InternetGateway: + Type: AWS::EC2::InternetGateway + Properties: + Tags: + - Key: Name + Value: fidelisGW + + InternetGatewayAttachment: + Type: AWS::EC2::VPCGatewayAttachment + Properties: + InternetGatewayId: !Ref InternetGateway + VpcId: !Ref VPC + + PublicSubnet: + Type: AWS::EC2::Subnet + Properties: + AvailabilityZone: !Select [ 0, !GetAZs '' ] + CidrBlock: 192.168.0.0/24 + MapPublicIpOnLaunch: true + Tags: + - Key: Name + Value: Public Subnet 1 + VpcId: !Ref VPC + + PublicSubnet2: + Type: AWS::EC2::Subnet + Properties: + AvailabilityZone: !Select [ 1, !GetAZs '' ] + CidrBlock: 192.168.1.0/24 + MapPublicIpOnLaunch: true + Tags: + - Key: Name + Value: Public Subnet 2 + VpcId: !Ref VPC + + PublicRouteTable: + Type: AWS::EC2::RouteTable + Properties: + Tags: + - Key: Name + Value: PublicRouteTable + VpcId: !Ref VPC + + PublicRoute: + Type: AWS::EC2::Route + DependsOn: InternetGatewayAttachment + Properties: + DestinationCidrBlock: 0.0.0.0/0 + GatewayId: !Ref InternetGateway + RouteTableId: !Ref PublicRouteTable + + PublicSubnet1RouteTableAssociation: + Type: AWS::EC2::SubnetRouteTableAssociation + Properties: + RouteTableId: !Ref PublicRouteTable + SubnetId: !Ref PublicSubnet + + PublicSubnet2RouteTableAssociation: + Type: AWS::EC2::SubnetRouteTableAssociation + Properties: + RouteTableId: !Ref PublicRouteTable + SubnetId: !Ref PublicSubnet2 + + InstanceSecurityGroup: + Type: AWS::EC2::SecurityGroup + Properties: + GroupDescription: Open HTTP (port 80) and SSH (port 22) + VpcId: !Ref VPC + SecurityGroupIngress: + - IpProtocol: tcp + FromPort: 80 + ToPort: 80 + CidrIp: 0.0.0.0/0 + - IpProtocol: tcp + FromPort: 22 + ToPort: 22 + CidrIp: !Ref SSHLocation + +Outputs: + VpcID: + Description: VPC ID + Value: !Ref VPC + Export: + Name: fidelisVpc + + PublicSubnetId: + Value: !Ref PublicSubnet + Export: + Name: fidelisPubSubnet + + PublicSubnet2Id: + Value: !Ref PublicSubnet2 + Export: + Name: fidelisPubSubnet2 + + SecuritygroupID: + Value: !Ref InstanceSecurityGroup + Export: + Name: InstancegroupID +