<% @app,@role,@env = name.sub('.json','').split('-') %> { "AWSTemplateFormatVersion": "2010-09-09", "Description": "<%= @app.capitalize %> <%= @role %>", "Outputs": { "DBHostname": { "Description": "Hostname for Redis", "Value": { "Fn::Join": [ "", [ "", { "Fn::GetAtt": [ "server", "PublicDnsName" ] } ] ] } } }, "Parameters": { "Ami": { "Default": "<%= @ami %>", "Description": "deploy ami", "Type": "String" }, "Application": { "Default": "<%= @app %>", "Description": "foo, bar, etc", "Type": "String" }, "Environment": { "Default": "<%= @env %>", "Description": "stag, prod etc", "Type": "String" }, "InstanceType": { "AllowedValues": [ "t1.micro", "m1.small", "m1.medium", "m1.large", "m1.xlarge", "m2.xlarge", "m2.2xlarge", "m2.4xlarge", "c1.medium", "c1.xlarge", "cc1.4xlarge", "cc2.8xlarge", "cg1.4xlarge" ], "ConstraintDescription": "must be a valid EC2 instance type.", "Default": "<%= @instance_type %>", "Description": "server EC2 instance type", "Type": "String" }, "KeyName": { "AllowedPattern": "[-_ a-zA-Z0-9]*", "ConstraintDescription": "can contain only alphanumeric characters, spaces, dashes and underscores.", "Default": "default", "Description": "Name of an existing EC2 KeyPair to enable SSH access to the instances", "MaxLength": "64", "MinLength": "1", "Type": "String" }, "Role": { "Default": "<%= @role %>", "Description": "redis, psql, app, etc", "Type": "String" }, "StackNumber": { "Default": "<%= @stack_number %>", "Description": "s1, s2, s3, etc", "Type": "String" }, "VolumeSize": { "ConstraintDescription": "must be between 5 and 1024 Gb.", "Default": "<%= @volume_size %>", "Description": "Size of Volume", "MaxValue": "1024", "MinValue": "5", "Type": "Number" } }, "Resources": { "CfnUser": { "Properties": { "Path": "/", "Policies": [ { "PolicyDocument": { "Statement": [ { "Action": "cloudformation:DescribeStackResource", "Effect": "Allow", "Resource": "*" } ] }, "PolicyName": "root" } ] }, "Type": "AWS::IAM::User" }, "DataVolume": { "DeletionPolicy": "Snapshot", "Properties": { "AvailabilityZone": { "Fn::GetAtt": [ "server", "AvailabilityZone" ] }, "Size": { "Ref": "VolumeSize" }, "Tags": [ { "Key": "Usage", "Value": "Data Volume" } ] }, "Type": "AWS::EC2::Volume" }, "HostKeys": { "Properties": { "UserName": { "Ref": "CfnUser" } }, "Type": "AWS::IAM::AccessKey" }, "HostRecord": { "Properties": { "Comment": "DNS name for my stack.", "HostedZoneName": ".mydomain.net.", "Name": { "Fn::Join": [ "", [ { "Ref": "AWS::StackName" }, ".mydomain.net." ] ] }, "ResourceRecords": [ { "Fn::GetAtt": [ "server", "PublicDnsName" ] } ], "TTL": "60", "Type": "CNAME" }, "Type": "AWS::Route53::RecordSet" }, "MountPoint": { "Properties": { "Device": "/dev/sdf", "InstanceId": { "Ref": "server" }, "VolumeId": { "Ref": "DataVolume" } }, "Type": "AWS::EC2::VolumeAttachment" }, "ServiceSecurityGroup": { "Properties": { "GroupDescription": "Enable SSH access.", "SecurityGroupIngress": [ { "CidrIp": "0.0.0.0/0", "FromPort": "22", "IpProtocol": "tcp", "ToPort": "22" } ] }, "Type": "AWS::EC2::SecurityGroup" }, "WaitCondition": { "DependsOn": "MountPoint", "Metadata": { "Comment1": "Note that the WaitCondition is dependent on the volume mount point allowing the volume to be created and attached to the EC2 instance", "Comment2": "The instance bootstrap script waits for the volume to be attached to the instance prior to signalling completion." }, "Properties": { "Handle": { "Ref": "WaitHandle" }, "Timeout": "3000" }, "Type": "AWS::CloudFormation::WaitCondition" }, "WaitHandle": { "Type": "AWS::CloudFormation::WaitConditionHandle" }, <%= partial("server") %> } }