Skip to content

Instantly share code, notes, and snippets.

@dassio
Created December 7, 2018 17:57
Show Gist options
  • Save dassio/8424a61d15df79456e18c7caba020ba6 to your computer and use it in GitHub Desktop.
Save dassio/8424a61d15df79456e18c7caba020ba6 to your computer and use it in GitHub Desktop.
setup onos cell with ubuntu 18 on aws
{
"AWSTemplateFormatVersion" : "2010-09-09",
"Description" : "AWS CloudFormation Sample Template VPC_Single_Instance_In_Subnet: Sample template showing how to create a VPC and add an EC2 instance with an Elastic IP address and a security group. **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.",
"Parameters" : {
"InstanceType" : {
"Description" : "Onos Instance",
"Type" : "String",
"Default" : "t2.medium",
"AllowedValues" : [ "t2.medium"],
"ConstraintDescription" : "must be a valid EC2 instance type."
},
"KeyName": {
"Description" : "Name of an existing EC2 KeyPair to enable SSH access to the instance",
"Type": "AWS::EC2::KeyPair::KeyName",
"Default" : "onos-germany",
"ConstraintDescription" : "must be the name of an existing EC2 KeyPair."
},
"SSHLocation" : {
"Description" : " The IP address range that can be used to SSH to the EC2 instances",
"Type": "String",
"MinLength": "9",
"MaxLength": "18",
"Default": "0.0.0.0/0",
"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."
}
},
"Mappings": {
"AWSInstanceType2Ubuntu": {
"t2.medium": {"Ubuntu": "HVM64"}
},
"AWSRegionUbuntu2AMI": {
"eu-west-1": {
"HVM64": "ami-09f0b8b3e41191524"
},
"eu-west-2": {
"HVM64": "ami-0b0a60c0a2bd40612"
},
"eu-west-3": {
"HVM64": "ami-08182c55a1c188dee"
},
"eu-central-1": {
"HVM64": "ami-0bdf93799014acdc4"
}
}
},
"Resources" : {
"VPC" : {
"Type" : "AWS::EC2::VPC",
"Properties" : {
"CidrBlock" : "10.0.0.0/16",
"Tags": [
{
"Key": "Name",
"Value": "Onos Network"
}
]
}
},
"PulicSubnet" : {
"Type" : "AWS::EC2::Subnet",
"Properties" : {
"VpcId" : { "Ref" : "VPC" },
"CidrBlock" : "10.0.0.0/24",
"Tags": [
{
"Key": "Name",
"Value": "Public Network"
}
]
}
},
"PrivateSubnet" : {
"Type" : "AWS::EC2::Subnet",
"Properties" : {
"VpcId" : { "Ref" : "VPC" },
"CidrBlock" : "10.0.1.0/24",
"Tags": [
{
"Key": "Name",
"Value": "Private Network"
}
]
}
},
"InternetGateway" : {
"Type" : "AWS::EC2::InternetGateway",
"Properties" : {}
},
"AttachGateway" : {
"Type" : "AWS::EC2::VPCGatewayAttachment",
"Properties" : {
"VpcId" : { "Ref" : "VPC" },
"InternetGatewayId" : { "Ref" : "InternetGateway" }
}
},
"NAT" : {
"DependsOn" : "AttachGateway",
"Type" : "AWS::EC2::NatGateway",
"Properties" : {
"AllocationId" : { "Fn::GetAtt" : ["NATEIP", "AllocationId"]},
"SubnetId" : { "Ref" : "PulicSubnet"},
"Tags": [
{
"Key": "Name",
"Value": "onos-private-nat-gateway"
}
]
}
},
"NATEIP" : {
"Type" : "AWS::EC2::EIP",
"Properties" : {
"Domain" : "vpc"
}
},
"PublicRouteTable" : {
"Type" : "AWS::EC2::RouteTable",
"Properties" : {
"VpcId" : {"Ref" : "VPC"},
"Tags": [
{
"Key": "Name",
"Value": "Public Route Table"
}
]
}
},
"PrivateRouteTable" : {
"Type" : "AWS::EC2::RouteTable",
"Properties" : {
"VpcId" : {"Ref" : "VPC"},
"Tags": [
{
"Key": "Name",
"Value": "Private Route Table"
}
]
}
},
"PublicRoute" : {
"Type" : "AWS::EC2::Route",
"DependsOn" : "AttachGateway",
"Properties" : {
"RouteTableId" : { "Ref" : "PublicRouteTable" },
"DestinationCidrBlock" : "0.0.0.0/0",
"GatewayId" : { "Ref" : "InternetGateway" }
}
},
"PrivateRoute" : {
"Type" : "AWS::EC2::Route",
"Properties" : {
"RouteTableId" : { "Ref" : "PrivateRouteTable" },
"DestinationCidrBlock" : "0.0.0.0/0",
"NatGatewayId" : { "Ref" : "NAT" }
}
},
"PublicSubnetRouteTableAssociation" : {
"Type" : "AWS::EC2::SubnetRouteTableAssociation",
"Properties" : {
"SubnetId" : { "Ref" : "PulicSubnet" },
"RouteTableId" : { "Ref" : "PublicRouteTable" }
}
},
"PrivateSubnetRouteTableAssociation" : {
"Type" : "AWS::EC2::SubnetRouteTableAssociation",
"Properties" : {
"SubnetId" : { "Ref" : "PrivateSubnet" },
"RouteTableId" : { "Ref" : "PrivateRouteTable" }
}
},
"NetworkAcl" : {
"Type" : "AWS::EC2::NetworkAcl",
"Properties" : {
"VpcId" : {"Ref" : "VPC"},
"Tags": [
{
"Key": "Name",
"Value": "Public subnet ACL"
}
]
}
},
"InboundHTTPNetworkAclEntry" : {
"Type" : "AWS::EC2::NetworkAclEntry",
"Properties" : {
"NetworkAclId" : {"Ref" : "NetworkAcl"},
"RuleNumber" : "100",
"Protocol" : "6",
"RuleAction" : "allow",
"Egress" : "false",
"CidrBlock" : "0.0.0.0/0",
"PortRange" : {"From" : "80", "To" : "80"}
}
},
"InboundSSHNetworkAclEntry" : {
"Type" : "AWS::EC2::NetworkAclEntry",
"Properties" : {
"NetworkAclId" : {"Ref" : "NetworkAcl"},
"RuleNumber" : "101",
"Protocol" : "6",
"RuleAction" : "allow",
"Egress" : "false",
"CidrBlock" : "0.0.0.0/0",
"PortRange" : {"From" : "22", "To" : "22"}
}
},
"InboundResponsePortsNetworkAclEntry" : {
"Type" : "AWS::EC2::NetworkAclEntry",
"Properties" : {
"NetworkAclId" : {"Ref" : "NetworkAcl"},
"RuleNumber" : "102",
"Protocol" : "6",
"RuleAction" : "allow",
"Egress" : "false",
"CidrBlock" : "0.0.0.0/0",
"PortRange" : {"From" : "1024", "To" : "65535"}
}
},
"OutBoundHTTPNetworkAclEntry" : {
"Type" : "AWS::EC2::NetworkAclEntry",
"Properties" : {
"NetworkAclId" : {"Ref" : "NetworkAcl"},
"RuleNumber" : "100",
"Protocol" : "6",
"RuleAction" : "allow",
"Egress" : "true",
"CidrBlock" : "0.0.0.0/0",
"PortRange" : {"From" : "80", "To" : "80"}
}
},
"OutBoundHTTPSNetworkAclEntry" : {
"Type" : "AWS::EC2::NetworkAclEntry",
"Properties" : {
"NetworkAclId" : {"Ref" : "NetworkAcl"},
"RuleNumber" : "101",
"Protocol" : "6",
"RuleAction" : "allow",
"Egress" : "true",
"CidrBlock" : "0.0.0.0/0",
"PortRange" : {"From" : "443", "To" : "443"}
}
},
"OutBoundResponsePortsNetworkAclEntry" : {
"Type" : "AWS::EC2::NetworkAclEntry",
"Properties" : {
"NetworkAclId" : {"Ref" : "NetworkAcl"},
"RuleNumber" : "102",
"Protocol" : "6",
"RuleAction" : "allow",
"Egress" : "true",
"CidrBlock" : "0.0.0.0/0",
"PortRange" : {"From" : "1024", "To" : "65535"}
}
},
"InboundICMP" : {
"Type" : "AWS::EC2::NetworkAclEntry",
"Properties" : {
"NetworkAclId" : {"Ref" : "NetworkAcl"},
"RuleNumber" : "103",
"Icmp" : {"Code" : -1,"Type" : -1},
"Protocol" : "1",
"RuleAction" : "allow",
"Egress" : "false",
"CidrBlock" : "0.0.0.0/0",
"PortRange" : {"From" : "0", "To" : "65535"}
}
},
"OutboundICMP" : {
"Type" : "AWS::EC2::NetworkAclEntry",
"Properties" : {
"NetworkAclId" : {"Ref" : "NetworkAcl"},
"RuleNumber" : "103",
"Icmp" : {"Code" : -1,"Type" : -1},
"Protocol" : "1",
"RuleAction" : "allow",
"Egress" : "true",
"CidrBlock" : "0.0.0.0/0",
"PortRange" : {"From" : "0", "To" : "65535"}
}
},
"SubnetNetworkAclAssociation" : {
"Type" : "AWS::EC2::SubnetNetworkAclAssociation",
"Properties" : {
"SubnetId" : { "Ref" : "PublicSubnet" },
"NetworkAclId" : { "Ref" : "NetworkAcl" }
}
},
"OnosNetworkAcl" : {
"Type" : "AWS::EC2::NetworkAcl",
"Properties" : {
"VpcId" : {"Ref" : "VPC"},
"Tags": [
{
"Key": "Name",
"Value": "private subnet ACL"
}
]
}
},
"TCPAllPortsInbound" : {
"Type" : "AWS::EC2::NetworkAclEntry",
"Properties" : {
"NetworkAclId" : {"Ref" : "OnosNetworkAcl"},
"RuleNumber" : "104",
"Protocol" : "6",
"RuleAction" : "allow",
"Egress" : "false",
"CidrBlock" : "0.0.0.0/0",
"PortRange" : {"From" : "0", "To" : "65535"}
}
},
"TCPAllPortsOutbound" : {
"Type" : "AWS::EC2::NetworkAclEntry",
"Properties" : {
"NetworkAclId" : {"Ref" : "OnosNetworkAcl"},
"RuleNumber" : "104",
"Protocol" : "6",
"RuleAction" : "allow",
"Egress" : "true",
"CidrBlock" : "0.0.0.0/0",
"PortRange" : {"From" : "0", "To" : "65535"}
}
},
"ICMPAllPortsInbound" : {
"Type" : "AWS::EC2::NetworkAclEntry",
"Properties" : {
"NetworkAclId" : {"Ref" : "OnosNetworkAcl"},
"RuleNumber" : "105",
"Icmp" : {"Code" : -1,"Type" : -1},
"Protocol" : "1",
"RuleAction" : "allow",
"Egress" : "false",
"CidrBlock" : "0.0.0.0/0",
"PortRange" : {"From" : "0", "To" : "65535"}
}
},
"ICMPAllPortsOutbound" : {
"Type" : "AWS::EC2::NetworkAclEntry",
"Properties" : {
"NetworkAclId" : {"Ref" : "OnosNetworkAcl"},
"RuleNumber" : "105",
"Icmp" : {"Code" : -1,"Type" : -1},
"Protocol" : "1",
"RuleAction" : "allow",
"Egress" : "true",
"CidrBlock" : "0.0.0.0/0",
"PortRange" : {"From" : "0", "To" : "65535"}
}
},
"SubnetNetworkAclAssociation" : {
"Type" : "AWS::EC2::SubnetNetworkAclAssociation",
"Properties" : {
"SubnetId" : { "Ref" : "PrivateSubnet" },
"NetworkAclId" : { "Ref" : "OnosNetworkAcl" }
}
},
"IPAddress" : {
"Type" : "AWS::EC2::EIP",
"DependsOn" : "AttachGateway",
"Properties" : {
"Domain" : "vpc",
"InstanceId" : { "Ref" : "OnosController" }
}
},
"InstanceSecurityGroup" : {
"Type" : "AWS::EC2::SecurityGroup",
"Properties" : {
"VpcId" : { "Ref" : "VPC" },
"GroupDescription" : "Enable SSH access via port 22",
"SecurityGroupIngress" : [
{"IpProtocol" : "tcp", "FromPort" : "22", "ToPort" : "22", "CidrIp" : { "Ref" : "SSHLocation"}},
{ "IpProtocol" : "tcp", "FromPort" : "80", "ToPort" : "80", "CidrIp" : "0.0.0.0/0"},
{ "IpProtocol" : "tcp", "FromPort" : "0", "ToPort" : "65535", "CidrIp" : "0.0.0.0/0"},
{ "IpProtocol" : "icmp", "FromPort" : "-1", "ToPort" : "-1", "CidrIp" : "0.0.0.0/0"}
]
}
},
"OnosController" : {
"Type" : "AWS::EC2::Instance",
"Metadata": {
"AWS::CloudFormation::Init" : {
"config" : {
"files" : {
"/etc/cfn/cfn-hup.conf" : {
"content" : { "Fn::Join" : ["", [
"[main]\n",
"stack=", { "Ref" : "AWS::StackId" }, "\n",
"region=", { "Ref" : "AWS::Region" }, "\n"
]]},
"mode" : "000400",
"owner" : "root",
"group" : "root"
},
"/etc/cfn/hooks.d/cfn-auto-reloader.conf" : {
"content": { "Fn::Join" : ["", [
"[cfn-auto-reloader-hook]\n",
"triggers=post.update\n",
"path=Resources.OnosController.Metadata.AWS::CloudFormation::Init\n",
"action=/usr/local/bin/cfn-init -v ",
" --stack ", { "Ref" : "AWS::StackName" },
" --resource OnosController ",
" --region ", { "Ref" : "AWS::Region" }, "\n",
"runas=root\n"
]]}
},
"/lib/systemd/system/cfn-hup.service": {
"content": { "Fn::Join" : ["", [
"[Unit]\n",
"Description=cfn-hup daemon\n\n",
"[Service]\n",
"Type=simple\n",
"ExecStart=/usr/local/bin/cfn-hup --no-daemon\n",
"[Install]\n",
"WantedBy=multi-user.target"]]}
}
},
"commands" : {
"01enable_cfn_hup" : {
"command" : "systemctl enable cfn-hup.service"
},
"02start_cfn_hup" : {
"command" : "systemctl start cfn-hup.service"
}
}
}
}
},
"DependsOn" : "AttachGateway",
"Properties" : {
"ImageId" : {"Fn::FindInMap": [
"AWSRegionUbuntu2AMI",
{
"Ref": "AWS::Region"
},
{
"Fn::FindInMap": [
"AWSInstanceType2Ubuntu",
{
"Ref": "InstanceType"
},
"Ubuntu"
]
}
]},
"InstanceType" : { "Ref" : "InstanceType" },
"KeyName" : {"Ref": "KeyName"},
"Tags" : [ {"Key" : "Name", "Value" : "Onos Controller" } ],
"NetworkInterfaces" : [{
"GroupSet" : [{ "Ref" : "InstanceSecurityGroup" }],
"AssociatePublicIpAddress" : "true",
"DeviceIndex" : "0",
"DeleteOnTermination" : "true",
"SubnetId" : { "Ref" : "PulicSubnet" }
}],
"UserData" : { "Fn::Base64" : { "Fn::Join" : ["", [
"Content-Type: multipart/mixed; boundary=\"=======6t461261365==\"\n",
"MIME-Version: 1.0\n",
"\n",
"--=======6t461261365==\n",
"Content-Type: text/x-shellscript; charset=\"us-ascii\"\n",
"Content-Disposition: attachment; filename=\"cfn-setup.sh\"\n",
"\n",
"#!/bin/bash\n",
"set -o errexit; set -o nounset; set -o pipefail\n",
"# Install java8\n",
"apt-get install software-properties-common -y",
"add-apt-repository ppa:webupd8team/java -y",
"apt-get update",
"echo \"oracle-java8-installer shared/accepted-oracle-license-v1-1 select true\" | debconf-set-selections",
"apt-get install oracle-java8-installer oracle-java8-set-default -y",
"# Install AWS cfn-bootstrap utilities\n",
"apt-get update\n",
"apt-get -y install python-pip\n",
"pip install https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-latest.tar.gz\n",
"/usr/local/bin/cfn-init",
" --stack ", { "Ref": "AWS::StackName" },
" --resource OnosController",
" --region ", { "Ref": "AWS::Region" }, "\n",
"/usr/local/bin/cfn-signal -e $? ",
" --stack ", { "Ref" : "AWS::StackName" },
" --resource OnosController",
" --region ", { "Ref" : "AWS::Region" }, "\n",
"\n",
"--=======6t461261365==--\n"
]]}
}
},
"CreationPolicy" : {
"ResourceSignal" : {
"Timeout" : "PT15M"
}
}
},
"OnosOC1" : {
"Type" : "AWS::EC2::Instance",
"Metadata": {
"AWS::CloudFormation::Init" : {
"config" : {
"files" : {
"/etc/cfn/cfn-hup.conf" : {
"content" : { "Fn::Join" : ["", [
"[main]\n",
"stack=", { "Ref" : "AWS::StackId" }, "\n",
"region=", { "Ref" : "AWS::Region" }, "\n"
]]},
"mode" : "000400",
"owner" : "root",
"group" : "root"
},
"/etc/cfn/hooks.d/cfn-auto-reloader.conf" : {
"content": { "Fn::Join" : ["", [
"[cfn-auto-reloader-hook]\n",
"triggers=post.update\n",
"path=Resources.OnosOC1.Metadata.AWS::CloudFormation::Init\n",
"action=/usr/local/bin/cfn-init -v ",
" --stack ", { "Ref" : "AWS::StackName" },
" --resource OnosOC1",
" --region ", { "Ref" : "AWS::Region" }, "\n",
"runas=root\n"
]]}
},
"/lib/systemd/system/cfn-hup.service": {
"content": { "Fn::Join" : ["", [
"[Unit]\n",
"Description=cfn-hup daemon\n\n",
"[Service]\n",
"Type=simple\n",
"ExecStart=/usr/local/bin/cfn-hup --no-daemon\n",
"[Install]\n",
"WantedBy=multi-user.target"]]}
}
},
"commands" : {
"01enable_cfn_hup" : {
"command" : "systemctl enable cfn-hup.service"
},
"02start_cfn_hup" : {
"command" : "systemctl start cfn-hup.service"
}
}
}
}
},
"DependsOn" : "NAT",
"Properties" : {
"ImageId" : {"Fn::FindInMap": [
"AWSRegionUbuntu2AMI",
{
"Ref": "AWS::Region"
},
{
"Fn::FindInMap": [
"AWSInstanceType2Ubuntu",
{
"Ref": "InstanceType"
},
"Ubuntu"
]
}
]},
"InstanceType" : { "Ref" : "InstanceType" },
"KeyName" : {"Ref": "KeyName"},
"Tags" : [ {"Key" : "Name", "Value" : "Onos OC1" } ],
"NetworkInterfaces" : [{
"GroupSet" : [{ "Ref" : "InstanceSecurityGroup" }],
"AssociatePublicIpAddress" : "false",
"DeviceIndex" : "0",
"DeleteOnTermination" : "true",
"SubnetId" : { "Ref" : "PrivateSubnet" }
}],
"UserData" : { "Fn::Base64" : { "Fn::Join" : ["", [
"Content-Type: multipart/mixed; boundary=\"=======6t461261365==\"\n",
"MIME-Version: 1.0\n",
"\n",
"--=======6t461261365==\n",
"Content-Type: text/x-shellscript; charset=\"us-ascii\"\n",
"Content-Disposition: attachment; filename=\"cfn-setup.sh\"\n",
"\n",
"#!/bin/bash\n",
"set -o errexit; set -o nounset; set -o pipefail\n",
"# Install java8\n",
"apt-get install software-properties-common -y",
"add-apt-repository ppa:webupd8team/java -y",
"apt-get update",
"echo \"oracle-java8-installer shared/accepted-oracle-license-v1-1 select true\" | debconf-set-selections",
"apt-get install oracle-java8-installer oracle-java8-set-default -y",
"# Install AWS cfn-bootstrap utilities\n",
"apt-get update\n",
"apt-get -y install python-pip\n",
"pip install https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-latest.tar.gz\n",
"cp /usr/local/init/ubuntu/cfn-hup /etc/init.d/cfn-hup \n",
"chmod +x /etc/init.d/cfn-hup \n",
"update-rc.d cfn-hup defaults \n ",
"service cfn-hup start \n",
"/usr/local/bin/cfn-init",
" --stack ", { "Ref": "AWS::StackName" },
" --resource OnosOC1",
" --region ", { "Ref": "AWS::Region" }, "\n",
"/usr/local/bin/cfn-signal -e $? ",
" --stack ", { "Ref" : "AWS::StackName" },
" --resource OnosOC1",
" --region ", { "Ref" : "AWS::Region" }, "\n",
"\n",
"--=======6t461261365==--\n"
]]}
}
},
"CreationPolicy" : {
"ResourceSignal" : {
"Timeout" : "PT15M"
}
}
}
},
"Outputs" : {
"URL" : {
"Value" : { "Fn::Join" : [ "", ["http://", { "Fn::GetAtt" : ["OnosController", "PublicIp"] }]]},
"Description" : "Newly created application URL"
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment