You don't have access to this class

Keep learning! Join and start boosting your career

Aprovecha el precio especial y haz tu profesión a prueba de IA

Antes: $249

Currency
$209
Suscríbete

Termina en:

0 Días
10 Hrs
23 Min
15 Seg

Laboratorio: empezando con CloudFormation

13/19
Resources

CloudFormation allows us to provision infrastructure as code. To test CloudFormation, using a template we will create a stack from which an S3 bucket will be deployed. Then, we will update the stack by adding another S3 bucket, and finally we will delete it.
Diagrama de stack de CloudFormation

Understanding the template

In this repository you will find the CloudFormation template that we will use. The template has the following JSON structure (remember, CloudFormation accepts JSON or YAML format):

{ " AWSTemplateFormatVersion": "2010-09-09", " Description": "this template does XXXX", " Metadata": {}, " Parameters": {}, " Mappings": {}, " Conditions": {}, " Transform": {}, " Resources": {}, " Outputs": {} }

These parameters correspond to the following:

  • AWSTemplateFormatVersion: this parameter is optional. Here we specify the template version
  • Description: text string describing the template. It must follow AWSTemplateFormatVersion.
  • Metadata: objects that provide additional information about the template.
  • Parameters: values that we will pass to the template when it is executed, either during the creation or update of the *stack.
  • Mappings: allows to assign a set of values to a specific key. For example, to set values based on a region, we can create a mapping that uses the name of a region as a key and contains the values we want to specify for each region.
  • Conditions: controls that resources are created or values are assigned to those resources based on a condition. For example, we can assign different values for production or test environments.
  • Transform: Specifies the macros that AWS CloudFormation uses to process the template.
  • Resources: here we declare the resources to be included in the stack. For example, EC2 instances or S3 buckets.
  • Outputs: declares output values that can be used in other stacks.

Steps to create the stack

  1. We go to the CloudFormation page from our AWS account (on this page we can learn more about the service in question).
  2. Here we click on "Create stack".
  3. To create the stack, under "Specify template" we select "Load a template file", and load the createstack.json file. This file simply defines an S3 bucket called "platzilab".
{ " Resources": { " platzilab": { " Type": "AWS::S3::Bucket"} } } }

Subir plantilla
4. We click next and then choose a name for the stack. In this case, we call it cfnlab, and click next.
5. Optionally, we can add labels to identify the stack, and an IAM role.
6. We leave the rest of the configurations by default and click next. Then it will take us to review the configurations, and we click on "Create stack".
7. We will be able to see the stack creation process, the events and the resources that were created. If you look at the name of the created bucket, you will see that it is composed by the name of the stack, the name we assigned to the bucket in the template, and a random text string. This is to avoid creating duplicate named resources.

Pila y bucket creados

Contribution created with contributions from: Ciro Villafraz.

Contributions 14

Questions 2

Sort by:

Want to see more contributions, questions and answers from the community?

Como aporte, hay varios frameworks que nos permiten modelar los recursos en .yaml, .ts (typescript) entre otros que integrandolos con GitOps los CI de infraestructura se vuelve muy rápido 😃, ejemplos:

  • Serverless Framework
  • Pulumi
  • Terraform

Laboratorio: empezando con CloudFormation

.
Esto es lo que vamos a realizar en este laboratorio
.

.

Paso a Paso del laboratorio

.

  1. En el buscador escribimos CloudFormation


    .

  2. Damos click en create stack

    .

  3. En Choose File cargamos el JSON que se encarga de crear el stack. Los archivos los dejó el profe en el repositorio: https://github.com/platzi/aws-cloud-practitioner/tree/main/lab-cloudformation


    .

  4. Damos el nombre del stack


    .

  5. Configuramos los tags y dejamos el resto igual

APORTE IMPORTANTE!

Para que puedan seguir el flujo de la clase por favor primero elijan la Region

Se podría emplear codebuild y cloud formation para automatizar por completo el despliegue. Una rama de la infraestructura en prueba y la otra en producción, que cambie menos.

Yo tengo que aprender esto, pero sinceramente soy mas de Terraform, es una alternativa excelente, aunque no sé si se equipara con Cloud Formation en sus capacidades.

Me puse a revisar y en donde trabajo utilizan yaml para crear el template de cloudformation

