Bluz
Bluz

Reputation: 6510

cloudformation, error creating a change: set Parameter 'ami' must be one of AllowedValues

I am trying to create a stack in CloudFormation. When I go through the process and populate the fields, I am asked to enter an AMI.

I key in the instance ID, but on the next screen I get the following error message:

There was an error creating this change set Parameter 'ami' must be one of AllowedValues

I am not sure what type of parameter is expected here. What else should I be entering instead of the ID?

Looking at the AMI details, I see the AMI is set to private. It's not shared with any account or organisation. Is this the reason why it's not working?

I tried to Google that error message but I haven't found anything relevant.

Thanks

template:

{

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

  "Description" : "Template to create a Ubuntu grafana server",

  "Parameters": {

    "instanceName": {

      "Description": "Ubuntu Grafana",

      "Type": "String"

    },

    "Subnet": {
c
      "Description": "The subnets where the instance is created.",

      "Type": "AWS::EC2::Subnet::Id"

    },

    "securitygroup": {

      "Description": "The subnets where workers can be created.",

      "Type": "List<AWS::EC2::SecurityGroup::Id>"

    },

    "InstanceType": {

      "Description": "EC2 instance type for the node instances",

      "Type": "String",

      "Default": "t3.micro",

      "AllowedValues": [

        "t3.micro", "t3.small", "t2.medium"

      ],

      "ConstraintDescription": "Must be a valid EC2 instance type"

    },

    "KeyName": {

      "Description": "The EC2 Key Pair to allow SSH access to the instances",

      "Type": "AWS::EC2::KeyPair::KeyName"

    },

    "volumeSize": {

      "Description": "Size of EBS volume in GB",

      "Type": "Number"

    },

    "ami" : {

      "Description": "ami of instance",

      "Type" : "AWS::EC2::Image::Id",

      "AllowedValues" : [

        "ami-00000000","ami-00000000", "ami-00000000"

      ]

    }

  },

  "Resources" : {

    "masterinstance" : {

      "Type" : "AWS::EC2::Instance",

      "Properties" : {

        "BlockDeviceMappings" : [ {

          "DeviceName" :  "/dev/sda1",

          "Ebs" : {

            "DeleteOnTermination" : "False",

            "Encrypted" : "False",

            "VolumeSize" : {"Ref":  "volumeSize"},

            "VolumeType" : "gp2"

          }

        }],

        "ImageId" : {"Ref": "ami"},

        "InstanceType" : {"Ref" : "InstanceType"},

        "KeyName" : {"Ref": "KeyName"},

        "SecurityGroupIds" : {"Ref" :  "securitygroup"},

        "SubnetId" : {"Ref": "Subnet"},

        "Tags" : [ {

          "Key" : "Name",

          "Value" : {"Ref": "instanceName"}

        } ]

      }

    }

  }

}

Upvotes: 0

Views: 2704

Answers (2)

Arkham
Arkham

Reputation: 11

I'm late, but I have just faced that problem some days ago.

The problem is that you have defined some allowed values but the informed value of the ami is not in the list of allowed values. If you don't inform a default value for the ami it will take empty as the value.

Maybe I can explain myself better using and example:

Code block with the problem...

"ami" : {
  "Description": "ami of instance",
  "Type" : "AWS::EC2::Image::Id",
  "AllowedValues" : [
     "ami-00000000","ami-00000001", "ami-00000002"
   ]
 }

You need to specify a Default value for the ami, that must be one of the allowed values or you must to add empty value in the allowed values list.

Solution 1. Setting ami default value

"ami" : {
  "Default": "ami-00000000",
  "Description": "ami of instance",
  "Type" : "AWS::EC2::Image::Id",
  "AllowedValues" : [
     "ami-00000000","ami-00000001", "ami-00000002"
   ]
 }

Solution 2. Adding empty value

"ami" : {
  "Description": "ami of instance",
  "Type" : "AWS::EC2::Image::Id",
  "AllowedValues" : [
     "","ami-00000000","ami-00000001", "ami-00000002"
   ]
 }

I hope it helps!

Upvotes: 0

Kaustubh Khavnekar
Kaustubh Khavnekar

Reputation: 2923

    "ami" : {

      "Description": "ami of instance",

      "Type" : "AWS::EC2::Image::Id",

      "AllowedValues" : [

        "ami-00000000","ami-00000000", "ami-00000000"

      ]

    }

Whatever value you are providing as value of the ami parameter needs to be one of AllowedValues. Since all the IDs in the AllowedValues are invalid, it is safe to assume that you aren't providing one of these values. Removing the AllowedValues constraint (or correcting the list) would fix this:

    "ami" : {

      "Description": "ami of instance",

      "Type" : "AWS::EC2::Image::Id"

    }

Upvotes: 1

Related Questions