AWS Classroom Series – 29/May/2020

Nesting and Existing Stack

  • Nested Stacks are created as a part of other stack
  • To create Nested Stacks the resource ‘AWS::CloudFormation::Stack’ will be used
  • Scenario: You already have cloud formation template written to create vpc and if you want to reuse that template rather than rewriting the script every time use nested stacks
    • Write a reusable template and upload to s3 bucket
    • Use this s3 buckets url in your current template
{
    "AWSTemplateFormatVersion": "2010-09-09",
    "Resources": {
        
        "mys3": {
            "Type": "AWS::S3::Bucket",
            "Properties": {
                "AccessControl": "PublicRead",
                "BucketName": "testings3qt.com"
            }
        },
        
        "NestedStack": {
            "Type": "AWS::CloudFormation::Stack",
            "DeletionPolicy": "Retain",
            "Properties": {
                "TemplateURL": "https://s3-us-west-2.amazonaws.com/cf-templates-1sv6xf2hjs8h8-us-west-2/2020150aju-common.json",
                "Parameters": {
                    "cidrrange": "10.10.0.0/16"
                }

            }
        }
        
        
    }
}
  • Look into DeletionPolicy over here
  • Exercise: Findout a solution to fetch the details about nested stack other ref

Calling AWS Cloudformation from CLI

  • AWS CLI Installation and configuration Refer Here
  • Create a folder cf create a file called as common.json with your cf script
{
    "AWSTemplateFormatVersion": "2010-09-09",
    "Parameters": {
        "cidrrange": {
            "Type": "String",
            "Default": "192.168.0.0/16"
        }
    },
    "Resources": {
        "commonvpc": {
            "Type": "AWS::EC2::VPC",
            "Properties": {
                "CidrBlock": {
                    "Ref": "cidrrange"
                }
            }
        }
    },
    "Outputs": {
        "vpcid": {
            "Value": {
                "Ref": "commonvpc"
            }
        }
    }
}
  • To run this from cli, you need to create stack
cd cf\
 aws cloudformation create-stack --stack-name fromcli --template-body file://common.json --parameters ParameterKey=cidrrange,ParameterValue=192.168.0.0/16
  • To describe stacks status
aws cloudformation describe-stacks --stack-name fromcli
  • now make changes in your template and update the stack
aws cloudformation update-stack --stack-name fromcli --template-body file://common.json --parameters ParameterKey=cidrrange,ParameterValue=192.168.0.0/16
  • deleting the stack
aws cloudformation delete-stack --stack-name fromcli

Stack Sets

Next Steps

Leave a ReplyCancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Please turn AdBlock off
Social Media Icons Powered by Acurax Web Design Company

Discover more from Direct DevOps from Quality Thought

Subscribe now to keep reading and get access to the full archive.

Continue reading

Exit mobile version
%%footer%%