Ejemplo plantilla ```js AWSTemplateFormatVersion: '2010-09-09' Description: Plantilla simple de CloudFormation para lanzar una instancia de EC2 Resources: MyEC2Instance: Type: "AWS::EC2::Instance" Properties: InstanceType: "t2.micro" ImageId: "ami-0abcdef1234567890" # Reemplaza con un ID de AMI válido para tu región KeyName: "my-key-pair" # Reemplaza con el nombre de tu par de llaves SecurityGroups: - Ref: MySecurityGroup MySecurityGroup: Type: "AWS::EC2::SecurityGroup" Properties: GroupDescription: "Permitir acceso SSH" SecurityGroupIngress: - IpProtocol: "tcp" FromPort: "22" ToPort: "22" CidrIp: "0.0.0.0/0" ```

Otros frameworks de mas alto nivel, son AWS CDK y AWS SAM

CloudFormation es un servicio de AWS que permite modelar y aprovisionar recursos de infraestructura en la nube utilizando archivos de configuración en formato YAML o JSON. Un laboratorio básico para empezar con CloudFormation incluiría los siguientes pasos: ### **1. Crear un Stack Básico en CloudFormation** Para empezar, se puede desplegar una infraestructura simple en AWS, como un bucket de S3. #### **Paso 1: Crear el archivo de la plantilla (YAML)** Crea un archivo llamado `s3-bucket.yaml` con el siguiente contenido: AWSTemplateFormatVersion: '2010-09-09' Resources: MyS3Bucket: Type: AWS::S3::Bucket Properties: BucketName: my-cloudformation-lab-bucket #### **Paso 2: Subir la Plantilla a CloudFormation** 1. Accede a la consola de AWS y ve a **CloudFormation**. 2. Haz clic en **Create Stack** > **With new resources (standard)**. 3. Selecciona **Upload a template file** y sube `s3-bucket.yaml`. 4. Asigna un nombre a tu Stack, como `MyFirstStack`. 5. Haz clic en **Next**, luego en **Next** nuevamente sin cambiar configuraciones adicionales. 6. En la pantalla de revisión, haz clic en **Create stack**. #### **Paso 3: Verificar la Creación** * Una vez que el Stack se haya creado con éxito, ve a **S3** en la consola de AWS y verifica que el bucket `my-cloudformation-lab-bucket` ha sido creado. ### **2. Eliminar el Stack** Para limpiar los recursos creados: 1. Ve a la consola de CloudFormation. 2. Selecciona el Stack `MyFirstStack`. 3. Haz clic en **Delete**. ### **Conceptos Claves en CloudFormation** * **Plantilla**: Define la infraestructura a desplegar. * **Stack**: Es una instancia de la plantilla en AWS. * **Recursos**: Son los componentes creados por CloudFormation (S3, EC2, RDS, etc.). * **Parámetros**: Permiten personalizar la plantilla sin modificar el código. * **Salidas**: Valores generados al ejecutar el Stack. Este laboratorio es un buen punto de partida para entender cómo funciona CloudFormation. A partir de aquí, puedes experimentar con otros recursos como EC2, RDS o VPC. 🚀
hola colegas. estoy en el paso 4 Set deployment options.... y no sé que paso seguir ..... me quedé...me pueden ayudar por favor? .. gracias ![](https://static.platzi.com/media/user_upload/image-fb8c1f4b-02bf-45eb-a8a4-ffb24a73ecf1.jpg)
![](https://static.platzi.com/media/user_upload/image-569e69dc-2f59-4a31-b544-322687b9e691.jpg) Me sale ese error :( [Error Responses - Amazon Simple Storage Service](https://docs.aws.amazon.com/AmazonS3/latest/API/ErrorResponses.html)

Recordatorio para que siempre revises en que region crear tus recursos

Información resumida de esta clase
#EstudiantesDePlatzi

  • CloudFormation nos permite construir toda la infraestructura como código en formato Json

  • Es buena idea tomar el curso de infraestructura como código para entender bien como crear y estructurar el archivo Json

  • Podemos utilizar Json o Yaml

  • El Bucket y Stack de Cloudformation deben estar creados en la misma región

  • Los Stacks pueden tener etiquetas para que sean fácilmente identificables

  • Dentro de S3 los Buckets deben tener único nombre