Skip to content
This repository has been archived by the owner on Oct 2, 2023. It is now read-only.

Commit

Permalink
added lab about costs
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelwittig committed Apr 21, 2017
1 parent f030d33 commit a2bd2f1
Show file tree
Hide file tree
Showing 3 changed files with 299 additions and 0 deletions.
21 changes: 21 additions & 0 deletions lab10-estimate-costs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Lab 10: Estimate Costs

Use a CloudFormationtemplate to calculate the monthly costs.

## Overview
1. Estimate costs of an CloudFormation template.

## Instructions
1. Open [CloudFormation](https://console.aws.amazon.com/cloudformation) in AWS Management Console.
1. Click **Create Stack** button.
1. Select **Upload a template to Amazon S3**.
1. Choose file ``learn-cloudformation/lab10-estimate-costs/demo.yaml``.
1. Click **Next** button.
1. Insert ``lab10-$username``as stack name. Replace ``$username`` with your username (e.g. lab10-awittig).
1. Select two random subnets and the only available VPC as **Parameters**.
1. Click **Next** button.
1. Skip next step by clicking on **Next** button.
1. Under **Estimate cost**, you will find a **Cost** link. CLick this link. A new tab will open
1. Explore the calculated costs.
1. Go back to the CLoudFormation tab and click **Cancel** to stop exit the wizzard.
1. Congratulations! You are done with the lab!
147 changes: 147 additions & 0 deletions lab10-estimate-costs/demo.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "Estimate Costs",
"Parameters": {
"VPCParameter": {
"Description": "VPC to launch instances into",
"Type": "AWS::EC2::VPC::Id"
},
"SubnetsParameter": {
"Description": "Subnets to launch instances into",
"Type": "List<AWS::EC2::Subnet::Id>"
}
},
"Mappings": {
"RegionMap": {
"eu-west-1": {"AMI": "ami-bff32ccc"},
"ap-southeast-1": {"AMI": "ami-c9b572aa"},
"ap-southeast-2": {"AMI": "ami-48d38c2b"},
"eu-central-1": {"AMI": "ami-bc5b48d0"},
"ap-northeast-2": {"AMI": "ami-249b554a"},
"ap-northeast-1": {"AMI": "ami-383c1956"},
"us-east-1": {"AMI": "ami-60b6c60a"},
"sa-east-1": {"AMI": "ami-6817af04"},
"us-west-1": {"AMI": "ami-d5ea86b5"},
"us-west-2": {"AMI": "ami-f0091d91"}
}
},
"Resources": {
"ELBSecurityGroup": {
"Type": "AWS::EC2::SecurityGroup",
"Properties": {
"GroupDescription": "elb-sg",
"SecurityGroupEgress": [{
"IpProtocol": "-1",
"CidrIp": "0.0.0.0/0"
}],
"SecurityGroupIngress": [{
"CidrIp": "0.0.0.0/0",
"FromPort": 80,
"IpProtocol": "tcp",
"ToPort": 80
}],
"VpcId": {"Ref": "VPCParameter"}
}
},
"ELB": {
"Type": "AWS::ElasticLoadBalancing::LoadBalancer",
"Properties": {
"ConnectionDrainingPolicy": {
"Enabled": true,
"Timeout": 30
},
"CrossZone": true,
"HealthCheck": {
"HealthyThreshold": "2",
"Interval": "10",
"Target": "HTTP:80/",
"Timeout": "5",
"UnhealthyThreshold": "2"
},
"LoadBalancerName": "elb",
"Listeners": [{
"InstancePort": "80",
"InstanceProtocol": "HTTP",
"LoadBalancerPort": "80",
"Protocol": "HTTP"
}],
"Scheme": "internet-facing",
"SecurityGroups": [{"Ref": "ELBSecurityGroup"}],
"Subnets": {"Ref": "SubnetsParameter"}
}
},
"EC2SecurityGroup": {
"Type": "AWS::EC2::SecurityGroup",
"Properties": {
"GroupDescription": "ec2-sg",
"SecurityGroupEgress": [{
"IpProtocol": "-1",
"CidrIp": "0.0.0.0/0"
}],
"SecurityGroupIngress": [{
"CidrIp": "0.0.0.0/0",
"FromPort": 22,
"IpProtocol": "tcp",
"ToPort": 22
}, {
"FromPort": 80,
"IpProtocol": "tcp",
"SourceSecurityGroupId": {"Ref": "ELBSecurityGroup"},
"ToPort": 80
}],
"VpcId": {"Ref": "VPCParameter"}
}
},
"LaunchConfiguration": {
"Type": "AWS::AutoScaling::LaunchConfiguration",
"Properties": {
"AssociatePublicIpAddress": true,
"ImageId": {"Fn::FindInMap": ["RegionMap", {"Ref": "AWS::Region"}, "AMI"]},
"InstanceType": "t2.micro",
"SecurityGroups": [{"Ref": "EC2SecurityGroup"}],
"UserData": {"Fn::Base64": {"Fn::Join": ["", [
"#!/bin/bash -ex", "\n",
"yum -y install httpd", "\n",
"chkconfig httpd on", "\n",
{"Fn::Sub": "echo \"<!DOCTYPE html><html><head><title>Version 1</title><meta http-equiv=\\\"refresh\\\" content=\\\"3\\\"></head><body>Version 1</body></html>\" >> /var/www/html/index.html"}, "\n",
"service httpd start", "\n",
"/opt/aws/bin/cfn-signal -e 0 --region ", {"Ref": "AWS::Region"}, " --stack ", {"Ref": "AWS::StackName"}, " --resource AutoScalingGroup", "\n"
]]}}
}
},
"AutoScalingGroup": {
"Type": "AWS::AutoScaling::AutoScalingGroup",
"Properties": {
"MinSize": "1",
"MaxSize": "2",
"DesiredCapacity": "1",
"LaunchConfigurationName": {"Ref": "LaunchConfiguration"},
"VPCZoneIdentifier": {"Ref": "SubnetsParameter"},
"LoadBalancerNames": [{"Ref": "ELB"}],
"HealthCheckGracePeriod": 60,
"HealthCheckType": "ELB"
},
"CreationPolicy": {
"ResourceSignal": {
"Count": 1,
"Timeout": "PT10M"
}
},
"UpdatePolicy": {
"AutoScalingRollingUpdate": {
"MaxBatchSize": "2",
"MinInstancesInService": "1",
"PauseTime": "PT10M",
"SuspendProcesses": ["AlarmNotification"],
"WaitOnResourceSignals": true
}
}
}
},
"Outputs": {
"ELB": {
"Value": {"Fn::Join": ["", ["http://", {"Fn::GetAtt": ["ELB", "DNSName"]}]]},
"Description": "Load Balancer URL"
}
}
}
131 changes: 131 additions & 0 deletions lab10-estimate-costs/demo.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
---
AWSTemplateFormatVersion: '2010-09-09'
Description: Estimate Costs
Parameters:
VPCParameter:
Description: VPC to launch instances into
Type: AWS::EC2::VPC::Id
SubnetsParameter:
Description: Subnets to launch instances into
Type: List<AWS::EC2::Subnet::Id>
Mappings:
RegionMap:
eu-west-1:
AMI: ami-bff32ccc
ap-southeast-1:
AMI: ami-c9b572aa
ap-southeast-2:
AMI: ami-48d38c2b
eu-central-1:
AMI: ami-bc5b48d0
ap-northeast-2:
AMI: ami-249b554a
ap-northeast-1:
AMI: ami-383c1956
us-east-1:
AMI: ami-60b6c60a
sa-east-1:
AMI: ami-6817af04
us-west-1:
AMI: ami-d5ea86b5
us-west-2:
AMI: ami-f0091d91
Resources:
ELBSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: elb-sg
SecurityGroupEgress:
- IpProtocol: "-1"
CidrIp: 0.0.0.0/0
SecurityGroupIngress:
- CidrIp: 0.0.0.0/0
FromPort: 80
IpProtocol: tcp
ToPort: 80
VpcId:
Ref: VPCParameter
ELB:
Type: AWS::ElasticLoadBalancing::LoadBalancer
Properties:
ConnectionDrainingPolicy:
Enabled: true
Timeout: 30
CrossZone: true
HealthCheck:
HealthyThreshold: '2'
Interval: '10'
Target: HTTP:80/
Timeout: '5'
UnhealthyThreshold: '2'
LoadBalancerName: elb
Listeners:
- InstancePort: '80'
InstanceProtocol: HTTP
LoadBalancerPort: '80'
Protocol: HTTP
Scheme: internet-facing
SecurityGroups:
- !Ref ELBSecurityGroup
Subnets: !Ref SubnetsParameter
EC2SecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: ec2-sg
SecurityGroupEgress:
- IpProtocol: "-1"
CidrIp: 0.0.0.0/0
SecurityGroupIngress:
- CidrIp: 0.0.0.0/0
FromPort: 22
IpProtocol: tcp
ToPort: 22
- FromPort: 80
IpProtocol: tcp
SourceSecurityGroupId: !Ref ELBSecurityGroup
ToPort: 80
VpcId: !Ref VPCParameter
LaunchConfiguration:
Type: AWS::AutoScaling::LaunchConfiguration
Properties:
AssociatePublicIpAddress: true
ImageId: !FindInMap [RegionMap, !Ref 'AWS::Region', AMI]
InstanceType: t2.micro
SecurityGroups:
- !Ref EC2SecurityGroup
UserData:
'Fn::Base64': !Sub |
#!/bin/bash -ex
yum -y install httpd
chkconfig httpd on
echo "<!DOCTYPE html><html><head><title>Version 1</title><meta http-equiv=\"refresh\" content=\"3\"></head><body>Version 1</body></html>" >> /var/www/html/index.html
service httpd start
/opt/aws/bin/cfn-signal -e 0 --region ${AWS::Region} --stack ${AWS::StackName} --resource AutoScalingGroup
AutoScalingGroup:
Type: AWS::AutoScaling::AutoScalingGroup
Properties:
MinSize: '1'
MaxSize: '2'
DesiredCapacity: '1'
LaunchConfigurationName: !Ref LaunchConfiguration
VPCZoneIdentifier: !Ref SubnetsParameter
LoadBalancerNames:
- !Ref ELB
HealthCheckGracePeriod: 60
HealthCheckType: ELB
CreationPolicy:
ResourceSignal:
Count: 1
Timeout: PT10M
UpdatePolicy:
AutoScalingRollingUpdate:
MaxBatchSize: '2'
MinInstancesInService: '1'
PauseTime: PT10M
SuspendProcesses:
- AlarmNotification
WaitOnResourceSignals: true
Outputs:
ELB:
Value: !Sub http://${ELB.DNSName}
Description: Load Balancer URL

0 comments on commit a2bd2f1

Please sign in to comment.