{
    "AWSTemplateFormatVersion" : "2010-09-09",

    "Description" : "An example of the EIP Lookup custom resource",

    "Parameters" : {
        "InstanceType" : {
            "Description" : "Example instance types",
            "Type" : "String",
            "Default" : "t1.micro",
            "AllowedValues" : [ "t1.micro","m1.small","m1.medium","m1.large","m1.xlarge","m2.xlarge","m2.2xlarge","m2.4xlarge","m3.xlarge","m3.2xlarge","c1.medium","c1.xlarge","cc1.4xlarge","cc2.8xlarge","cg1.4xlarge"],
            "ConstraintDescription" : "must be a valid EC2 instance type."
        },
        "EipLookupServiceToken" : {
            "Description" : "ServiceToken of EIP Lookup Custom Resource",
            "Type" : "String",
            "AllowedPattern" : "arn:aws:sns:.*",
            "ConstraintDescription" : "must be an SNS topic ARN"
        }
    },

    "Mappings" : {
        "RegionMap" : {
          "us-east-1"      : { "AMI" : "ami-7f418316" },
          "us-west-1"      : { "AMI" : "ami-951945d0" },
          "us-west-2"      : { "AMI" : "ami-16fd7026" },
          "eu-west-1"      : { "AMI" : "ami-24506250" },
          "sa-east-1"      : { "AMI" : "ami-3e3be423" },
          "ap-southeast-1" : { "AMI" : "ami-74dda626" },
          "ap-southeast-2" : { "AMI" : "ami-b3990e89" },
          "ap-northeast-1" : { "AMI" : "ami-dcfa4edd" }
        }
  },

  "Resources" : {
    "Ec2Instance" : {
      "Type" : "AWS::EC2::Instance",
      "Properties" : {
        "UserData" : { "Fn::Base64" : { "Fn::Join" : [ "", [ "IPAddress=", {"Ref" : "IPAddress"}]]}},
        "ImageId" : { "Fn::FindInMap" : [ "RegionMap", { "Ref" : "AWS::Region" }, "AMI" ]}
      }
    },

    "IPAddress" : {
        "Type" : "Custom::EipLookup",
        "Version" : "1.0",
        "Properties" : {
            "ServiceToken" : { "Ref" : "EipLookupServiceToken" },
            "pool" : "default"
        }
    },

    "IPAssoc" : {
      "Type" : "AWS::EC2::EIPAssociation",
      "Properties" : {
        "InstanceId" : { "Ref" : "Ec2Instance" },
        "EIP" : { "Ref" : "IPAddress" }
      }
    }
  }
}