You are currently viewing Create CloudFormation Template

Create CloudFormation Template

Create CloudFormation Template

Hello Everyone

Welcome to CloudAffaire and this is Debjeet.

In the last blog post, we have created a CloudFormation stack using a sample template provided by AWS.

https://cloudaffaire.com/create-cloudformation-stack/

In this blog post, we are going to create our 1st CloudFormation template and using this template we will create a CloudFormation stack in AWS console. We have tried to include most of the template elements in this demo.

Create CloudFormation Template:

Step 1: Login to AWS console and navigate to ‘CloudFormation’.

Create CloudFormation Template

Note: For shortening of the code, only has AMI mapping for APAC regions. Make sure you are in any one of the APAC regions.

Step 2: Click ‘Create Stack’.

Create CloudFormation Template

Step 3: Open your favorite editor and create a file with .yaml extension using below YAML code.

Note: Make sure code indentation id correct or you can download the template_elements_demo.yaml file from below GitHub repo.

https://github.com/CloudAffaire/CloudFormation

Step 4: Select ‘Template is ready’ and then ‘Upload a template file’, click ‘Choose file’ to upload the file and click ‘Next’.

Create CloudFormation Template

Step 5: Provide name, parameters for your stack and click ‘Next’.

Create CloudFormation Template

Step 6: Leave ‘Configure stack options’ as it is and click ‘Next’.

Create CloudFormation Template

Step 7: Review your stack configuration and click ‘Create stack’.

Create CloudFormation Template

Note: It will take some time to complete the stack creation. You can monitor the progress in ‘Events’ section.

Our stack successfully created using the template created in step 3.

Create CloudFormation Template

Correlate the code with below tabs output for your understanding.

Events: Stack creation details with the timeline (used for troubleshooting if stack creation failed)

Resource: AWS resources created under this stack (in our case one EC2 instance, if db then elastic IP)

Outputs: Values that are returned (In our instance id, type and if db then elastic IP address)

Parameters: Values passed to your template at runtime (cache or web or db)

Template: The actual code for this stack (defined in step 3)

Step 8: Cleanup.

Create CloudFormation Template

Note: This will also delete the underlying resources for this stack.

Hope you have enjoyed this article. In the next blog post, we will create a template using CloudFormation Designer.

To get more details on CloudFormation, please refer below AWS documentation

https://docs.aws.amazon.com/cloudformation/index.html

 

This Post Has One Comment

  1. Avatar
    li

    Hello, how would I like to see if you could help me? Will my code be good? because it gives me some errors

    AWSTemplateFormatVersion: 2010-09-09
    Parameters:
    EC2Instance:
    Type: ‘AWS::EC2::Image::Id’
    Default: ami-01e24be29428c15b2
    SubnetID:
    Type:’AWS::EC2::Subnet::Id’
    Description:Subnet de la instancia
    SecurityGroupsIDs:a
    Type: ‘AWS::EC2::SecurityGroup::Id’
    Default: sg-0d68df229cf090306
    Description:grupo de seguridad
    KeyName:
    Type: ‘AWS::EC2::KeyPair::KeyName’
    Default: xxxxxxx
    Description: nombre key
    InstanceType:
    Type:String
    Default: t2.micro
    Description:EC2 tipo instancia
    Storage:
    Default: 8
    Type: String
    Description: gb
    Resources:
    EC2Instance:
    Type:Type: AWS::EC2::Image::Id
    Properties:
    ImageId: !Ref EC2Instance
    KeyName: !Ref KeyName
    SecurityGroupIds: !Ref SecurityGroupsIDs
    SubnetId: !Ref SubnetID

    Tags:
    -Key:Owner
    Value: prueba
    -Origin:
    Value: DevOps Academy 2019

Leave a Reply