gshtong
gshtong

Reputation: 157

attribute publicip was not found for resource during aws cloudformation

I'm very new to aws cloudformation, I try to launch a EC2 with Neo4j install in a private VPC, I have found someone who has already created a cloudformation template for instance with Neo4j, but that instance is for public VPC, so I have modified the template to suit my purpose, but I got this problem when I launch it: 'attribute publicip was not found for resource'

Here is some part of the script (without the neo4j bash script and EBS volume setup):

"Mappings" : {

"AWSRegionArch2AMI" : {
  "eu-west-1"      : { "64" : "ami-58d7e821" }
}

},

"Parameters": {
    "InstanceType" : {
    "Description" : "EC2 instance type",
    "Type" : "String",
    "Default" : "m5.large",
    "ConstraintDescription" : "Must be a valid EC2 instance type."
    },

    "SSHKeyName": {
      "Description": "Name of the SSH key that you will use to access the server (must be on AWS Availability Zone already)",
      "Type": "String"
    },

    "NetworkWhitelist": {
        "Description": " The IP address range that can be used to connect to the Neo4j server (by REST or SSH)",
        "Type": "String",
        "MinLength": "9",
        "MaxLength": "18",
        "Default": "",
        "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."
    },

    "SubnetId" : {
        "Type" : "AWS::EC2::Subnet::Id",
        "Description" : "SubnetId of an existing subnet (for the primary network) in your Virtual Private Cloud (VPC)"
    },

    "SecurityGroupIds": {
        "Type": "AWS::EC2::SecurityGroup::Id",
        "Description" : "Existing SecurityGroups ID"
    },

    "AvailabilityZone": {
        "Type" : "AWS::EC2::AvailabilityZone::Name",
        "Description" : "Select the Availability Zone"
    }

},
"Resources": {
    "Server": {
        "Type": "AWS::EC2::Instance",
        "Properties": {
            "AvailabilityZone": {
                "Ref": "AvailabilityZone"
            },


            "DisableApiTermination": "FALSE",
            "ImageId": {
                "Fn::FindInMap": [ "AWSRegionArch2AMI", {
                    "Ref": "AWS::Region"
                }, "64"]
            },
            "InstanceType": {
                "Ref": "InstanceType"
            },
            "KeyName": {"Ref": "SSHKeyName"},
            "Monitoring": "false",
            "NetworkInterfaces" : [
                {
                    "AssociatePublicIpAddress": false,
                    "DeleteOnTermination": true,
                    "DeviceIndex": "0",
                    "SubnetId": {"Ref": "SubnetId"},
                    "GroupSet": [ {"Ref": "SecurityGroupIds"} ]
                }
            ],

Can't I lanuch an instance without public ip address just like in 'Configure Instance Details' in 'Launch instance wizard'?

thank you

Upvotes: 5

Views: 4134

Answers (3)

Lina T
Lina T

Reputation: 169

Perhaps you are tying to do Fn::GetAtt on the Instance logical Id to get the PublicIp somewhere in your code and the Instance doesn't have PublicIp assigned to it.

Upvotes: 5

scotter
scotter

Reputation: 76

I experienced this error just a couple of weeks ago, while getting my feet wet with CloudFormation. In my case, I'd dropped the public IP for the interface, in favor of only a private IP, but I still had an output configured in the CloudFormation template that referenced the now non-existent publicid attribute. Removing that output from the template fixed my issue.

Upvotes: 3

John Nicely
John Nicely

Reputation: 1034

Do you have the "Auto-assign Public IP" option enabled for the subnet you're trying to create the instance in? Because you're explicitly not associating a public IP address, it might be failing because the resource is expecting to have a public IP address assigned. A surefire way to test this would be to set the SubnetId parameter to the ID of a subnet that does not automatically assign public IP addresses when you deploy the stack.

Upvotes: 6

Related Questions