Understanding the Interface Metadata Key in AWS

Pratyush MisraPratyush Misra
5 min read

Introduction

Have you ever wondered how to enhance the user experience when working with AWS CloudFormation? Picture this: you're in the process of creating or updating stacks in the AWS CloudFormation console, and you find yourself confronted with a long list of input parameters, presented to you in some random order. It can be quite a tedious task to efficiently navigate through this sea of parameters and specify the values you need.

Well, stress no more! Enter the interface metadata key, a powerful tool that allows you to take control of how parameters are grouped, sorted, and labelled within the AWS CloudFormation console. This metadata key, identified as AWS::CloudFormation::Interface, empowers you to create a user-friendly experience for defining parameter values.

In this blog post, we'll dive deeper into the interface metadata key and explore how it can revolutionize your experience with AWS CloudFormation. We'll discover the various ways to utilize this key to streamline parameter management, improve user understanding, and ultimately enhance the overall usability of your CloudFormation templates.

Understanding Parameters and ordering

Parameters are optional sections inside your Cloudformation template that enables you to input custom values to your template each time you create or update a stack.

This is how you create a parameter in cfn template:

Parameters:
  InstanceType:
    Type: String
    Description: select t2.micro or t2.large or m1.small
    Default: t2.micro
    AllowedValues:
      - t2.micro
      - t2.large
      - m1.small

Here InstanceType is the name of the parameter and is of string datatype. It has a default value of t2.micro and will be displayed to the user in the form of a list with values t2.micro, t2.large and m1.small.

See it for yourself...

Now, here we just have a single parameter but things start to change when we have a lot of parameters. For understanding this in a better manner, let's say that this is a cloud formation template for taking student information.

Let's take a look at this piece of code:

Parameters:
  StudentName:
    Type: String
    Description: Enter your full name

  StudentID:
    Type: String
    Description: Enter the student ID

  StudentAge:
    Type: Number
    Description: Enter your age

  StudentBatch:
    Type: String
    Description: Enter your batch

  FathersName:
    Type: String
    Description: Enter the fathers age

  FathersOccupation:
    Type: String
    Description: Enter the fathers occupation

  FathersAge:
    Type: Number
    Description: Enter your fathers age

See how this looks when the script with these parameters is run:

This is not the order we provided in the code. Also, it does not make sense to provide information logically to a student. But why is this happening, that's the question.

According to the docs:

"When you create or update stacks in the console, the console lists input parameters in alphabetical order by their logical IDs."

We can check clearly that these are sorted alphabetically also. But we don't want them. We want to present the parameters to the user in the way we want i.e. sorted in a particular order.

Also in some cases or maybe here also, we would want to create separate sections for parameters, one for the student's information and the other for Father.

Cloudformation Interface Metadata

What we want to achieve can be done with the help of the Interface metadata key in cloud formation. AWS::CloudFormation::Interface is a metadata key that defines how parameters are grouped and sorted in the AWS CloudFormation console. By using this key, you can create the ordering you want for parameters. Along with that, you can also create separate sections that we had discussed earlier.

So let's create it in this manner-

We have 2 sections:

  • Student's Information

    • Student's Name

    • Student's ID

    • Student's Age

    • Student's Batch

  • Father's Information

    • Father's Name

    • Father's Occupation

    • Father's Age

Well, this section we are talking about here is called "Parameter Groups" in Interface Metadata Key. So we create Parameter Groups and then assign labels to these groups. These labels will be displayed to the user. Also, we have a thing called "Parameter Labels" which allows us to label the parameters we want. For example, If we have StudentsBatch Parameter, We can create a label for this parameter as "Enter The Student Batch".

Note:

  • Parameter Labels and Parameter Descriptions are different things. In AWS CloudFormation, parameter labels provide concise names for parameters, making them easily recognizable, while parameter descriptions offer detailed explanations and instructions for proper configuration. Together, they enhance the usability and clarity of CloudFormation templates.

Each of the Parameter Groups contains 2 parts:

  • Label: Labelling and describing this parameter group

  • Parameters: The list of parameters that will be a part of this Parameter group.

Important Note:

  • The order in which you specify parameters in this parameter group will be the order in which your parameters will be displayed to the user.

See the code:

Metadata: 
  AWS::CloudFormation::Interface: 
    ParameterGroups: 
      - Label: 
          default: "Student Information"
        Parameters: 
          - StudentName
          - StudentID
          - StudentAge
          - StudentBatch

      - Label: 
          default: "Fathers Information"
        Parameters: 
          - FathersName
          - FathersOccupation
          - FathersAge

    ParameterLabels:
      StudentBatch: 
        default: "Enter the batch you've enrolled into"

Parameters:
  StudentName:
    Type: String
    Description: Enter your full name

  StudentID:
    Type: String
    Description: Enter the student ID

  StudentAge:
    Type: Number
    Description: Enter your age

  StudentBatch:
    Type: String
    Description: Batch will be like B_<Class>

  FathersName:
    Type: String
    Description: Enter the fathers age

  FathersOccupation:
    Type: String
    Description: Enter the fathers occupation

  FathersAge:
    Type: Number
    Description: Enter your fathers age

See it for yourself:

We can see the current parameter configuration. Now with the help of this metadata key, we can organise, group and label the parameters we want as per our wish.

Conclusion

In conclusion, parameter labels and parameter descriptions in AWS CloudFormation serve distinct purposes but work together to improve the usability and documentation of CloudFormation templates. Parameter labels provide clear and concise names for parameters, aiding in their identification and understanding. On the other hand, parameter descriptions offer in-depth explanations and instructions, providing valuable context for configuring the parameters correctly. By leveraging both labels and descriptions, CloudFormation templates become more user-friendly, facilitating the seamless management and deployment of AWS infrastructure as code.

Hope you enjoyed...Happy Learning :)

1
Subscribe to my newsletter

Read articles from Pratyush Misra directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Pratyush Misra
Pratyush Misra