Update a CloudFormation template


Services Covered

  • cloudformation CloudFormation

Lab description

You have been tasked with the following:
Increasing the size of one of the instances
Allowing HTTP access to the instances from anywhere
Exposing the instance Id of one of the instances as a stack template output


Learning Objectives

Enable Stack Termination Protection

Update template


Lab date

31-12-2021


Prerequisites

:cloud: AWS account

:computer: EC2 Instance running or Terraform installed locally


Lab steps

  1. Enable Stack Termination Protection. Using AWS Management Console enable termination protection for the lab CloudFormation stack.

  2. Update EC2 Instance Type.
    TestEc2Instance:
       Type: "AWS::EC2::Instance"
       Properties:
         ImageId: !Ref LatestAmiId
         InstanceType: t3.micro
         KeyName: !Ref "AWS::AccountId"
         NetworkInterfaces:
           - AssociatePublicIpAddress: "true"
             DeviceIndex: "0"
             GroupSet:
               - Ref: Ec2InstanceSecurityGroup
             SubnetId: !Ref PublicSubnet
         Tags:
           - Key: Name
             Value: !Sub ${TagPrefix} Test Instance
  3. Add a Security Group Ingress Rule.
    Ec2InstanceSecurityGroup:
       Type: "AWS::EC2::SecurityGroup"
       Properties:
         GroupDescription: Security group for EC2 instances
         GroupName: ec2-instance-sg
         VpcId: !Ref VPC
         SecurityGroupIngress:
         - IpProtocol: tcp
           FromPort: 80
           ToPort: 80
           CidrIp: 0.0.0.0/0
  4. Add a Template Output.
    ProdEc2Instance:
       Description: Instance Id
       Value: !Ref ProdEc2Instance
  5. Use Specific IAM Role for Updates.

  6. Update stack.

Lab files


Acknowledgements

Tags: