Introducción a CloudFormation - Español
Introduction to CloudFormation
In this section, the speaker introduces CloudFormation and explains its motivation in simplifying the creation, update, and deletion of resources in AWS.
Motivation behind CloudFormation
- A cloud application consists of multiple components such as networks, compute instances, databases, security groups, etc.
- Managing the creation, update, and deletion of these resources manually can be repetitive and prone to human errors.
Infrastructure as Code with CloudFormation
- CloudFormation is a service that allows you to create, update, or delete AWS resources using infrastructure as code.
- You can model your entire infrastructure using a text file called a template.
- The template becomes the single source of truth for your infrastructure and helps standardize components used across your organization.
Benefits of Using CloudFormation
- Simplifies resource management by securely and repeatably provisioning resources.
- Enables building and rebuilding infrastructure without manual actions or custom scripts.
- Automatically handles changes and rollback if errors are detected.
- Provides a simplified way to create and manage collections of resources (stacks).
- Supports version control of infrastructure configurations.
- Can be executed through the AWS Management Console, command line interface (CLI), or SDKs.
Template Formats
- Two formats available for templates: JSON or YAML.
- No additional charges for using CloudFormation; only pay for the provisioned resources.
How CloudFormation Works
This section explains how CloudFormation works by translating templates into API requests to provision resources in an orderly manner.
Execution Process
- Create or use existing templates written in JSON or YAML format.
- Present the templates to CloudFormation either by uploading local files or referencing from S3 buckets.
- CloudFormation translates the template into a series of API requests to provision a stack of resources.
- CloudFormation calls the corresponding service APIs to create and provision the resources in your account.
- Resources are ordered based on dependencies specified in the template.
- CloudFormation can also handle updates and deletions of resources.
Free Usage and Availability
- Using CloudFormation is free; only pay for the provisioned resources.
- Available in all AWS regions.
- Supports declaring dependencies or relationships between resources.
Artifacts of CloudFormation
This section explains the artifacts that make up CloudFormation, including templates, change sets, stacks, and stack sets.
Template
- Describes the desired state of your infrastructure, including resources, attributes, dependencies, and configurations.
- Written in JSON or YAML format.
Change Set
- Represents changes you want to make to an existing stack.
- Generated when you execute a template through CloudFormation and want to modify the infrastructure.
Stack
- A group of resources defined by a template and their intended states.
- Created when executing a template through CloudFormation.
Stack Set
- A collection of stacks that can be deployed across regions or accounts.
Syntax of a CloudFormation Template
This section explains the syntax used in a CloudFormation template written in YAML format.
Template Structure
- Version: Specifies the version of AWS CloudFormation used for the template.
- Description (optional): Provides a description for the template.
- Metadata (optional): Objects that provide additional information about the template.
Example Template Anatomy
AWSTemplateFormatVersion: "2010-09-09"
Description: "Sample CloudFormation Template"
Metadata:
Key1: Value1
Key2: Value2
Conclusion
This section concludes the introduction to CloudFormation and highlights the key points discussed.
- CloudFormation simplifies resource management by using infrastructure as code.
- Templates describe the desired state of resources in JSON or YAML format.
- Change sets allow modifications to existing stacks.
- Stacks are groups of resources created from templates.
- Stack sets enable deploying stacks across regions or accounts.
CloudFormation Runtime and Parameters
This section discusses the runtime of CloudFormation templates, including creating and updating them. It also covers referencing parameters in resource sections and outputs.
CloudFormation Runtime
- CloudFormation templates can be executed at runtime when created or updated.
- Mapping or mappings is an assignment of key-value pairs used for conditional parameters.
- Conditional parameters can control the creation of certain resources based on specific conditions.
Resource Sections and Outputs
- Resources are the mandatory part of a CloudFormation template that specify the properties of each resource.
- Outputs describe the resources that will be returned when the template is executed.
- It is good practice to declare outputs in a CloudFormation template for reusability.
Demo: Deploying an EC2 Instance with CloudFormation
This section provides a demonstration of deploying an EC2 instance using CloudFormation. The demo includes a simple template with parameters, resources, and outputs.
Template Structure
- The template includes version, description, parameters, resources, and outputs sections.
- Parameters define keys used to connect to the EC2 instance.
- Resources include an EC2 instance and a security group associated with it.
Deployment Process
- Access the AWS Management Console for CloudFormation.
- Create a new stack using the provided template.
- Load the template file from your local workstation or Amazon S3.
- Review the template in the designer to visualize its structure.
- Provide a name for the stack (e.g., "simple-s2").
- Specify parameter values, such as SSH key names.
- Add optional tags for stack configuration if needed.
- Proceed with stack creation.
Loading Template and Viewing in Designer
This section explains how to load a CloudFormation template and view it in the designer for visualization.
Loading Template
- In the AWS Management Console for CloudFormation, choose "Create stack" to start creating a new stack.
- Select the option to upload a template file from your local workstation or Amazon S3.
Viewing in Designer
- After loading the template, you can view it in the CloudFormation designer.
- The designer provides a visual representation of the resources defined in the template.
- Additional resources can be added using advanced options within the designer.
Stack Creation and Parameter Configuration
This section covers stack creation and parameter configuration during the CloudFormation deployment process.
Stack Creation
- Provide a name for the stack during creation (e.g., "simple-s2").
- Choose an existing SSH key pair or create a new one for connecting to EC2 instances.
Parameter Configuration
- Configure parameters based on their predefined keys.
- In this case, use the previously mentioned SSH key pair for connectivity purposes.
- Optional tags can be added for further customization if required.
Creating Stacks and Resources
In this section, the speaker discusses the process of creating stacks and resources using CloudFormation.
Creating a Stack
- A stack is created to manage resources efficiently.
- The first resource created is the security group, as it is required for the instance.
- CloudFormation waits for the security group to be created before initiating the creation of other resources.
Instance Creation Progress
- The progress of resource creation can be tracked in CloudFormation.
- The instance creation is still in progress at this stage.
Instance Details
- Once the instance is created, its details can be viewed.
- Details include public and private IP addresses and the associated security group.
Verifying Connectivity
- SSH connectivity to the instance can be verified using its public IP address.
- A terminal command can be used to establish an SSH connection.
Destroying Resources
This section covers how to destroy resources created through CloudFormation.
Deleting Resources
- To delete resources, access the CloudFormation console.
- Select the stack containing the desired resources and choose "Delete".
- This will remove all resources associated with that stack, including security groups and instances.