Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added changes to mod 06 #48

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions 06-auto-scaling/.gitignore
@@ -0,0 +1 @@
fidelis.pem
26 changes: 26 additions & 0 deletions 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
44 changes: 44 additions & 0 deletions 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
45 changes: 45 additions & 0 deletions 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

55 changes: 55 additions & 0 deletions 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

54 changes: 54 additions & 0 deletions 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
21 changes: 21 additions & 0 deletions 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

6 changes: 6 additions & 0 deletions 06-auto-scaling/params.json
@@ -0,0 +1,6 @@
{
"Parameters": {
"LinuxAMI": "ami-052efd3df9dad4825",
"Ec2InstanceType": "t2.small"
}
}
124 changes: 124 additions & 0 deletions 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