Cloud Formation

  1. Infrastructure as code (JSON or YAML)
  2. AWS CloudFormation is an AWS service that helps you model and set up your Amazon Web Services resources.
  3. You create a template that describes all the AWS resources that you want (like Amazon EC2 instances or Amazon RDS DB instances), and AWS CloudFormation takes care of provisioning and configuring those resources for you.
  4. You don’t need to individually create and configure AWS resources and figure out what’s dependent on what
  5. By using AWS CloudFormation, you create a CF stack and easily manage a collection of resources (stack) as a single unit.
  6. When you use AWS CloudFormation, you can reuse your template to set up your resources consistently and repeatedly across other regions.
  7. You can use a version control system with your templates so that you know exactly what changes were made, who made them, and when.
  8. A sample template looks like below. Notice that even though a eip needs an instance id, since we don’t know the iid, we can simply use “Ref” to the name of the instance to obtain the iid.
    YAML
    AWSTemplateFormatVersion: "2010-09-09"
    Description: A sample template
    Resources:
     MyEC2Instance:
     Type: "AWS::EC2::Instance"
     Properties: 
     ImageId: "ami-2f726546"
     InstanceType: t1.micro
     KeyName: testkey
     BlockDeviceMappings:
     -
     DeviceName: /dev/sdm
     Ebs:
     VolumeType: io1
     Iops: 200
     DeleteOnTermination: false
     VolumeSize: 20
     MyEIP:
     Type: AWS::EC2::EIP
     Properties:
     InstanceId: !Ref MyEC2Instance
  9. You can use input parameters to a CF template thus avoiding the need to hard code variables (such as instance type)
  10. You can use AWS::Include to include snippets that are stored in S3
  11. Stacks: When you use AWS CloudFormation, you manage related resources as a single unit called a stack.
    1. You create, update, and delete a collection of resources by creating, updating, and deleting stacks.
    2. All the resources in a stack are defined by the stack’s AWS CloudFormation template.
  12. Change Sets
    1. If you need to make changes to the running resources in a stack, you update the stack.
    2. Before making changes to your resources, you can generate a change set, which is summary of your proposed changes.
    3. Change sets allow you to see how your changes might impact your running resources, especially for critical resources, before implementing them.
  13. Cloudformation Template Anatomy
    1. Format Version (optional)
    2. Description (optional)
    3. Metadata (optional)
    4. Parameters (optional) Values to pass to your template at runtime (when you create or update a stack). You can refer to parameters from the Resources and Outputs sections of the template.
    5. Mappings (optional) A mapping of keys and associated values that you can use to specify conditional parameter values, similar to a lookup table. You can match a key to a corresponding value by using the Fn::FindInMap intrinsic function in the Resources and Outputs section.
    6. Conditions (optional) Conditions that control whether certain resources are created or whether certain resource properties are assigned a value during stack creation or update.
    7. Transform (optional)    You can also use AWS::Include transforms to work with template snippets that are stored separately from the main AWS CloudFormation template. You can store your snippet files in an Amazon S3 bucket and then reuse the functions across multiple templates.
    8. Resources (required)  Specifies the stack resources and their properties, such as an Amazon Elastic Compute Cloud instance or an Amazon Simple Storage Service bucket.
    9. Outputs (optional) The optional Outputs section declares output values. For example, you can output the S3 bucket name for a stack to make the bucket easier to find.
      YAML
      Outputs:
        Logical ID:
          Description: Information about the value
          Value: Value to return
          Export:
            Name: Value to export

      You can use Output variables to:

      1. Import into other stacks (to create cross-stack references),
      2. return in response (to describe stack calls)
      3. view on the AWS CloudFormation console. 
      4. Output Fields
        1. Logical ID: An identifier for the current output.
        2. Description (optional)  The description can be a maximum of 4 K in length.
        3. Value (required): The value of the property returned by the aws cloudformation describe-stacks command. The value of an output can include literals, parameter references, pseudo-parameters, a mapping value, or intrinsic functions.
        4. Export (optional): The name of the resource output to be exported for a cross-stack reference.
        5. The following restrictions apply to cross-stack references:
          1. For each AWS account, Export names must be unique within a region.
          2. You can’t create cross-stack references across regions.
          3. You can’t delete a stack if another stack references one of its outputs.
          4. You can’t modify or remove an output value that is referenced by another stack.
  14. Stack sets:
    1. As you create the stack set, you specify the template to use, as well as any parameters and capabilities that template requires.
    2. A stack set is a regional resource. If you create a stack set in one region, you cannot see it or change it in other regions.
  15. Stack instances: A stack instance is a reference to a stack in a target account within a region.
  16. Use of CF, Beanstalk and Auto scaling are free but you pay for the AWS resources that these services create.
  17. By Default CF rolls back everything when an error occurs (Atomic)
<<< CloudFront CDNRelational Database Service (RDS) >>>
Copyright 2005-2016 KnowledgeHills. Privacy Policy. Contact .