├── AutoScalingLessonPart2 ├── autoscalingLifecycleHooks.sh └── readme ├── AutoScalingWithSQS └── CLICommands ├── CanaryDeployment ├── mathCeil.js └── mathFloor.js ├── CrossStack ├── Network.json └── webapp.json ├── Drift Detection ├── afterdriftupdate.json └── ec24drift.json ├── Lambda Aliases ├── AWS Lambda Aliases Lab Commands.docx └── amilookup.js ├── Lambda ├── index.js ├── readme └── samTemplate.yaml ├── Nested Stacks ├── error.html ├── index.html ├── rootstack.json └── s3static.json ├── StackPolicies ├── stackpolicies.json └── wordpress-single-instance.yaml ├── VPC Endpoints for S3 └── readme ├── lamp-stack-1478287817_1530269327 (3).json ├── lifecyclehooks └── userdataForLifeCycleHooks.sh └── userdataForLifeCycleHooks.sh /AutoScalingLessonPart2/autoscalingLifecycleHooks.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | yum update -y && \ 3 | yum install stress -y && \ 4 | INSTANCE_ID="`wget -q -O - http://instance-data/latest/meta-data/instance-id`" && \ 5 | aws autoscaling complete-lifecycle-action --lifecycle-action-result CONTINUE --instance-id $INSTANCE_ID --lifecycle-hook-name devops-pro-hook --auto-scaling-group-name devopsASG --region us-east-1 || \ 6 | aws autoscaling complete-lifecycle-action --lifecycle-action-result ABANDON --instance-id $INSTANCE_ID --lifecycle-hook-name devops-pro-hook --auto-scaling-group-name devopsASG --region us-east-1 7 | -------------------------------------------------------------------------------- /AutoScalingLessonPart2/readme: -------------------------------------------------------------------------------- 1 | Please note, the bash script in this folder is for the Lesson (not the Lab) named 'Auto Scaling Lifecycle Hooks Part 2'. 2 | The bash scripts for the lesson and the lab are different. The script is ONLY for the lesson. 3 | -------------------------------------------------------------------------------- /AutoScalingWithSQS/CLICommands: -------------------------------------------------------------------------------- 1 | aws autoscaling put-scaling-policy --policy-name sqs-scaleout --auto-scaling-group-name ASG4SQS --scaling-adjustment 1 --adjustment-type ChangeInCapacity 2 | 3 | aws autoscaling put-scaling-policy --policy-name sqs-scalein --auto-scaling-group-name ASG4SQS --scaling-adjustment -1 --adjustment-type ChangeInCapacity 4 | 5 | aws cloudwatch put-metric-alarm --alarm-name AddCapacityToProcessQueue --metric-name ApproximateNumberOfMessagesVisible --namespace “AWS/SQS” --statistic Average --period 300 --threshold 3 --comparison-operator GreaterThanOrEqualToThreshold --dimensions Name=QueueName, Value=SQS4ASG.fifo --evaluation-periods 2 --alarm-actions arn:aws:::scalingPolicy::autoScalingGroupName/ASG4SQS:policyName/sqs-scaleout 6 | 7 | aws cloudwatch put-metric-alarm --alarm-name RemoveCapacityFromProcessQueue --metric-name ApproximateNumberOfMessagesVisible --namespace “AWS/SQS” --statistic Average --period 300 --threshold 1 --comparison-operator LessThanOrEqualToThreshold --dimensions Name=QueueName, Value=SQS4ASG.fifo --evaluation-periods 2 --alarm-actions arn:aws:::scalingPolicy::autoScalingGroupName/ASG4SQS:policyName/sqs-scalein 8 | 9 | aws cloudwatch describe-alarms --alarm-names AddCapacityToProcessQueue RemoveCapacityFromProcessQueue 10 | 11 | aws autoscaling describe-policies --auto-scaling-group-name ASG4SQS 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /CanaryDeployment/mathCeil.js: -------------------------------------------------------------------------------- 1 | console.log('Loading Lambda function'); 2 | 3 | exports.handler = async (event, context, callback) => { 4 | let resultNum = Math.ceil(999.99); 5 | 6 | callback(null, 'this is the original function (Math.ceil) = ' + resultNum); 7 | }; -------------------------------------------------------------------------------- /CanaryDeployment/mathFloor.js: -------------------------------------------------------------------------------- 1 | console.log('Loading Lambda function'); 2 | 3 | exports.handler = async (event, context, callback) => { 4 | let resultNum = Math.floor(999.99); 5 | 6 | callback(null, 'this is the canary function (Math.floor) = ' + resultNum); 7 | }; -------------------------------------------------------------------------------- /CrossStack/Network.json: -------------------------------------------------------------------------------- 1 | { 2 | "AWSTemplateFormatVersion" : "2010-09-09", 3 | "Description" : "AWS CloudFormation Sample Template VPC_with_PublicIPs_And_DNS: Sample template that creates a VPC with DNS and public IPs enabled. Note that you are billed for the AWS resources that you use when you create a stack from this template.", 4 | "Resources" : { 5 | "VPC" : { 6 | "Type" : "AWS::EC2::VPC", 7 | "Properties" : { 8 | "EnableDnsSupport" : "true", 9 | "EnableDnsHostnames" : "true", 10 | "CidrBlock" : "10.0.0.0/16" 11 | } 12 | }, 13 | "PublicSubnet" : { 14 | "Type" : "AWS::EC2::Subnet", 15 | "Properties" : { 16 | "VpcId" : { "Ref" : "VPC" }, 17 | "CidrBlock" : "10.0.0.0/24" 18 | } 19 | }, 20 | "InternetGateway" : { 21 | "Type" : "AWS::EC2::InternetGateway" 22 | }, 23 | "VPCGatewayAttachment" : { 24 | "Type" : "AWS::EC2::VPCGatewayAttachment", 25 | "Properties" : { 26 | "VpcId" : { "Ref" : "VPC" }, 27 | "InternetGatewayId" : { "Ref" : "InternetGateway" } 28 | } 29 | }, 30 | "PublicRouteTable" : { 31 | "Type" : "AWS::EC2::RouteTable", 32 | "Properties" : { 33 | "VpcId" : { "Ref" : "VPC" } 34 | } 35 | }, 36 | "PublicRoute" : { 37 | "Type" : "AWS::EC2::Route", 38 | "DependsOn" : "VPCGatewayAttachment", 39 | "Properties" : { 40 | "RouteTableId" : { "Ref" : "PublicRouteTable" }, 41 | "DestinationCidrBlock" : "0.0.0.0/0", 42 | "GatewayId" : { "Ref" : "InternetGateway" } 43 | } 44 | }, 45 | "PublicSubnetRouteTableAssociation" : { 46 | "Type" : "AWS::EC2::SubnetRouteTableAssociation", 47 | "Properties" : { 48 | "SubnetId" : { "Ref" : "PublicSubnet" }, 49 | "RouteTableId" : { "Ref" : "PublicRouteTable" } 50 | } 51 | }, 52 | "PublicSubnetNetworkAclAssociation" : { 53 | "Type" : "AWS::EC2::SubnetNetworkAclAssociation", 54 | "Properties" : { 55 | "SubnetId" : { "Ref" : "PublicSubnet" }, 56 | "NetworkAclId" : { "Fn::GetAtt" : ["VPC", "DefaultNetworkAcl"] } 57 | } 58 | }, 59 | "WebServerSecurityGroup" : { 60 | "Type" : "AWS::EC2::SecurityGroup", 61 | "Properties" : { 62 | "GroupDescription" : "Enable HTTP ingress", 63 | "VpcId" : { "Ref" : "VPC" }, 64 | "SecurityGroupIngress" : [ { 65 | "IpProtocol" : "tcp", 66 | "FromPort" : "80", 67 | "ToPort" : "80", 68 | "CidrIp" : "0.0.0.0/0" 69 | } ] 70 | } 71 | } 72 | }, 73 | "Outputs" : { 74 | "VPCId" : { 75 | "Description" : "VPC ID", 76 | "Value" : { "Ref" : "VPC" }, 77 | "Export" : { "Name" : {"Fn::Sub": "${AWS::StackName}-VPCID" }} 78 | }, 79 | "PublicSubnet" : { 80 | "Description" : "The subnet ID to use for public web servers", 81 | "Value" : { "Ref" : "PublicSubnet" }, 82 | "Export" : { "Name" : {"Fn::Sub": "${AWS::StackName}-SubnetID" }} 83 | }, 84 | "WebServerSecurityGroup" : { 85 | "Description" : "The security group ID to use for public web servers", 86 | "Value" : { "Fn::GetAtt" : ["WebServerSecurityGroup", "GroupId"] }, 87 | "Export" : { "Name" : {"Fn::Sub": "${AWS::StackName}-SecurityGroupID" }} 88 | } 89 | } 90 | } -------------------------------------------------------------------------------- /CrossStack/webapp.json: -------------------------------------------------------------------------------- 1 | { 2 | "AWSTemplateFormatVersion" : "2010-09-09", 3 | 4 | "Description" : "AWS CloudFormation Cross-Stack Reference Sample Template: Demonstrates how to reference resources from a different stack. This template provisions an EC2 instance in an EC2 Security Group provisioned in a different stack. **WARNING** This template creates an Amazon EC2 instance. You will be billed for the AWS resources used if you create a stack from this template.", 5 | 6 | "Parameters": { 7 | "NetworkStackName": { 8 | "Description": "Name of an active CloudFormation stack that contains the networking resources, such as the subnet and security group, that will be used in this stack.", 9 | "Type": "String", 10 | "MinLength" : 1, 11 | "MaxLength" : 255, 12 | "AllowedPattern" : "^[a-zA-Z][-a-zA-Z0-9]*$", 13 | "Default" : "SampleNetworkCrossStack" 14 | } 15 | }, 16 | 17 | "Mappings" : { 18 | "AWSRegionArch2AMI" : { 19 | "us-east-1" : {"PV64" : "ami-8ff710e2", "HVM64" : "ami-f5f41398", "HVMG2" : "ami-4afd1d27"}, 20 | "us-west-2" : {"PV64" : "ami-eff1028f", "HVM64" : "ami-d0f506b0", "HVMG2" : "ami-ee897b8e"}, 21 | "us-west-1" : {"PV64" : "ami-ac85fbcc", "HVM64" : "ami-6e84fa0e", "HVMG2" : "ami-69106909"}, 22 | "eu-west-1" : {"PV64" : "ami-23ab2250", "HVM64" : "ami-b0ac25c3", "HVMG2" : "ami-936de5e0"}, 23 | "eu-central-1" : {"PV64" : "ami-27c12348", "HVM64" : "ami-d3c022bc", "HVMG2" : "ami-8e7092e1"}, 24 | "ap-northeast-1" : {"PV64" : "ami-26160d48", "HVM64" : "ami-29160d47", "HVMG2" : "ami-91809aff"}, 25 | "ap-northeast-2" : {"PV64" : "NOT_SUPPORTED", "HVM64" : "ami-cf32faa1", "HVMG2" : "NOT_SUPPORTED"}, 26 | "ap-southeast-1" : {"PV64" : "ami-f3dd0a90", "HVM64" : "ami-1ddc0b7e", "HVMG2" : "ami-3c30e75f"}, 27 | "ap-southeast-2" : {"PV64" : "ami-8f94b9ec", "HVM64" : "ami-0c95b86f", "HVMG2" : "ami-543d1137"}, 28 | "sa-east-1" : {"PV64" : "ami-e188018d", "HVM64" : "ami-fb890097", "HVMG2" : "NOT_SUPPORTED"}, 29 | "cn-north-1" : {"PV64" : "ami-77a46e1a", "HVM64" : "ami-05a66c68", "HVMG2" : "NOT_SUPPORTED"} 30 | } 31 | }, 32 | 33 | "Resources" : { 34 | "WebServerInstance": { 35 | "Type": "AWS::EC2::Instance", 36 | "Metadata" : { 37 | "AWS::CloudFormation::Init" : { 38 | "configSets" : { 39 | "All" : [ "ConfigureSampleApp" ] 40 | }, 41 | 42 | "ConfigureSampleApp" : { 43 | "packages" : { 44 | "yum" : { 45 | "httpd" : [] 46 | } 47 | }, 48 | 49 | "files" : { 50 | "/var/www/html/index.html" : { 51 | "content" : { "Fn::Join" : ["\n", [ 52 | "\"AWS", 53 | "

Congratulations, you have successfully launched the AWS CloudFormation sample.

" 54 | ]]}, 55 | "mode" : "000644", 56 | "owner" : "root", 57 | "group" : "root" 58 | } 59 | }, 60 | 61 | "services" : { 62 | "sysvinit" : { 63 | "httpd" : { "enabled" : "true", "ensureRunning" : "true" } 64 | } 65 | } 66 | } 67 | } 68 | }, 69 | "Properties": { 70 | "InstanceType" : "t2.micro", 71 | "ImageId": { "Fn::FindInMap": [ "AWSRegionArch2AMI", { "Ref": "AWS::Region" } , "HVM64" ] }, 72 | "NetworkInterfaces" : [{ 73 | "GroupSet" : [{ "Fn::ImportValue" : {"Fn::Sub": "${NetworkStackName}-SecurityGroupID" } }], 74 | "AssociatePublicIpAddress" : "true", 75 | "DeviceIndex" : "0", 76 | "DeleteOnTermination" : "true", 77 | "SubnetId" : { "Fn::ImportValue" : {"Fn::Sub": "${NetworkStackName}-SubnetID" } } 78 | }], 79 | "UserData" : { "Fn::Base64" : { "Fn::Join" : ["", [ 80 | "#!/bin/bash -xe\n", 81 | "yum update -y aws-cfn-bootstrap\n", 82 | 83 | "# Install the files and packages from the metadata\n", 84 | "/opt/aws/bin/cfn-init -v ", 85 | " --stack ", { "Ref" : "AWS::StackName" }, 86 | " --resource WebServerInstance ", 87 | " --configsets All ", 88 | " --region ", { "Ref" : "AWS::Region" }, "\n", 89 | 90 | "# Signal the status from cfn-init\n", 91 | "/opt/aws/bin/cfn-signal -e $? ", 92 | " --stack ", { "Ref" : "AWS::StackName" }, 93 | " --resource WebServerInstance ", 94 | " --region ", { "Ref" : "AWS::Region" }, "\n" 95 | ]]}} 96 | }, 97 | "CreationPolicy" : { 98 | "ResourceSignal" : { 99 | "Timeout" : "PT5M" 100 | } 101 | } 102 | } 103 | }, 104 | 105 | "Outputs" : { 106 | "URL" : { 107 | "Description" : "URL of the sample website", 108 | "Value" : { "Fn::Join" : [ "", [ "http://", { "Fn::GetAtt" : [ "WebServerInstance", "PublicDnsName" ]}]]} 109 | } 110 | } 111 | } -------------------------------------------------------------------------------- /Drift Detection/afterdriftupdate.json: -------------------------------------------------------------------------------- 1 | { 2 | "AWSTemplateFormatVersion" : "2010-09-09", 3 | 4 | "Description" : "AWS CloudFormation Sample Template EC2InstanceWithSecurityGroupSample: Create an Amazon EC2 instance running the Amazon Linux AMI. The AMI is chosen based on the region in which the stack is run. This example creates an EC2 security group for the instance to give you SSH access. **WARNING** This template creates an Amazon EC2 instance. You will be billed for the AWS resources used if you create a stack from this template.", 5 | 6 | "Parameters" : { 7 | "KeyName": { 8 | "Description" : "Name of an existing EC2 KeyPair to enable SSH access to the instance", 9 | "Type": "AWS::EC2::KeyPair::KeyName", 10 | "ConstraintDescription" : "must be the name of an existing EC2 KeyPair." 11 | }, 12 | 13 | "InstanceType" : { 14 | "Description" : "WebServer EC2 instance type", 15 | "Type" : "String", 16 | "Default" : "t2.small", 17 | "AllowedValues" : [ "t1.micro", "t2.nano", "t2.micro", "t2.small", "t2.medium", "t2.large", "m1.small", "m1.medium", "m1.large", "m1.xlarge", "m2.xlarge", "m2.2xlarge", "m2.4xlarge", "m3.medium", "m3.large", "m3.xlarge", "m3.2xlarge", "m4.large", "m4.xlarge", "m4.2xlarge", "m4.4xlarge", "m4.10xlarge", "c1.medium", "c1.xlarge", "c3.large", "c3.xlarge", "c3.2xlarge", "c3.4xlarge", "c3.8xlarge", "c4.large", "c4.xlarge", "c4.2xlarge", "c4.4xlarge", "c4.8xlarge", "g2.2xlarge", "g2.8xlarge", "r3.large", "r3.xlarge", "r3.2xlarge", "r3.4xlarge", "r3.8xlarge", "i2.xlarge", "i2.2xlarge", "i2.4xlarge", "i2.8xlarge", "d2.xlarge", "d2.2xlarge", "d2.4xlarge", "d2.8xlarge", "hi1.4xlarge", "hs1.8xlarge", "cr1.8xlarge", "cc2.8xlarge", "cg1.4xlarge"] 18 | , 19 | "ConstraintDescription" : "must be a valid EC2 instance type." 20 | }, 21 | "myVPC": { 22 | "Description" : "Learning Activity Provided VPC", 23 | "Type" : "String", 24 | "Default" : "vpc-XXXXXXXX" 25 | }, 26 | "MySubnet": { 27 | "Description" : "Learning Activity Provided subnet", 28 | "Type": "String", 29 | "Default": "subnet-XXXXXXXX" 30 | }, 31 | "SSHLocation" : { 32 | "Description" : "The IP address range that can be used to SSH to the EC2 instances", 33 | "Type": "String", 34 | "MinLength": "9", 35 | "MaxLength": "18", 36 | "Default": "0.0.0.0/0", 37 | "AllowedPattern": "(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})/(\\d{1,2})", 38 | "ConstraintDescription": "must be a valid IP CIDR range of the form x.x.x.x/x." 39 | } 40 | }, 41 | 42 | "Mappings" : { 43 | "AWSInstanceType2Arch" : { 44 | "t1.micro" : { "Arch" : "HVM64" }, 45 | "t2.nano" : { "Arch" : "HVM64" }, 46 | "t2.micro" : { "Arch" : "HVM64" }, 47 | "t2.small" : { "Arch" : "HVM64" }, 48 | "t2.medium" : { "Arch" : "HVM64" }, 49 | "t2.large" : { "Arch" : "HVM64" }, 50 | "m1.small" : { "Arch" : "HVM64" }, 51 | "m1.medium" : { "Arch" : "HVM64" }, 52 | "m1.large" : { "Arch" : "HVM64" }, 53 | "m1.xlarge" : { "Arch" : "HVM64" }, 54 | "m2.xlarge" : { "Arch" : "HVM64" }, 55 | "m2.2xlarge" : { "Arch" : "HVM64" }, 56 | "m2.4xlarge" : { "Arch" : "HVM64" }, 57 | "m3.medium" : { "Arch" : "HVM64" }, 58 | "m3.large" : { "Arch" : "HVM64" }, 59 | "m3.xlarge" : { "Arch" : "HVM64" }, 60 | "m3.2xlarge" : { "Arch" : "HVM64" }, 61 | "m4.large" : { "Arch" : "HVM64" }, 62 | "m4.xlarge" : { "Arch" : "HVM64" }, 63 | "m4.2xlarge" : { "Arch" : "HVM64" }, 64 | "m4.4xlarge" : { "Arch" : "HVM64" }, 65 | "m4.10xlarge" : { "Arch" : "HVM64" }, 66 | "c1.medium" : { "Arch" : "HVM64" }, 67 | "c1.xlarge" : { "Arch" : "HVM64" }, 68 | "c3.large" : { "Arch" : "HVM64" }, 69 | "c3.xlarge" : { "Arch" : "HVM64" }, 70 | "c3.2xlarge" : { "Arch" : "HVM64" }, 71 | "c3.4xlarge" : { "Arch" : "HVM64" }, 72 | "c3.8xlarge" : { "Arch" : "HVM64" }, 73 | "c4.large" : { "Arch" : "HVM64" }, 74 | "c4.xlarge" : { "Arch" : "HVM64" }, 75 | "c4.2xlarge" : { "Arch" : "HVM64" }, 76 | "c4.4xlarge" : { "Arch" : "HVM64" }, 77 | "c4.8xlarge" : { "Arch" : "HVM64" }, 78 | "g2.2xlarge" : { "Arch" : "HVMG2" }, 79 | "g2.8xlarge" : { "Arch" : "HVMG2" }, 80 | "r3.large" : { "Arch" : "HVM64" }, 81 | "r3.xlarge" : { "Arch" : "HVM64" }, 82 | "r3.2xlarge" : { "Arch" : "HVM64" }, 83 | "r3.4xlarge" : { "Arch" : "HVM64" }, 84 | "r3.8xlarge" : { "Arch" : "HVM64" }, 85 | "i2.xlarge" : { "Arch" : "HVM64" }, 86 | "i2.2xlarge" : { "Arch" : "HVM64" }, 87 | "i2.4xlarge" : { "Arch" : "HVM64" }, 88 | "i2.8xlarge" : { "Arch" : "HVM64" }, 89 | "d2.xlarge" : { "Arch" : "HVM64" }, 90 | "d2.2xlarge" : { "Arch" : "HVM64" }, 91 | "d2.4xlarge" : { "Arch" : "HVM64" }, 92 | "d2.8xlarge" : { "Arch" : "HVM64" }, 93 | "hi1.4xlarge" : { "Arch" : "HVM64" }, 94 | "hs1.8xlarge" : { "Arch" : "HVM64" }, 95 | "cr1.8xlarge" : { "Arch" : "HVM64" }, 96 | "cc2.8xlarge" : { "Arch" : "HVM64" } 97 | }, 98 | 99 | "AWSInstanceType2NATArch" : { 100 | "t1.micro" : { "Arch" : "NATHVM64" }, 101 | "t2.nano" : { "Arch" : "NATHVM64" }, 102 | "t2.micro" : { "Arch" : "NATHVM64" }, 103 | "t2.small" : { "Arch" : "NATHVM64" }, 104 | "t2.medium" : { "Arch" : "NATHVM64" }, 105 | "t2.large" : { "Arch" : "NATHVM64" }, 106 | "m1.small" : { "Arch" : "NATHVM64" }, 107 | "m1.medium" : { "Arch" : "NATHVM64" }, 108 | "m1.large" : { "Arch" : "NATHVM64" }, 109 | "m1.xlarge" : { "Arch" : "NATHVM64" }, 110 | "m2.xlarge" : { "Arch" : "NATHVM64" }, 111 | "m2.2xlarge" : { "Arch" : "NATHVM64" }, 112 | "m2.4xlarge" : { "Arch" : "NATHVM64" }, 113 | "m3.medium" : { "Arch" : "NATHVM64" }, 114 | "m3.large" : { "Arch" : "NATHVM64" }, 115 | "m3.xlarge" : { "Arch" : "NATHVM64" }, 116 | "m3.2xlarge" : { "Arch" : "NATHVM64" }, 117 | "m4.large" : { "Arch" : "NATHVM64" }, 118 | "m4.xlarge" : { "Arch" : "NATHVM64" }, 119 | "m4.2xlarge" : { "Arch" : "NATHVM64" }, 120 | "m4.4xlarge" : { "Arch" : "NATHVM64" }, 121 | "m4.10xlarge" : { "Arch" : "NATHVM64" }, 122 | "c1.medium" : { "Arch" : "NATHVM64" }, 123 | "c1.xlarge" : { "Arch" : "NATHVM64" }, 124 | "c3.large" : { "Arch" : "NATHVM64" }, 125 | "c3.xlarge" : { "Arch" : "NATHVM64" }, 126 | "c3.2xlarge" : { "Arch" : "NATHVM64" }, 127 | "c3.4xlarge" : { "Arch" : "NATHVM64" }, 128 | "c3.8xlarge" : { "Arch" : "NATHVM64" }, 129 | "c4.large" : { "Arch" : "NATHVM64" }, 130 | "c4.xlarge" : { "Arch" : "NATHVM64" }, 131 | "c4.2xlarge" : { "Arch" : "NATHVM64" }, 132 | "c4.4xlarge" : { "Arch" : "NATHVM64" }, 133 | "c4.8xlarge" : { "Arch" : "NATHVM64" }, 134 | "g2.2xlarge" : { "Arch" : "NATHVMG2" }, 135 | "g2.8xlarge" : { "Arch" : "NATHVMG2" }, 136 | "r3.large" : { "Arch" : "NATHVM64" }, 137 | "r3.xlarge" : { "Arch" : "NATHVM64" }, 138 | "r3.2xlarge" : { "Arch" : "NATHVM64" }, 139 | "r3.4xlarge" : { "Arch" : "NATHVM64" }, 140 | "r3.8xlarge" : { "Arch" : "NATHVM64" }, 141 | "i2.xlarge" : { "Arch" : "NATHVM64" }, 142 | "i2.2xlarge" : { "Arch" : "NATHVM64" }, 143 | "i2.4xlarge" : { "Arch" : "NATHVM64" }, 144 | "i2.8xlarge" : { "Arch" : "NATHVM64" }, 145 | "d2.xlarge" : { "Arch" : "NATHVM64" }, 146 | "d2.2xlarge" : { "Arch" : "NATHVM64" }, 147 | "d2.4xlarge" : { "Arch" : "NATHVM64" }, 148 | "d2.8xlarge" : { "Arch" : "NATHVM64" }, 149 | "hi1.4xlarge" : { "Arch" : "NATHVM64" }, 150 | "hs1.8xlarge" : { "Arch" : "NATHVM64" }, 151 | "cr1.8xlarge" : { "Arch" : "NATHVM64" }, 152 | "cc2.8xlarge" : { "Arch" : "NATHVM64" } 153 | } 154 | , 155 | "AWSRegionArch2AMI" : { 156 | "us-east-1" : {"HVM64" : "ami-0ff8a91507f77f867", "HVMG2" : "ami-0a584ac55a7631c0c"}, 157 | "us-west-2" : {"HVM64" : "ami-a0cfeed8", "HVMG2" : "ami-0e09505bc235aa82d"}, 158 | "us-west-1" : {"HVM64" : "ami-0bdb828fd58c52235", "HVMG2" : "ami-066ee5fd4a9ef77f1"}, 159 | "eu-west-1" : {"HVM64" : "ami-047bb4163c506cd98", "HVMG2" : "ami-0a7c483d527806435"}, 160 | "eu-west-2" : {"HVM64" : "ami-f976839e", "HVMG2" : "NOT_SUPPORTED"}, 161 | "eu-west-3" : {"HVM64" : "ami-0ebc281c20e89ba4b", "HVMG2" : "NOT_SUPPORTED"}, 162 | "eu-central-1" : {"HVM64" : "ami-0233214e13e500f77", "HVMG2" : "ami-06223d46a6d0661c7"}, 163 | "ap-northeast-1" : {"HVM64" : "ami-06cd52961ce9f0d85", "HVMG2" : "ami-053cdd503598e4a9d"}, 164 | "ap-northeast-2" : {"HVM64" : "ami-0a10b2721688ce9d2", "HVMG2" : "NOT_SUPPORTED"}, 165 | "ap-northeast-3" : {"HVM64" : "ami-0d98120a9fb693f07", "HVMG2" : "NOT_SUPPORTED"}, 166 | "ap-southeast-1" : {"HVM64" : "ami-08569b978cc4dfa10", "HVMG2" : "ami-0be9df32ae9f92309"}, 167 | "ap-southeast-2" : {"HVM64" : "ami-09b42976632b27e9b", "HVMG2" : "ami-0a9ce9fecc3d1daf8"}, 168 | "ap-south-1" : {"HVM64" : "ami-0912f71e06545ad88", "HVMG2" : "ami-097b15e89dbdcfcf4"}, 169 | "us-east-2" : {"HVM64" : "ami-0b59bfac6be064b78", "HVMG2" : "NOT_SUPPORTED"}, 170 | "ca-central-1" : {"HVM64" : "ami-0b18956f", "HVMG2" : "NOT_SUPPORTED"}, 171 | "sa-east-1" : {"HVM64" : "ami-07b14488da8ea02a0", "HVMG2" : "NOT_SUPPORTED"}, 172 | "cn-north-1" : {"HVM64" : "ami-0a4eaf6c4454eda75", "HVMG2" : "NOT_SUPPORTED"}, 173 | "cn-northwest-1" : {"HVM64" : "ami-6b6a7d09", "HVMG2" : "NOT_SUPPORTED"} 174 | } 175 | 176 | }, 177 | 178 | "Resources" : { 179 | "S3Bucket" : { 180 | "Type" : "AWS::S3::Bucket", 181 | "Properties" : { 182 | "AccessControl" : "PublicRead" 183 | } 184 | }, 185 | "EC2Instance2" : { 186 | "Type" : "AWS::EC2::Instance", 187 | "Properties" : { 188 | "SubnetId": { "Ref": "MySubnet" }, 189 | "InstanceType" : { "Ref" : "InstanceType" }, 190 | "SecurityGroupIds": [ 191 | { 192 | "Ref": "InstanceSecurityGroup" 193 | } 194 | ], 195 | "KeyName" : { "Ref" : "KeyName" }, 196 | "Tags" : [ {"Key" : "Name", "Value" : "Instance2"}], 197 | "ImageId" : { "Fn::FindInMap" : [ "AWSRegionArch2AMI", { "Ref" : "AWS::Region" }, 198 | { "Fn::FindInMap" : [ "AWSInstanceType2Arch", { "Ref" : "InstanceType" }, "Arch" ] } ] } 199 | } 200 | }, 201 | 202 | "EC2Instance3" : { 203 | "Type" : "AWS::EC2::Instance", 204 | "Properties" : { 205 | "SubnetId": { "Ref": "MySubnet" }, 206 | "InstanceType" : { "Ref" : "InstanceType" }, 207 | "SecurityGroupIds": [ 208 | { 209 | "Ref": "InstanceSecurityGroup" 210 | } 211 | ], 212 | "KeyName" : { "Ref" : "KeyName" }, 213 | "Tags" : [ {"Key" : "Name", "Value" : "Instance3"}], 214 | "ImageId" : { "Fn::FindInMap" : [ "AWSRegionArch2AMI", { "Ref" : "AWS::Region" }, 215 | { "Fn::FindInMap" : [ "AWSInstanceType2Arch", { "Ref" : "InstanceType" }, "Arch" ] } ] } 216 | } 217 | }, 218 | "InstanceSecurityGroup" : { 219 | "Type" : "AWS::EC2::SecurityGroup", 220 | "Properties" : { 221 | "GroupDescription" : "Enable SSH access via port 22", 222 | "VpcId" : {"Ref" : "myVPC"}, 223 | "SecurityGroupIngress" : [ { 224 | "IpProtocol" : "tcp", 225 | "FromPort" : "22", 226 | "ToPort" : "22", 227 | "CidrIp" : { "Ref" : "SSHLocation"} 228 | }, 229 | { 230 | "CidrIp": "0.0.0.0/0", 231 | "FromPort": 443, 232 | "IpProtocol": "tcp", 233 | "ToPort": 443 234 | }, 235 | { 236 | "FromPort": 443, 237 | "IpProtocol": "tcp", 238 | "ToPort": 443 239 | }, 240 | { 241 | "CidrIp": "0.0.0.0/0", 242 | "FromPort": 80, 243 | "IpProtocol": "tcp", 244 | "ToPort": 80 245 | }, 246 | { 247 | "FromPort": 80, 248 | "IpProtocol": "tcp", 249 | "ToPort": 80 250 | } 251 | ] 252 | } 253 | } 254 | }, 255 | 256 | "Outputs" : { 257 | "InstanceId" : { 258 | "Description" : "InstanceId of the newly created EC2 instance", 259 | "Value" : { "Ref" : "EC2Instance2" } 260 | }, 261 | "AZ" : { 262 | "Description" : "Availability Zone of the newly created EC2 instance", 263 | "Value" : { "Fn::GetAtt" : [ "EC2Instance2", "AvailabilityZone" ] } 264 | }, 265 | "PublicDNS" : { 266 | "Description" : "Public DNSName of the newly created EC2 instance", 267 | "Value" : { "Fn::GetAtt" : [ "EC2Instance2", "PublicDnsName" ] } 268 | } 269 | } 270 | } 271 | -------------------------------------------------------------------------------- /Drift Detection/ec24drift.json: -------------------------------------------------------------------------------- 1 | { 2 | "AWSTemplateFormatVersion" : "2010-09-09", 3 | 4 | "Description" : "AWS CloudFormation Sample Template EC2InstanceWithSecurityGroupSample: Create an Amazon EC2 instance running the Amazon Linux AMI. The AMI is chosen based on the region in which the stack is run. This example creates an EC2 security group for the instance to give you SSH access. **WARNING** This template creates an Amazon EC2 instance. You will be billed for the AWS resources used if you create a stack from this template.", 5 | 6 | "Parameters" : { 7 | "KeyName": { 8 | "Description" : "Name of an existing EC2 KeyPair to enable SSH access to the instance", 9 | "Type": "AWS::EC2::KeyPair::KeyName", 10 | "ConstraintDescription" : "must be the name of an existing EC2 KeyPair." 11 | }, 12 | 13 | "InstanceType" : { 14 | "Description" : "WebServer EC2 instance type", 15 | "Type" : "String", 16 | "Default" : "t2.small", 17 | "AllowedValues" : [ "t1.micro", "t2.nano", "t2.micro", "t2.small", "t2.medium", "t2.large", "m1.small", "m1.medium", "m1.large", "m1.xlarge", "m2.xlarge", "m2.2xlarge", "m2.4xlarge", "m3.medium", "m3.large", "m3.xlarge", "m3.2xlarge", "m4.large", "m4.xlarge", "m4.2xlarge", "m4.4xlarge", "m4.10xlarge", "c1.medium", "c1.xlarge", "c3.large", "c3.xlarge", "c3.2xlarge", "c3.4xlarge", "c3.8xlarge", "c4.large", "c4.xlarge", "c4.2xlarge", "c4.4xlarge", "c4.8xlarge", "g2.2xlarge", "g2.8xlarge", "r3.large", "r3.xlarge", "r3.2xlarge", "r3.4xlarge", "r3.8xlarge", "i2.xlarge", "i2.2xlarge", "i2.4xlarge", "i2.8xlarge", "d2.xlarge", "d2.2xlarge", "d2.4xlarge", "d2.8xlarge", "hi1.4xlarge", "hs1.8xlarge", "cr1.8xlarge", "cc2.8xlarge", "cg1.4xlarge"] 18 | , 19 | "ConstraintDescription" : "must be a valid EC2 instance type." 20 | }, 21 | "myVPC": { 22 | "Description" : "Learning Activity Provided VPC", 23 | "Type" : "String", 24 | "Default" : "vpc-XXXXXXXX" 25 | }, 26 | "MySubnet": { 27 | "Description" : "Learning Activity Provided subnet", 28 | "Type": "String", 29 | "Default": "subnet-XXXXXXXX" 30 | }, 31 | "SSHLocation" : { 32 | "Description" : "The IP address range that can be used to SSH to the EC2 instances", 33 | "Type": "String", 34 | "MinLength": "9", 35 | "MaxLength": "18", 36 | "Default": "0.0.0.0/0", 37 | "AllowedPattern": "(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})/(\\d{1,2})", 38 | "ConstraintDescription": "must be a valid IP CIDR range of the form x.x.x.x/x." 39 | } 40 | }, 41 | 42 | "Mappings" : { 43 | "AWSInstanceType2Arch" : { 44 | "t1.micro" : { "Arch" : "HVM64" }, 45 | "t2.nano" : { "Arch" : "HVM64" }, 46 | "t2.micro" : { "Arch" : "HVM64" }, 47 | "t2.small" : { "Arch" : "HVM64" }, 48 | "t2.medium" : { "Arch" : "HVM64" }, 49 | "t2.large" : { "Arch" : "HVM64" }, 50 | "m1.small" : { "Arch" : "HVM64" }, 51 | "m1.medium" : { "Arch" : "HVM64" }, 52 | "m1.large" : { "Arch" : "HVM64" }, 53 | "m1.xlarge" : { "Arch" : "HVM64" }, 54 | "m2.xlarge" : { "Arch" : "HVM64" }, 55 | "m2.2xlarge" : { "Arch" : "HVM64" }, 56 | "m2.4xlarge" : { "Arch" : "HVM64" }, 57 | "m3.medium" : { "Arch" : "HVM64" }, 58 | "m3.large" : { "Arch" : "HVM64" }, 59 | "m3.xlarge" : { "Arch" : "HVM64" }, 60 | "m3.2xlarge" : { "Arch" : "HVM64" }, 61 | "m4.large" : { "Arch" : "HVM64" }, 62 | "m4.xlarge" : { "Arch" : "HVM64" }, 63 | "m4.2xlarge" : { "Arch" : "HVM64" }, 64 | "m4.4xlarge" : { "Arch" : "HVM64" }, 65 | "m4.10xlarge" : { "Arch" : "HVM64" }, 66 | "c1.medium" : { "Arch" : "HVM64" }, 67 | "c1.xlarge" : { "Arch" : "HVM64" }, 68 | "c3.large" : { "Arch" : "HVM64" }, 69 | "c3.xlarge" : { "Arch" : "HVM64" }, 70 | "c3.2xlarge" : { "Arch" : "HVM64" }, 71 | "c3.4xlarge" : { "Arch" : "HVM64" }, 72 | "c3.8xlarge" : { "Arch" : "HVM64" }, 73 | "c4.large" : { "Arch" : "HVM64" }, 74 | "c4.xlarge" : { "Arch" : "HVM64" }, 75 | "c4.2xlarge" : { "Arch" : "HVM64" }, 76 | "c4.4xlarge" : { "Arch" : "HVM64" }, 77 | "c4.8xlarge" : { "Arch" : "HVM64" }, 78 | "g2.2xlarge" : { "Arch" : "HVMG2" }, 79 | "g2.8xlarge" : { "Arch" : "HVMG2" }, 80 | "r3.large" : { "Arch" : "HVM64" }, 81 | "r3.xlarge" : { "Arch" : "HVM64" }, 82 | "r3.2xlarge" : { "Arch" : "HVM64" }, 83 | "r3.4xlarge" : { "Arch" : "HVM64" }, 84 | "r3.8xlarge" : { "Arch" : "HVM64" }, 85 | "i2.xlarge" : { "Arch" : "HVM64" }, 86 | "i2.2xlarge" : { "Arch" : "HVM64" }, 87 | "i2.4xlarge" : { "Arch" : "HVM64" }, 88 | "i2.8xlarge" : { "Arch" : "HVM64" }, 89 | "d2.xlarge" : { "Arch" : "HVM64" }, 90 | "d2.2xlarge" : { "Arch" : "HVM64" }, 91 | "d2.4xlarge" : { "Arch" : "HVM64" }, 92 | "d2.8xlarge" : { "Arch" : "HVM64" }, 93 | "hi1.4xlarge" : { "Arch" : "HVM64" }, 94 | "hs1.8xlarge" : { "Arch" : "HVM64" }, 95 | "cr1.8xlarge" : { "Arch" : "HVM64" }, 96 | "cc2.8xlarge" : { "Arch" : "HVM64" } 97 | }, 98 | 99 | "AWSInstanceType2NATArch" : { 100 | "t1.micro" : { "Arch" : "NATHVM64" }, 101 | "t2.nano" : { "Arch" : "NATHVM64" }, 102 | "t2.micro" : { "Arch" : "NATHVM64" }, 103 | "t2.small" : { "Arch" : "NATHVM64" }, 104 | "t2.medium" : { "Arch" : "NATHVM64" }, 105 | "t2.large" : { "Arch" : "NATHVM64" }, 106 | "m1.small" : { "Arch" : "NATHVM64" }, 107 | "m1.medium" : { "Arch" : "NATHVM64" }, 108 | "m1.large" : { "Arch" : "NATHVM64" }, 109 | "m1.xlarge" : { "Arch" : "NATHVM64" }, 110 | "m2.xlarge" : { "Arch" : "NATHVM64" }, 111 | "m2.2xlarge" : { "Arch" : "NATHVM64" }, 112 | "m2.4xlarge" : { "Arch" : "NATHVM64" }, 113 | "m3.medium" : { "Arch" : "NATHVM64" }, 114 | "m3.large" : { "Arch" : "NATHVM64" }, 115 | "m3.xlarge" : { "Arch" : "NATHVM64" }, 116 | "m3.2xlarge" : { "Arch" : "NATHVM64" }, 117 | "m4.large" : { "Arch" : "NATHVM64" }, 118 | "m4.xlarge" : { "Arch" : "NATHVM64" }, 119 | "m4.2xlarge" : { "Arch" : "NATHVM64" }, 120 | "m4.4xlarge" : { "Arch" : "NATHVM64" }, 121 | "m4.10xlarge" : { "Arch" : "NATHVM64" }, 122 | "c1.medium" : { "Arch" : "NATHVM64" }, 123 | "c1.xlarge" : { "Arch" : "NATHVM64" }, 124 | "c3.large" : { "Arch" : "NATHVM64" }, 125 | "c3.xlarge" : { "Arch" : "NATHVM64" }, 126 | "c3.2xlarge" : { "Arch" : "NATHVM64" }, 127 | "c3.4xlarge" : { "Arch" : "NATHVM64" }, 128 | "c3.8xlarge" : { "Arch" : "NATHVM64" }, 129 | "c4.large" : { "Arch" : "NATHVM64" }, 130 | "c4.xlarge" : { "Arch" : "NATHVM64" }, 131 | "c4.2xlarge" : { "Arch" : "NATHVM64" }, 132 | "c4.4xlarge" : { "Arch" : "NATHVM64" }, 133 | "c4.8xlarge" : { "Arch" : "NATHVM64" }, 134 | "g2.2xlarge" : { "Arch" : "NATHVMG2" }, 135 | "g2.8xlarge" : { "Arch" : "NATHVMG2" }, 136 | "r3.large" : { "Arch" : "NATHVM64" }, 137 | "r3.xlarge" : { "Arch" : "NATHVM64" }, 138 | "r3.2xlarge" : { "Arch" : "NATHVM64" }, 139 | "r3.4xlarge" : { "Arch" : "NATHVM64" }, 140 | "r3.8xlarge" : { "Arch" : "NATHVM64" }, 141 | "i2.xlarge" : { "Arch" : "NATHVM64" }, 142 | "i2.2xlarge" : { "Arch" : "NATHVM64" }, 143 | "i2.4xlarge" : { "Arch" : "NATHVM64" }, 144 | "i2.8xlarge" : { "Arch" : "NATHVM64" }, 145 | "d2.xlarge" : { "Arch" : "NATHVM64" }, 146 | "d2.2xlarge" : { "Arch" : "NATHVM64" }, 147 | "d2.4xlarge" : { "Arch" : "NATHVM64" }, 148 | "d2.8xlarge" : { "Arch" : "NATHVM64" }, 149 | "hi1.4xlarge" : { "Arch" : "NATHVM64" }, 150 | "hs1.8xlarge" : { "Arch" : "NATHVM64" }, 151 | "cr1.8xlarge" : { "Arch" : "NATHVM64" }, 152 | "cc2.8xlarge" : { "Arch" : "NATHVM64" } 153 | } 154 | , 155 | "AWSRegionArch2AMI" : { 156 | "us-east-1" : {"HVM64" : "ami-0ff8a91507f77f867", "HVMG2" : "ami-0a584ac55a7631c0c"}, 157 | "us-west-2" : {"HVM64" : "ami-a0cfeed8", "HVMG2" : "ami-0e09505bc235aa82d"}, 158 | "us-west-1" : {"HVM64" : "ami-0bdb828fd58c52235", "HVMG2" : "ami-066ee5fd4a9ef77f1"}, 159 | "eu-west-1" : {"HVM64" : "ami-047bb4163c506cd98", "HVMG2" : "ami-0a7c483d527806435"}, 160 | "eu-west-2" : {"HVM64" : "ami-f976839e", "HVMG2" : "NOT_SUPPORTED"}, 161 | "eu-west-3" : {"HVM64" : "ami-0ebc281c20e89ba4b", "HVMG2" : "NOT_SUPPORTED"}, 162 | "eu-central-1" : {"HVM64" : "ami-0233214e13e500f77", "HVMG2" : "ami-06223d46a6d0661c7"}, 163 | "ap-northeast-1" : {"HVM64" : "ami-06cd52961ce9f0d85", "HVMG2" : "ami-053cdd503598e4a9d"}, 164 | "ap-northeast-2" : {"HVM64" : "ami-0a10b2721688ce9d2", "HVMG2" : "NOT_SUPPORTED"}, 165 | "ap-northeast-3" : {"HVM64" : "ami-0d98120a9fb693f07", "HVMG2" : "NOT_SUPPORTED"}, 166 | "ap-southeast-1" : {"HVM64" : "ami-08569b978cc4dfa10", "HVMG2" : "ami-0be9df32ae9f92309"}, 167 | "ap-southeast-2" : {"HVM64" : "ami-09b42976632b27e9b", "HVMG2" : "ami-0a9ce9fecc3d1daf8"}, 168 | "ap-south-1" : {"HVM64" : "ami-0912f71e06545ad88", "HVMG2" : "ami-097b15e89dbdcfcf4"}, 169 | "us-east-2" : {"HVM64" : "ami-0b59bfac6be064b78", "HVMG2" : "NOT_SUPPORTED"}, 170 | "ca-central-1" : {"HVM64" : "ami-0b18956f", "HVMG2" : "NOT_SUPPORTED"}, 171 | "sa-east-1" : {"HVM64" : "ami-07b14488da8ea02a0", "HVMG2" : "NOT_SUPPORTED"}, 172 | "cn-north-1" : {"HVM64" : "ami-0a4eaf6c4454eda75", "HVMG2" : "NOT_SUPPORTED"}, 173 | "cn-northwest-1" : {"HVM64" : "ami-6b6a7d09", "HVMG2" : "NOT_SUPPORTED"} 174 | } 175 | 176 | }, 177 | 178 | "Resources" : { 179 | "S3Bucket" : { 180 | "Type" : "AWS::S3::Bucket", 181 | "Properties" : { 182 | "AccessControl" : "PublicRead", 183 | "WebsiteConfiguration" : { 184 | "IndexDocument" : "index.html", 185 | "ErrorDocument" : "error.html" 186 | } 187 | } 188 | }, 189 | "EC2Instance" : { 190 | "Type" : "AWS::EC2::Instance", 191 | "Properties" : { 192 | "SubnetId": { "Ref": "MySubnet" }, 193 | "InstanceType" : { "Ref" : "InstanceType" }, 194 | "SecurityGroupIds": [ 195 | { 196 | "Ref": "InstanceSecurityGroup" 197 | } 198 | ], 199 | "KeyName" : { "Ref" : "KeyName" }, 200 | "Tags" : [ {"Key" : "Name", "Value" : "Instance1"}], 201 | "ImageId" : { "Fn::FindInMap" : [ "AWSRegionArch2AMI", { "Ref" : "AWS::Region" }, 202 | { "Fn::FindInMap" : [ "AWSInstanceType2Arch", { "Ref" : "InstanceType" }, "Arch" ] } ] } 203 | } 204 | }, 205 | "EC2Instance2" : { 206 | "Type" : "AWS::EC2::Instance", 207 | "Properties" : { 208 | "SubnetId": { "Ref": "MySubnet" }, 209 | "InstanceType" : { "Ref" : "InstanceType" }, 210 | "SecurityGroupIds": [ 211 | { 212 | "Ref": "InstanceSecurityGroup" 213 | } 214 | ], 215 | "KeyName" : { "Ref" : "KeyName" }, 216 | "Tags" : [ {"Key" : "Name", "Value" : "Instance2"}], 217 | "ImageId" : { "Fn::FindInMap" : [ "AWSRegionArch2AMI", { "Ref" : "AWS::Region" }, 218 | { "Fn::FindInMap" : [ "AWSInstanceType2Arch", { "Ref" : "InstanceType" }, "Arch" ] } ] } 219 | } 220 | }, 221 | "EC2Instance3" : { 222 | "Type" : "AWS::EC2::Instance", 223 | "Properties" : { 224 | "SubnetId": { "Ref": "MySubnet" }, 225 | "InstanceType" : { "Ref" : "InstanceType" }, 226 | "SecurityGroupIds": [ 227 | { 228 | "Ref": "InstanceSecurityGroup" 229 | } 230 | ], 231 | "KeyName" : { "Ref" : "KeyName" }, 232 | "Tags" : [ {"Key" : "Name", "Value" : "Instance3"}], 233 | "ImageId" : { "Fn::FindInMap" : [ "AWSRegionArch2AMI", { "Ref" : "AWS::Region" }, 234 | { "Fn::FindInMap" : [ "AWSInstanceType2Arch", { "Ref" : "InstanceType" }, "Arch" ] } ] } 235 | } 236 | }, 237 | "InstanceSecurityGroup" : { 238 | "Type" : "AWS::EC2::SecurityGroup", 239 | "Properties" : { 240 | "GroupDescription" : "Enable SSH access via port 22", 241 | "VpcId" : {"Ref" : "myVPC"}, 242 | "SecurityGroupIngress" : [ { 243 | "IpProtocol" : "tcp", 244 | "FromPort" : "22", 245 | "ToPort" : "22", 246 | "CidrIp" : { "Ref" : "SSHLocation"} 247 | } ] 248 | } 249 | } 250 | }, 251 | 252 | "Outputs" : { 253 | "InstanceId" : { 254 | "Description" : "InstanceId of the newly created EC2 instance", 255 | "Value" : { "Ref" : "EC2Instance" } 256 | }, 257 | "AZ" : { 258 | "Description" : "Availability Zone of the newly created EC2 instance", 259 | "Value" : { "Fn::GetAtt" : [ "EC2Instance", "AvailabilityZone" ] } 260 | }, 261 | "PublicDNS" : { 262 | "Description" : "Public DNSName of the newly created EC2 instance", 263 | "Value" : { "Fn::GetAtt" : [ "EC2Instance", "PublicDnsName" ] } 264 | } 265 | } 266 | } 267 | -------------------------------------------------------------------------------- /Lambda Aliases/AWS Lambda Aliases Lab Commands.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/natonic/DevOpsPro/49dd24c7fd26a35bfa9e5a8397940165f1aac83b/Lambda Aliases/AWS Lambda Aliases Lab Commands.docx -------------------------------------------------------------------------------- /Lambda Aliases/amilookup.js: -------------------------------------------------------------------------------- 1 | /** 2 | * A sample Lambda function that looks up the latest AMI ID for a given region and architecture. 3 | **/ 4 | 5 | // Map instance architectures to an AMI name pattern 6 | var archToAMINamePattern = { 7 | "PV64": "amzn-ami-pv*x86_64-ebs", 8 | "HVM64": "amzn-ami-hvm*x86_64-gp2", 9 | "HVMG2": "amzn-ami-graphics-hvm*x86_64-ebs*" 10 | }; 11 | var aws = require("aws-sdk"); 12 | 13 | exports.handler = function(event, context) { 14 | 15 | console.log("REQUEST RECEIVED:\n" + JSON.stringify(event)); 16 | 17 | // For Delete requests, immediately send a SUCCESS response. 18 | if (event.RequestType == "Delete") { 19 | sendResponse(event, context, "SUCCESS"); 20 | return; 21 | } 22 | 23 | var responseStatus = "FAILED"; 24 | var responseData = {}; 25 | 26 | var ec2 = new aws.EC2({region: event.ResourceProperties.Region}); 27 | var describeImagesParams = { 28 | Filters: [{ Name: "name", Values: [archToAMINamePattern[event.ResourceProperties.Architecture]]}], 29 | Owners: [event.ResourceProperties.Architecture == "HVMG2" ? "679593333241" : "amazon"] 30 | }; 31 | 32 | // Get AMI IDs with the specified name pattern and owner 33 | ec2.describeImages(describeImagesParams, function(err, describeImagesResult) { 34 | if (err) { 35 | responseData = {Error: "DescribeImages call failed"}; 36 | console.log(responseData.Error + ":\n", err); 37 | } 38 | else { 39 | var images = describeImagesResult.Images; 40 | // Sort images by name in decscending order. The names contain the AMI version, formatted as YYYY.MM.Ver. 41 | images.sort(function(x, y) { return y.Name.localeCompare(x.Name); }); 42 | for (var j = 0; j < images.length; j++) { 43 | if (isBeta(images[j].Name)) continue; 44 | responseStatus = "SUCCESS"; 45 | responseData["Id"] = images[j].ImageId; 46 | break; 47 | } 48 | } 49 | sendResponse(event, context, responseStatus, responseData); 50 | }); 51 | }; 52 | 53 | // Check if the image is a beta or rc image. The Lambda function won't return any of those images. 54 | function isBeta(imageName) { 55 | return imageName.toLowerCase().indexOf("beta") > -1 || imageName.toLowerCase().indexOf(".rc") > -1; 56 | } 57 | 58 | 59 | // Send response to the pre-signed S3 URL 60 | function sendResponse(event, context, responseStatus, responseData) { 61 | 62 | var responseBody = JSON.stringify({ 63 | Status: responseStatus, 64 | Reason: "See the details in CloudWatch Log Stream: " + context.logStreamName, 65 | PhysicalResourceId: context.logStreamName, 66 | StackId: event.StackId, 67 | RequestId: event.RequestId, 68 | LogicalResourceId: event.LogicalResourceId, 69 | Data: responseData 70 | }); 71 | 72 | console.log("RESPONSE BODY:\n", responseBody); 73 | 74 | var https = require("https"); 75 | var url = require("url"); 76 | 77 | var parsedUrl = url.parse(event.ResponseURL); 78 | var options = { 79 | hostname: parsedUrl.hostname, 80 | port: 443, 81 | path: parsedUrl.path, 82 | method: "PUT", 83 | headers: { 84 | "content-type": "", 85 | "content-length": responseBody.length 86 | } 87 | }; 88 | 89 | console.log("SENDING RESPONSE...\n"); 90 | 91 | var request = https.request(options, function(response) { 92 | console.log("STATUS: " + response.statusCode); 93 | console.log("HEADERS: " + JSON.stringify(response.headers)); 94 | // Tell AWS Lambda that the function execution is done 95 | context.done(); 96 | }); 97 | 98 | request.on("error", function(error) { 99 | console.log("sendResponse Error:" + error); 100 | // Tell AWS Lambda that the function execution is done 101 | context.done(); 102 | }); 103 | 104 | // write data to request body 105 | request.write(responseBody); 106 | request.end(); 107 | } -------------------------------------------------------------------------------- /Lambda/index.js: -------------------------------------------------------------------------------- 1 | 2 | var time = require('time'); 3 | exports.handler = (event, context, callback) => { 4 | var currentTime = new time.Date(); 5 | currentTime.setTimezone("America/Los_Angeles"); 6 | callback(null, { 7 | statusCode: '200', 8 | body: 'The time in Los Angeles is: ' + currentTime.toString(), 9 | }); 10 | }; 11 | -------------------------------------------------------------------------------- /Lambda/readme: -------------------------------------------------------------------------------- 1 | Test 2 | -------------------------------------------------------------------------------- /Lambda/samTemplate.yaml: -------------------------------------------------------------------------------- 1 | 2 | AWSTemplateFormatVersion: '2010-09-09' 3 | Transform: AWS::Serverless-2016-10-31 4 | Description: Outputs the time 5 | Resources: 6 | TimeFunction: 7 | Type: AWS::Serverless::Function 8 | Properties: 9 | Handler: index.handler 10 | Runtime: nodejs8.10 11 | CodeUri: ./ 12 | Events: 13 | MyTimeApi: 14 | Type: Api 15 | Properties: 16 | Path: /TimeResource 17 | Method: GET 18 | -------------------------------------------------------------------------------- /Nested Stacks/error.html: -------------------------------------------------------------------------------- 1 | 2 |
S3 Demo
3 | 4 | Error! 5 | 6 | -------------------------------------------------------------------------------- /Nested Stacks/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Elastic Beanstalk 5 | 74 | 75 | 76 |
77 |

Congratulations

78 |

Your first AWS Elastic Beanstalk Node.js application is now running on your own dedicated environment in the AWS Cloud

79 |
80 | 92 | 93 | 94 | -------------------------------------------------------------------------------- /Nested Stacks/rootstack.json: -------------------------------------------------------------------------------- 1 | { 2 | "AWSTemplateFormatVersion" : "2010-09-09", 3 | "Resources" : { 4 | "myStack" : { 5 | "Type" : "AWS::CloudFormation::Stack", 6 | "Properties" : { 7 | "TemplateURL" : "https://s3.amazonaws.com/nestedstack945/s3static.json", 8 | "TimeoutInMinutes" : "60" 9 | } 10 | } 11 | } 12 | } -------------------------------------------------------------------------------- /Nested Stacks/s3static.json: -------------------------------------------------------------------------------- 1 | { 2 | "AWSTemplateFormatVersion": "2010-09-09", 3 | "Resources": { 4 | "S3Bucket": { 5 | "Type": "AWS::S3::Bucket", 6 | "Properties": { 7 | "AccessControl": "PublicRead", 8 | "WebsiteConfiguration": { 9 | "IndexDocument": "index.html", 10 | "ErrorDocument": "error.html" 11 | } 12 | }, 13 | "DeletionPolicy": "Retain" 14 | }, 15 | "BucketPolicy": { 16 | "Type": "AWS::S3::BucketPolicy", 17 | "Properties": { 18 | "PolicyDocument": { 19 | "Id": "MyPolicy", 20 | "Version": "2012-10-17", 21 | "Statement": [ 22 | { 23 | "Sid": "PublicReadForGetBucketObjects", 24 | "Effect": "Allow", 25 | "Principal": "*", 26 | "Action": "s3:GetObject", 27 | "Resource": { 28 | "Fn::Join": [ 29 | "", 30 | [ 31 | "arn:aws:s3:::", 32 | { 33 | "Ref": "S3Bucket" 34 | }, 35 | "/*" 36 | ] 37 | ] 38 | } 39 | } 40 | ] 41 | }, 42 | "Bucket": { 43 | "Ref": "S3Bucket" 44 | } 45 | } 46 | } 47 | }, 48 | "Outputs": { 49 | "WebsiteURL": { 50 | "Value": { 51 | "Fn::GetAtt": [ 52 | "S3Bucket", 53 | "WebsiteURL" 54 | ] 55 | }, 56 | "Description": "URL for website hosted on S3" 57 | }, 58 | "S3BucketSecureURL": { 59 | "Value": { 60 | "Fn::Join": [ 61 | "", 62 | [ 63 | "https://", 64 | { 65 | "Fn::GetAtt": [ 66 | "S3Bucket", 67 | "DomainName" 68 | ] 69 | } 70 | ] 71 | ] 72 | }, 73 | "Description": "Name of S3 bucket to hold website content" 74 | } 75 | } 76 | } -------------------------------------------------------------------------------- /StackPolicies/stackpolicies.json: -------------------------------------------------------------------------------- 1 | { 2 | "Statement" : [ 3 | { 4 | "Effect" : "Allow", 5 | "Action" : "Update:*", 6 | "Principal": "*", 7 | "Resource" : "*" 8 | }, 9 | { 10 | "Effect" : "Deny", 11 | "Action" : "Update:*", 12 | "Principal": "*", 13 | "Resource" : "LogicalResourceId/wordpressdb" 14 | } 15 | ] 16 | } 17 | 18 | 19 | { 20 | "Statement" : [ 21 | { 22 | "Effect" : "Deny_or_Allow", 23 | "Action" : "update_actions", 24 | "Principal" : "*", 25 | "Resource" : "LogicalResourceId/resource_logical_ID", 26 | "Condition" : { 27 | "StringEquals_or_StringLike" : { 28 | "ResourceType" : [resource_type, ...] 29 | } 30 | } 31 | }   32 | ] 33 | } 34 | 35 | 36 | { 37 | "Statement" : [ 38 | { 39 | "Effect" : "Deny", 40 | "Principal" : "*", 41 | "Action" : "Update:*", 42 | "Resource" : "*", 43 | "Condition" : { 44 | "StringEquals" : { 45 | "ResourceType" : ["AWS::EC2::Instance", "AWS::RDS::DBInstance"] 46 | } 47 | } 48 | }, 49 | { 50 | "Effect" : "Allow", 51 | "Principal" : "*", 52 | "Action" : "Update:*", 53 | "Resource" : "*" 54 | } 55 | ] 56 | } 57 | 58 | -------------------------------------------------------------------------------- /StackPolicies/wordpress-single-instance.yaml: -------------------------------------------------------------------------------- 1 | AWSTemplateFormatVersion: '2010-09-09' 2 | Description: 'AWS CloudFormation Sample Template WordPress_Single_Instance: WordPress 3 | is web software you can use to create a beautiful website or blog. This template 4 | installs WordPress with a local MySQL database for storage. It demonstrates using 5 | the AWS CloudFormation bootstrap scripts to deploy WordPress. **WARNING** This template 6 | creates an Amazon EC2 instance. You will be billed for the AWS resources used if 7 | you create a stack from this template.' 8 | Parameters: 9 | DBName: 10 | AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*' 11 | ConstraintDescription: must begin with a letter and contain only alphanumeric characters. 12 | Description: The WordPress database name 13 | MaxLength: '64' 14 | MinLength: '1' 15 | Type: String 16 | DBPassword: 17 | AllowedPattern: '[a-zA-Z0-9]*' 18 | ConstraintDescription: must contain only alphanumeric characters. 19 | Description: The WordPress database admin account password 20 | MaxLength: '41' 21 | MinLength: '8' 22 | NoEcho: 'true' 23 | Type: String 24 | DBRootPassword: 25 | AllowedPattern: '[a-zA-Z0-9]*' 26 | ConstraintDescription: must contain only alphanumeric characters. 27 | Description: MySQL root password 28 | MaxLength: '41' 29 | MinLength: '8' 30 | NoEcho: 'true' 31 | Type: String 32 | DBUser: 33 | AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*' 34 | ConstraintDescription: must begin with a letter and contain only alphanumeric characters. 35 | Description: The WordPress database admin account username 36 | MaxLength: '16' 37 | MinLength: '1' 38 | NoEcho: 'true' 39 | Type: String 40 | InstanceType: 41 | AllowedValues: 42 | - t1.micro 43 | - t2.nano 44 | - t2.micro 45 | - t2.small 46 | - t2.medium 47 | - t2.large 48 | - m1.small 49 | - m1.medium 50 | - m1.large 51 | - m1.xlarge 52 | - m2.xlarge 53 | - m2.2xlarge 54 | - m2.4xlarge 55 | - m3.medium 56 | - m3.large 57 | - m3.xlarge 58 | - m3.2xlarge 59 | - m4.large 60 | - m4.xlarge 61 | - m4.2xlarge 62 | - m4.4xlarge 63 | - m4.10xlarge 64 | - c1.medium 65 | - c1.xlarge 66 | - c3.large 67 | - c3.xlarge 68 | - c3.2xlarge 69 | - c3.4xlarge 70 | - c3.8xlarge 71 | - c4.large 72 | - c4.xlarge 73 | - c4.2xlarge 74 | - c4.4xlarge 75 | - c4.8xlarge 76 | - g2.2xlarge 77 | - g2.8xlarge 78 | - r3.large 79 | - r3.xlarge 80 | - r3.2xlarge 81 | - r3.4xlarge 82 | - r3.8xlarge 83 | - i2.xlarge 84 | - i2.2xlarge 85 | - i2.4xlarge 86 | - i2.8xlarge 87 | - d2.xlarge 88 | - d2.2xlarge 89 | - d2.4xlarge 90 | - d2.8xlarge 91 | - hi1.4xlarge 92 | - hs1.8xlarge 93 | - cr1.8xlarge 94 | - cc2.8xlarge 95 | - cg1.4xlarge 96 | ConstraintDescription: must be a valid EC2 instance type. 97 | Default: t2.small 98 | Description: WebServer EC2 instance type 99 | Type: String 100 | KeyName: 101 | ConstraintDescription: must be the name of an existing EC2 KeyPair. 102 | Description: Name of an existing EC2 KeyPair to enable SSH access to the instances 103 | Type: AWS::EC2::KeyPair::KeyName 104 | SSHLocation: 105 | AllowedPattern: (\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})/(\d{1,2}) 106 | ConstraintDescription: must be a valid IP CIDR range of the form x.x.x.x/x. 107 | Default: 0.0.0.0/0 108 | Description: The IP address range that can be used to SSH to the EC2 instances 109 | MaxLength: '18' 110 | MinLength: '9' 111 | Type: String 112 | Mappings: 113 | SubnetConfig: 114 | VPC: 115 | CIDR: 10.0.0.0/16 116 | Public: 117 | CIDR: 10.0.0.0/24 118 | Public1: 119 | CIDR: 10.0.1.0/24 120 | Public2: 121 | CIDR: 10.0.2.0/24 122 | AWSInstanceType2Arch: 123 | c1.medium: 124 | Arch: PV64 125 | c1.xlarge: 126 | Arch: PV64 127 | c3.2xlarge: 128 | Arch: HVM64 129 | c3.4xlarge: 130 | Arch: HVM64 131 | c3.8xlarge: 132 | Arch: HVM64 133 | c3.large: 134 | Arch: HVM64 135 | c3.xlarge: 136 | Arch: HVM64 137 | c4.2xlarge: 138 | Arch: HVM64 139 | c4.4xlarge: 140 | Arch: HVM64 141 | c4.8xlarge: 142 | Arch: HVM64 143 | c4.large: 144 | Arch: HVM64 145 | c4.xlarge: 146 | Arch: HVM64 147 | cc2.8xlarge: 148 | Arch: HVM64 149 | cr1.8xlarge: 150 | Arch: HVM64 151 | d2.2xlarge: 152 | Arch: HVM64 153 | d2.4xlarge: 154 | Arch: HVM64 155 | d2.8xlarge: 156 | Arch: HVM64 157 | d2.xlarge: 158 | Arch: HVM64 159 | g2.2xlarge: 160 | Arch: HVMG2 161 | g2.8xlarge: 162 | Arch: HVMG2 163 | hi1.4xlarge: 164 | Arch: HVM64 165 | hs1.8xlarge: 166 | Arch: HVM64 167 | i2.2xlarge: 168 | Arch: HVM64 169 | i2.4xlarge: 170 | Arch: HVM64 171 | i2.8xlarge: 172 | Arch: HVM64 173 | i2.xlarge: 174 | Arch: HVM64 175 | m1.large: 176 | Arch: PV64 177 | m1.medium: 178 | Arch: PV64 179 | m1.small: 180 | Arch: PV64 181 | m1.xlarge: 182 | Arch: PV64 183 | m2.2xlarge: 184 | Arch: PV64 185 | m2.4xlarge: 186 | Arch: PV64 187 | m2.xlarge: 188 | Arch: PV64 189 | m3.2xlarge: 190 | Arch: HVM64 191 | m3.large: 192 | Arch: HVM64 193 | m3.medium: 194 | Arch: HVM64 195 | m3.xlarge: 196 | Arch: HVM64 197 | m4.10xlarge: 198 | Arch: HVM64 199 | m4.2xlarge: 200 | Arch: HVM64 201 | m4.4xlarge: 202 | Arch: HVM64 203 | m4.large: 204 | Arch: HVM64 205 | m4.xlarge: 206 | Arch: HVM64 207 | r3.2xlarge: 208 | Arch: HVM64 209 | r3.4xlarge: 210 | Arch: HVM64 211 | r3.8xlarge: 212 | Arch: HVM64 213 | r3.large: 214 | Arch: HVM64 215 | r3.xlarge: 216 | Arch: HVM64 217 | t1.micro: 218 | Arch: PV64 219 | t2.large: 220 | Arch: HVM64 221 | t2.medium: 222 | Arch: HVM64 223 | t2.micro: 224 | Arch: HVM64 225 | t2.nano: 226 | Arch: HVM64 227 | t2.small: 228 | Arch: HVM64 229 | AWSInstanceType2NATArch: 230 | c1.medium: 231 | Arch: NATPV64 232 | c1.xlarge: 233 | Arch: NATPV64 234 | c3.2xlarge: 235 | Arch: NATHVM64 236 | c3.4xlarge: 237 | Arch: NATHVM64 238 | c3.8xlarge: 239 | Arch: NATHVM64 240 | c3.large: 241 | Arch: NATHVM64 242 | c3.xlarge: 243 | Arch: NATHVM64 244 | c4.2xlarge: 245 | Arch: NATHVM64 246 | c4.4xlarge: 247 | Arch: NATHVM64 248 | c4.8xlarge: 249 | Arch: NATHVM64 250 | c4.large: 251 | Arch: NATHVM64 252 | c4.xlarge: 253 | Arch: NATHVM64 254 | cc2.8xlarge: 255 | Arch: NATHVM64 256 | cr1.8xlarge: 257 | Arch: NATHVM64 258 | d2.2xlarge: 259 | Arch: NATHVM64 260 | d2.4xlarge: 261 | Arch: NATHVM64 262 | d2.8xlarge: 263 | Arch: NATHVM64 264 | d2.xlarge: 265 | Arch: NATHVM64 266 | g2.2xlarge: 267 | Arch: NATHVMG2 268 | g2.8xlarge: 269 | Arch: NATHVMG2 270 | hi1.4xlarge: 271 | Arch: NATHVM64 272 | hs1.8xlarge: 273 | Arch: NATHVM64 274 | i2.2xlarge: 275 | Arch: NATHVM64 276 | i2.4xlarge: 277 | Arch: NATHVM64 278 | i2.8xlarge: 279 | Arch: NATHVM64 280 | i2.xlarge: 281 | Arch: NATHVM64 282 | m1.large: 283 | Arch: NATPV64 284 | m1.medium: 285 | Arch: NATPV64 286 | m1.small: 287 | Arch: NATPV64 288 | m1.xlarge: 289 | Arch: NATPV64 290 | m2.2xlarge: 291 | Arch: NATPV64 292 | m2.4xlarge: 293 | Arch: NATPV64 294 | m2.xlarge: 295 | Arch: NATPV64 296 | m3.2xlarge: 297 | Arch: NATHVM64 298 | m3.large: 299 | Arch: NATHVM64 300 | m3.medium: 301 | Arch: NATHVM64 302 | m3.xlarge: 303 | Arch: NATHVM64 304 | m4.10xlarge: 305 | Arch: NATHVM64 306 | m4.2xlarge: 307 | Arch: NATHVM64 308 | m4.4xlarge: 309 | Arch: NATHVM64 310 | m4.large: 311 | Arch: NATHVM64 312 | m4.xlarge: 313 | Arch: NATHVM64 314 | r3.2xlarge: 315 | Arch: NATHVM64 316 | r3.4xlarge: 317 | Arch: NATHVM64 318 | r3.8xlarge: 319 | Arch: NATHVM64 320 | r3.large: 321 | Arch: NATHVM64 322 | r3.xlarge: 323 | Arch: NATHVM64 324 | t1.micro: 325 | Arch: NATPV64 326 | t2.large: 327 | Arch: NATHVM64 328 | t2.medium: 329 | Arch: NATHVM64 330 | t2.micro: 331 | Arch: NATHVM64 332 | t2.nano: 333 | Arch: NATHVM64 334 | t2.small: 335 | Arch: NATHVM64 336 | AWSRegionArch2AMI: 337 | ap-northeast-1: 338 | HVM64: ami-383c1956 339 | HVMG2: ami-08e5c166 340 | PV64: ami-393c1957 341 | ap-northeast-2: 342 | HVM64: ami-249b554a 343 | HVMG2: NOT_SUPPORTED 344 | PV64: NOT_SUPPORTED 345 | ap-southeast-1: 346 | HVM64: ami-c9b572aa 347 | HVMG2: ami-5a15d239 348 | PV64: ami-34bd7a57 349 | ap-southeast-2: 350 | HVM64: ami-48d38c2b 351 | HVMG2: ami-0c1a446f 352 | PV64: ami-ced887ad 353 | cn-north-1: 354 | HVM64: ami-43a36a2e 355 | HVMG2: NOT_SUPPORTED 356 | PV64: ami-18ac6575 357 | eu-central-1: 358 | HVM64: ami-bc5b48d0 359 | HVMG2: ami-ba1a09d6 360 | PV64: ami-794a5915 361 | eu-west-1: 362 | HVM64: ami-bff32ccc 363 | HVMG2: ami-83fd23f0 364 | PV64: ami-95e33ce6 365 | sa-east-1: 366 | HVM64: ami-6817af04 367 | HVMG2: NOT_SUPPORTED 368 | PV64: ami-7d15ad11 369 | us-east-1: 370 | HVM64: ami-60b6c60a 371 | HVMG2: ami-e998ea83 372 | PV64: ami-5fb8c835 373 | us-west-1: 374 | HVM64: ami-d5ea86b5 375 | HVMG2: ami-943956f4 376 | PV64: ami-56ea8636 377 | us-west-2: 378 | HVM64: ami-f0091d91 379 | HVMG2: ami-315f4850 380 | PV64: ami-d93622b8 381 | Resources: 382 | VPC: 383 | Type: 'AWS::EC2::VPC' 384 | Properties: 385 | EnableDnsSupport: 'true' 386 | EnableDnsHostnames: 'true' 387 | CidrBlock: !FindInMap 388 | - SubnetConfig 389 | - VPC 390 | - CIDR 391 | Tags: 392 | - Key: Application 393 | Value: !Ref 'AWS::StackName' 394 | - Key: Network 395 | Value: Public 396 | WebServer: 397 | Type: AWS::EC2::Instance 398 | Properties: 399 | SubnetId: '10.0.0.0/24' 400 | CreationPolicy: 401 | ResourceSignal: 402 | Timeout: PT15M 403 | Metadata: 404 | AWS::CloudFormation::Init: 405 | configSets: 406 | wordpress_install: 407 | - install_cfn 408 | - install_wordpress 409 | - configure_wordpress 410 | configure_wordpress: 411 | commands: 412 | 01_set_mysql_root_password: 413 | command: !Sub | 414 | mysqladmin -u root password '${DBRootPassword}' 415 | test: !Sub | 416 | $(mysql ${DBName} -u root --password='${DBRootPassword}' >/dev/null 2>&1 /dev/null 2>&1 \n", 120 | " \n", 121 | " AWS CloudFormation PHP Sample\n", 122 | " \n", 123 | " \n", 124 | " \n", 125 | "

Welcome to the AWS CloudFormation PHP Sample

\n", 126 | "

\n", 127 | " \";\n", 130 | " print date(\"g:i A l, F j Y.\");\n", 131 | " ?>\n", 132 | "

\n", 133 | " \";\n", 138 | " $dbconnection = mysql_connect($Database, $DBUser, $DBPassword)\n", 139 | " or die(\"Could not connect: \" . mysql_error());\n", 140 | " print (\"Connected to $Database successfully\");\n", 141 | " mysql_close($dbconnection);\n", 142 | " ?>\n", 143 | " \n", 144 | "\n" 145 | ]]}, 146 | "mode" : "000600", 147 | "owner" : "apache", 148 | "group" : "apache" 149 | }, 150 | 151 | "/tmp/setup.mysql" : { 152 | "content" : { "Fn::Join" : ["", [ 153 | "CREATE DATABASE ", { "Ref" : "DBName" }, ";\n", 154 | "GRANT ALL ON ", { "Ref" : "DBName" }, ".* TO '", { "Ref" : "DBUser" }, "'@localhost IDENTIFIED BY '", { "Ref" : "DBPassword" }, "';\n" 155 | ]]}, 156 | "mode" : "000400", 157 | "owner" : "root", 158 | "group" : "root" 159 | }, 160 | "/etc/cfn/cfn-hup.conf" : { 161 | "content" : { "Fn::Join" : ["", [ 162 | "[main]\n", 163 | "stack=", { "Ref" : "AWS::StackId" }, "\n", 164 | "region=", { "Ref" : "AWS::Region" }, "\n", 165 | "interval=6", "\n" 166 | ]]}, 167 | "mode" : "000400", 168 | "owner" : "root", 169 | "group" : "root" 170 | }, 171 | 172 | "/etc/cfn/hooks.d/cfn-auto-reloader.conf" : { 173 | "content": { "Fn::Join" : ["", [ 174 | "[cfn-auto-reloader-hook]\n", 175 | "triggers=post.update\n", 176 | "path=Resources.WebServerInstance.Metadata.AWS::CloudFormation::Init\n", 177 | "action=/opt/aws/bin/cfn-init -v ", 178 | " --stack ", { "Ref" : "AWS::StackName" }, 179 | " --resource WebServerInstance ", 180 | " --configsets InstallAndRun ", 181 | " --region ", { "Ref" : "AWS::Region" }, "\n", 182 | "runas=root\n" 183 | ]]} 184 | } 185 | }, 186 | 187 | "services" : { 188 | "sysvinit" : { 189 | "mysqld" : { "enabled" : "true", "ensureRunning" : "true" }, 190 | "httpd" : { "enabled" : "true", "ensureRunning" : "true" }, 191 | "cfn-hup" : { "enabled" : "true", "ensureRunning" : "true", 192 | "files" : ["/etc/cfn/cfn-hup.conf", "/etc/cfn/hooks.d/cfn-auto-reloader.conf"]} 193 | } 194 | } 195 | }, 196 | 197 | "Configure" : { 198 | "commands" : { 199 | "01_set_mysql_root_password" : { 200 | "command" : { "Fn::Join" : ["", ["mysqladmin -u root password '", { "Ref" : "DBRootPassword" }, "'"]]}, 201 | "test" : { "Fn::Join" : ["", ["$(mysql ", { "Ref" : "DBName" }, " -u root --password='", { "Ref" : "DBRootPassword" }, "' >/dev/null 2>&1 /dev/null 2>&1 Welcome to your application" > /var/www/html/index.html && \ 7 | chmod 644 /var/www/html/index.html && \ 8 | chown root:root /var/www/html/index.html && \ 9 | INSTANCE_ID="`wget -q -O - http://instance-data/latest/meta-data/instance-id`" && \ 10 | aws autoscaling complete-lifecycle-action --lifecycle-action-result CONTINUE --instance-id $INSTANCE_ID --lifecycle-hook-name devops-pro-hook --auto-scaling-group-name devopsASG --region us-east-1 || \ 11 | aws autoscaling complete-lifecycle-action --lifecycle-action-result ABANDON --instance-id $INSTANCE_ID --lifecycle-hook-name devops-pro-hook --auto-scaling-group-name devopsASG --region us-east-1 -------------------------------------------------------------------------------- /userdataForLifeCycleHooks.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | yum update -y && \ 3 | yum install -y httpd && \ 4 | service httpd start && \ 5 | chkconfig httpd on && \ 6 | echo "

Welcome to your application

" > /var/www/html/index.html && \ 7 | chmod 644 /var/www/html/index.html && \ 8 | chown root:root /var/www/html/index.html && \ 9 | INSTANCE_ID="`wget -q -O - http://instance-data/latest/meta-data/instance-id`" && \ 10 | aws autoscaling complete-lifecycle-action --lifecycle-action-result CONTINUE --instance-id $INSTANCE_ID --lifecycle-hook-name devops-pro-hook --auto-scaling-group-name devopsASG --region us-east-1 || \ 11 | aws autoscaling complete-lifecycle-action --lifecycle-action-result ABANDON --instance-id $INSTANCE_ID --lifecycle-hook-name devops-pro-hook --auto-scaling-group-name devopsASG --region us-east-1 --------------------------------------------------------------------------------