0

I am using the following code of Parameters to select the latest AMI. It works as execpted.

"Parameters" : {
  "LatestAmiId" : { 
    "Type" : "AWS::SSM::Parameter::Value<AWS::EC2::Image::Id>",
    "Default" : "/aws/service/ami-amazon-linux-latest/amzn-ami-hvm-x86_64-ebs"
}},

Is there a similar way to select the subnet of default security group? I do not want to mention the subnet (or security group) like this...

"SubnetId": "subnet-e8ecf09c, subnet-aa9dfc90, subnet-ce083188, subnet-718bd259",

Update:

I am using the following code and it fails with an error " Value of property SubnetId must be of type String"

{
"Parameters": {
  "LatestAmiId": {
    "Type": "AWS::SSM::Parameter::Value<AWS::EC2::Image::Id>",     
    "Default": "/aws/service/ami-amazon-linux-latest/amzn2-ami-hvm-x86_64-ebs"
},

  "myKeyPair" : {
    "Description" : "Amazon EC2 Key Pair",
    "Type" : "AWS::EC2::KeyPair::KeyName"
  },
  "mySubnetIDs" : {
    "Description" : "Subnet IDs",
    "Type" : "List<AWS::EC2::Subnet::Id>"
  },
     "Oksoftaccess":{  
         "Type":"AWS::SSM::Parameter::Value<String>",
         "Default":"myEC2TypeDev"
      },
      "Oksoftsecret":{  
         "Type":"String",
         "Default":"mysecret1"
      }
},

1 Answer 1

1

As per this document, the “SubnetId” property in the “AWS::EC2::Instance” must be “String” type. However, the parameter type called “Subnet” is defined as “List” which is a list . EC2 instances can be run in the only one subnet (not multiple subnets).

Change the parameter type to “AWS::EC2::Subnet::Id” as below in your CF template and then try again:

    "mySubnetIDs": {
     ...
        "Type": "AWS::EC2::Subnet::Id"
     ...
    }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.