0
0
AWScloud~5 mins

Parameters for customization in AWS - Commands & Configuration

Choose your learning style9 modes available
Introduction
When you create cloud resources, you often want to change some settings without rewriting everything. Parameters let you customize your setup easily by giving values that change how your resources behave.
When you want to reuse the same cloud setup but with different names or sizes for resources.
When you need to deploy the same application in different environments like testing and production with different settings.
When you want to let others provide input values to your cloud setup without changing the main configuration.
When you want to avoid hardcoding values like passwords or instance types in your cloud templates.
When you want to quickly update a setting like the number of servers without rewriting the whole setup.
Config File - template.yaml
template.yaml
AWSTemplateFormatVersion: '2010-09-09'
Description: Simple EC2 instance with parameter for instance type
Parameters:
  InstanceTypeParam:
    Type: String
    Default: t3.micro
    AllowedValues:
      - t3.micro
      - t3.small
      - t3.medium
    Description: EC2 instance type
Resources:
  MyEC2Instance:
    Type: AWS::EC2::Instance
    Properties:
      InstanceType: !Ref InstanceTypeParam
      ImageId: ami-0c94855ba95c71c99
Outputs:
  InstanceId:
    Description: The Instance ID
    Value: !Ref MyEC2Instance

This AWS CloudFormation template creates an EC2 instance.

Parameters: Defines InstanceTypeParam to let you choose the EC2 instance type when you deploy.

Resources: Creates an EC2 instance using the chosen instance type.

Outputs: Shows the instance ID after deployment.

Commands
This command deploys the CloudFormation stack named 'my-ec2-stack' using the template file. It sets the parameter 'InstanceTypeParam' to 't3.small' to customize the EC2 instance type.
Terminal
aws cloudformation deploy --template-file template.yaml --stack-name my-ec2-stack --parameter-overrides InstanceTypeParam=t3.small
Expected OutputExpected
Waiting for stack create/update to complete... Successfully created/updated stack - my-ec2-stack
--template-file - Specifies the CloudFormation template file to use
--stack-name - Names the CloudFormation stack
--parameter-overrides - Overrides parameter values in the template
This command shows details about the deployed stack, including the output values like the EC2 instance ID.
Terminal
aws cloudformation describe-stacks --stack-name my-ec2-stack
Expected OutputExpected
{ "Stacks": [ { "StackName": "my-ec2-stack", "StackStatus": "CREATE_COMPLETE", "Outputs": [ { "OutputKey": "InstanceId", "OutputValue": "i-0123456789abcdef0", "Description": "The Instance ID" } ] } ] }
--stack-name - Specifies which stack to describe
Key Concept

If you remember nothing else from this pattern, remember: parameters let you change key settings without rewriting your whole cloud setup.

Common Mistakes
Not providing a required parameter value when deploying the stack.
The deployment fails because the template expects a value and none was given.
Always provide values for required parameters using --parameter-overrides or set defaults in the template.
Using a parameter value not listed in AllowedValues.
CloudFormation rejects the deployment because the value is invalid.
Use only values allowed by the template or update AllowedValues to include new options.
Summary
Define parameters in your CloudFormation template to allow customization.
Use the AWS CLI with --parameter-overrides to set parameter values when deploying.
Check stack outputs to verify your resources were created with the desired settings.