Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save alekseybobkov/d29558c7f3b27b89c42954ec76f86cc7 to your computer and use it in GitHub Desktop.
Save alekseybobkov/d29558c7f3b27b89c42954ec76f86cc7 to your computer and use it in GitHub Desktop.
CloudFormation template for October CMS demo AWS infrastructure, Part 2: https://octobercms.com/blog/post/running-october-aws-part-2
{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "October CMS demo infrastructure.",
"Parameters": {
"KeyName": {
"Description": "Name of an existing EC2 KeyPair to enable SSH access to the instance",
"Type": "AWS::EC2::KeyPair::KeyName",
"ConstraintDescription": "must be the name of an existing EC2 KeyPair."
},
"StagingInstanceType": {
"Description": "Staging instance EC2 instance type",
"Type": "String",
"Default": "t2.micro",
"AllowedValues": ["t1.micro", "t2.nano", "t2.micro", "t2.small", "t2.medium", "t2.large"],
"ConstraintDescription": "must be a valid EC2 instance type."
},
"DBName": {
"Default": "MyDatabase",
"Description": "MySQL database name",
"Type": "String",
"MinLength": "1",
"MaxLength": "64",
"AllowedPattern": "[a-zA-Z][a-zA-Z0-9]*",
"ConstraintDescription": "must begin with a letter and contain only alphanumeric characters."
},
"DBUser": {
"NoEcho": "true",
"Description": "Username for MySQL database access",
"Type": "String",
"MinLength": "1",
"MaxLength": "16",
"AllowedPattern": "[a-zA-Z][a-zA-Z0-9]*",
"ConstraintDescription": "must begin with a letter and contain only alphanumeric characters."
},
"DBPassword": {
"NoEcho": "true",
"Description": "Password MySQL database access",
"Type": "String",
"MinLength": "8",
"MaxLength": "41",
"AllowedPattern": "[a-zA-Z0-9]*",
"ConstraintDescription": "must contain only alphanumeric characters."
},
"DBClass": {
"Description": "Database instance class",
"Type": "String",
"Default": "db.t2.micro",
"AllowedValues": ["db.t2.micro", "db.t2.small", "db.t2.medium", "db.t2.large"],
"ConstraintDescription": "must be a valid RDS instance class."
},
"DBAllocatedStorage": {
"Default": 100,
"Description": "The size of the database (Gb)",
"Type": "Number",
"MinValue": 5,
"MaxValue": 1024,
"ConstraintDescription": "must be between 5 and 1024Gb."
},
"StagingImageId": {
"Type": "AWS::EC2::Image::Id",
"ConstraintDescription": "must be a valid AMI identifier."
}
},
"Resources": {
"VPC": {
"Type": "AWS::EC2::VPC",
"Properties": {
"CidrBlock": "10.0.0.0/16",
"EnableDnsSupport": true,
"EnableDnsHostnames": true,
"Tags": [{
"Key": "Application",
"Value": {
"Ref": "AWS::StackId"
}
},
{
"Key": "Name",
"Value": "October CMS VPC"
}
]
}
},
"PublicSubnet": {
"Type": "AWS::EC2::Subnet",
"Properties": {
"VpcId": {
"Ref": "VPC"
},
"MapPublicIpOnLaunch": "true",
"CidrBlock": "10.0.1.0/24",
"AvailabilityZone": "us-west-2a",
"Tags": [{
"Key": "Application",
"Value": {
"Ref": "AWS::StackId"
}
},
{
"Key": "Name",
"Value": "October CMS Public Subnet"
}
]
}
},
"DBSubnet1": {
"Type": "AWS::EC2::Subnet",
"Properties": {
"AvailabilityZone": {
"Fn::Select": [
"0",
{
"Fn::GetAZs": ""
}
]
},
"CidrBlock": "10.0.3.0/24",
"Tags": [{
"Key": "Application",
"Value": {
"Ref": "AWS::StackId"
}
},
{
"Key": "Name",
"Value": "October CMS DB Subnet 1"
}
],
"VpcId": {
"Ref": "VPC"
}
}
},
"DBSubnet2": {
"Type": "AWS::EC2::Subnet",
"Properties": {
"AvailabilityZone": {
"Fn::Select": [
"1",
{
"Fn::GetAZs": ""
}
]
},
"CidrBlock": "10.0.4.0/24",
"Tags": [{
"Key": "Application",
"Value": {
"Ref": "AWS::StackId"
}
},
{
"Key": "Name",
"Value": "October CMS DB Subnet 2"
}
],
"VpcId": {
"Ref": "VPC"
}
}
},
"DBSubnetGroup": {
"Properties": {
"DBSubnetGroupDescription": "October CMS subnets for RDS",
"SubnetIds": [{
"Ref": "DBSubnet1"
},
{
"Ref": "DBSubnet2"
}
]
},
"Type": "AWS::RDS::DBSubnetGroup"
},
"InternetGateway": {
"Type": "AWS::EC2::InternetGateway",
"Properties": {
"Tags": [{
"Key": "Application",
"Value": {
"Ref": "AWS::StackId"
}
},
{
"Key": "Name",
"Value": "October CMS Gateway"
}
]
}
},
"AttachGateway": {
"Type": "AWS::EC2::VPCGatewayAttachment",
"Properties": {
"VpcId": {
"Ref": "VPC"
},
"InternetGatewayId": {
"Ref": "InternetGateway"
}
}
},
"InternetAccessRouteTable": {
"Type": "AWS::EC2::RouteTable",
"Properties": {
"VpcId": {
"Ref": "VPC"
},
"Tags": [{
"Key": "Application",
"Value": {
"Ref": "AWS::StackId"
}
},
{
"Key": "Name",
"Value": "October CMS VPC Internet Access"
}
]
}
},
"InternetAccessRoute": {
"Type": "AWS::EC2::Route",
"DependsOn": "AttachGateway",
"Properties": {
"RouteTableId": {
"Ref": "InternetAccessRouteTable"
},
"DestinationCidrBlock": "0.0.0.0/0",
"GatewayId": {
"Ref": "InternetGateway"
}
}
},
"PublicSubnetRouteTableAssociation": {
"Type": "AWS::EC2::SubnetRouteTableAssociation",
"Properties": {
"SubnetId": {
"Ref": "PublicSubnet"
},
"RouteTableId": {
"Ref": "InternetAccessRouteTable"
}
}
},
"WebServerSecurityGroup": {
"Type": "AWS::EC2::SecurityGroup",
"Properties": {
"GroupDescription": "Enable SSH access via ports 80 and 22",
"SecurityGroupIngress": [{
"IpProtocol": "tcp",
"FromPort": "22",
"ToPort": "22",
"CidrIp": "0.0.0.0/0"
},
{
"IpProtocol": "tcp",
"FromPort": "80",
"ToPort": "80",
"CidrIp": "0.0.0.0/0"
}
],
"VpcId": {
"Ref": "VPC"
},
"Tags": [{
"Key": "Application",
"Value": {
"Ref": "AWS::StackId"
}
},
{
"Key": "Name",
"Value": "October CMS Web Server SG"
}
]
}
},
"MountTargetSecurityGroup": {
"Type": "AWS::EC2::SecurityGroup",
"Properties": {
"VpcId": {
"Ref": "VPC"
},
"GroupDescription": "Security group for EFS mount target",
"SecurityGroupIngress": [{
"IpProtocol": "tcp",
"FromPort": "2049",
"ToPort": "2049",
"SourceSecurityGroupId": {
"Fn::GetAtt": [
"WebServerSecurityGroup",
"GroupId"
]
}
}],
"Tags": [{
"Key": "Application",
"Value": {
"Ref": "AWS::StackId"
}
},
{
"Key": "Name",
"Value": "October CMS EFS mount target SG"
}
]
}
},
"DBSecurityGroup": {
"Type": "AWS::EC2::SecurityGroup",
"Properties": {
"GroupDescription": "Open database for access from web servers",
"VpcId": {
"Ref": "VPC"
},
"SecurityGroupIngress": [{
"IpProtocol": "tcp",
"FromPort": "3306",
"ToPort": "3306",
"SourceSecurityGroupId": {
"Fn::GetAtt": [
"WebServerSecurityGroup",
"GroupId"
]
}
}],
"Tags": [{
"Key": "Application",
"Value": {
"Ref": "AWS::StackId"
}
},
{
"Key": "Name",
"Value": "October CMS database SG"
}
]
}
},
"FileSystem": {
"Type": "AWS::EFS::FileSystem",
"Properties": {
"PerformanceMode": "generalPurpose",
"FileSystemTags": [{
"Key": "Application",
"Value": {
"Ref": "AWS::StackId"
}
},
{
"Key": "Name",
"Value": "October CMS file data"
}
]
}
},
"DBInstance": {
"Type": "AWS::RDS::DBInstance",
"Properties": {
"DBName": {
"Ref": "DBName"
},
"MasterUsername": {
"Ref": "DBUser"
},
"MasterUserPassword": {
"Ref": "DBPassword"
},
"Engine": "MySQL",
"DBInstanceClass": {
"Ref": "DBClass"
},
"AllocatedStorage": {
"Ref": "DBAllocatedStorage"
},
"StorageType": "gp2",
"VPCSecurityGroups": [{
"Fn::GetAtt": ["DBSecurityGroup", "GroupId"]
}],
"DBSubnetGroupName": {
"Ref": "DBSubnetGroup"
},
"Tags": [{
"Key": "Application",
"Value": {
"Ref": "AWS::StackId"
}
},
{
"Key": "Name",
"Value": "October CMS MySQL"
}
]
}
},
"MountTarget": {
"Type": "AWS::EFS::MountTarget",
"Properties": {
"FileSystemId": {
"Ref": "FileSystem"
},
"SubnetId": {
"Ref": "PublicSubnet"
},
"SecurityGroups": [{
"Ref": "MountTargetSecurityGroup"
}]
}
},
"StagingInstance": {
"Type": "AWS::EC2::Instance",
"Metadata" : {
"AWS::CloudFormation::Init" : {
"config" : {
"files" : {
"/var/www/html/.env" : {
"content": { "Fn::Join" : ["", [
"APP_DEBUG=false\n",
"APP_URL=http://54.188.246.198/\n",
"APP_KEY=YOUR-APP-KEY\n",
"DB_CONNECTION=mysql\n",
"DB_HOST=",{ "Fn::GetAtt": [ "DBInstance", "Endpoint.Address" ] },"\n",
"DB_PORT=",{ "Fn::GetAtt": [ "DBInstance", "Endpoint.Port" ] },"\n",
"DB_DATABASE=",{ "Ref" : "DBName" },"\n",
"DB_USERNAME=",{ "Ref" : "DBUser" },"\n",
"DB_PASSWORD=",{ "Ref" : "DBPassword" },"\n",
"REDIS_HOST=127.0.0.1\n",
"REDIS_PASSWORD=null\n",
"REDIS_PORT=6379\n",
"CACHE_DRIVER=file\n",
"SESSION_DRIVER=database\n",
"QUEUE_DRIVER=sync\n",
"MAIL_DRIVER=smtp\n",
"MAIL_HOST=smtp.mailgun.org\n",
"MAIL_PORT=587\n",
"MAIL_ENCRYPTION=tls\n",
"MAIL_USERNAME=null\n",
"MAIL_PASSWORD=null\n",
"ROUTES_CACHE=false\n",
"ASSET_CACHE=false\n",
"LINK_POLICY=detect\n",
"ENABLE_CSRF=true"
]]}
}
}
}
}
},
"Properties": {
"ImageId": {
"Ref": "StagingImageId"
},
"KeyName": {
"Ref": "KeyName"
},
"InstanceType": {
"Ref": "StagingInstanceType"
},
"UserData" : { "Fn::Base64" : { "Fn::Join" : ["", [
"Content-Type: multipart/mixed; boundary=\"//\"\n",
"MIME-Version: 1.0\n",
"\n",
"--//\n",
"Content-Type: text/cloud-config; charset=\"us-ascii\"\n",
"MIME-Version: 1.0\n",
"Content-Transfer-Encoding: 7bit\n",
"Content-Disposition: attachment; filename=\"cloud-config.txt\"\n",
"\n",
"#cloud-config\n",
"cloud_final_modules:\n",
"- [scripts-user, always]\n",
"\n",
"--//\n",
"Content-Type: text/x-shellscript; charset=\"us-ascii\"\n",
"MIME-Version: 1.0\n",
"Content-Transfer-Encoding: 7bit\n",
"Content-Disposition: attachment; filename=\"userdata.txt\"\n",
"\n",
"#!/bin/bash\n",
"yum update -y aws-cfn-bootstrap\n",
"mkdir -p /mnt/october-efs\n",
"mount -t efs ", { "Ref" : "FileSystem" }, ":/ /mnt/october-efs\n",
"chown ec2-user:apache /mnt/october-efs\n",
"/opt/aws/bin/cfn-init -v ",
" --stack ", { "Ref" : "AWS::StackName" },
" --resource StagingInstance ",
" --region ", { "Ref" : "AWS::Region" }, "\n",
"--//\n"
]]}},
"NetworkInterfaces": [{
"AssociatePublicIpAddress": "true",
"DeviceIndex": "0",
"GroupSet": [{
"Ref": "WebServerSecurityGroup"
}],
"SubnetId": {
"Ref": "PublicSubnet"
}
}],
"Tags": [{
"Key": "Application",
"Value": {
"Ref": "AWS::StackId"
}
},
{
"Key": "Name",
"Value": "October CMS Staging Instance"
}
]
},
"DependsOn": ["FileSystem", "MountTarget"]
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment