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. If at any point you need to reverse changes to your infrastructure, you can use a previous version of your template.
  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.
    AWSTemplateFormatVersion: "2010-09-09"
    Description: A sample template
     Type: "AWS::EC2::Instance"
     ImageId: "ami-2f726546"
     InstanceType: t1.micro
     KeyName: testkey
     DeviceName: /dev/sdm
     VolumeType: io1
     Iops: 200
     DeleteOnTermination: false
     VolumeSize: 20
     Type: AWS::EC2::EIP
     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. Before making changes to your resources, you can generate a change set, which is summary of your proposed changes. Change sets allow you to see how your changes might impact your running resources, especially for critical resources, before implementing them.
  13. 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. For example, you could conditionally create a resource that depends on whether the stack is for a production or test environment.
    7. Transform (optional)    For serverless applications (also referred to as Lambda-based applications), specifies the version of the AWS Serverless Application Model (AWS SAM) to use. When you specify a transform, you can use AWS SAM syntax to declare resources in your template. The model defines the syntax that you can use and how it is processed. 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. You can refer to resources in the Resources and Outputssections of the template.
    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.
        Logical ID:
          Description: Information about the value
          Value: Value to return
            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. The logical ID must be alphanumeric (a-zA-Z0-9) and unique within the template.
        2. Description (optional): String type that describes the output value. 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. 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 use the intrinsic functionFn::ImportValue to import only values that have been exported within the same region.
          4. For outputs, the value of the Name property of an Export can’t use Ref or GetAtt functions that depend on a resource. Similarly, the ImportValue function can’t include Ref or GetAtt functions that depend on a resource.
          5. You can’t delete a stack if another stack references one of its outputs.
          6. You can’t modify or remove an output value that is referenced by another stack.
  14. Stack sets:

    1. stack set lets you create stacks in AWS accounts across regions by using a single AWS CloudFormation template.

    2. All the resources included in each stack are defined by the stack set’s AWS CloudFormation template.

    3. As you create the stack set, you specify the template to use, as well as any parameters and capabilities that template requires.

    4. After you’ve defined a stack set, you can create, update, or delete stacks in the target accounts and regions you specify.

    5. When you create, update, or delete stacks, you can also specify operation preferences, such as the order of regions in which you want the operation to be performed, the failure tolerance beyond which stack operations stop, and the number of accounts in which operations are performed on stacks concurrently.

    6. 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
    1. stack instance is a reference to a stack in a target account within a region.
    2. A stack instance can exist without a stack; for example, if the stack could not be created for some reason, the stack instance shows the reason for stack creation failure. A stack instance is associated with only one stack set.
<<< AuroraElasticache >>>
Copyright 2005-2016 KnowledgeHills. Privacy Policy. Contact .