Infrastructure as code Automation

Infrastructure as code Automation

In this article i would like to focus on the most value part of DevOps which is Automation.

In this category we will learn how it works and look at a simple example of Infra as code and it's automation.

Imagine the situation in which you start rolling on a new application, you configure your Local environment, Development Stage, Test Stage , QA Stage , maybe PreProduction Stage and finally Production. Wow , seems a Huge work, your application code will be shared on all theses stages , but the Ips will change, the Servers will change, the infrastructure will change based on the importance of the stage and it's proper environment, do you like to configure on thing multiple times? do you like have more error pron tasks? , surely no, and surely you not gonna lost the money to duplicate the production power full resources on your test environment, or inversely lost the performance and SLA by duplicating the Test environment configuration on production.

Here we ll learn how to do the first step Automating IaC on AWS :

  1. Convert your infrastructure to a document base source
  2. Parameterize your source
  3. Implement a source versioning strategy
  4. Automate commitment and change detections
  5. Run Continuous Delivery

What we love to have followings

  1. Run Continuous integration
  2. Run Continuous Deployment

What we must have

  1. Automating Tests

Amazon web services Infra As Code:

AWS introduces CloudFormation to simplify the DevOps word, by allowing you to have human readable , versioned and parameterized infrastructure resources.

Human Readable : You can write them easily in JSON or Yaml formats. camparing to the XML based structures and Modern Coding Languages as C# , Java is easy to understand and you don't need to have any competency on Coding

Versioned: When i say versioned i don't face to talk about Git, GitHub, SVN, CVS or TFS, I just want to say the Cloud Formation Can recognize your template modifications and execute just your modification , it is really intelligent to find your stack , compare the new version of template with the last successful released one.

Parameterized : Each Cloud formation Template consists of some structured parts which help you to make the rich templates, fully dynamic and extensible.

A template has 1 mandatory part:

  • Resource

And has useful parts as:

  • Parameters
  • Conditions
  • Metadata
  • Mappings

To Know More About CFT's :

Example :

At the first step we create a simple template

AWSTemplateFormatVersion: 2010-09-09
Resources:
  MyLambda:
    Type: 'AWS::Lambda::Function'
    Properties:
      FunctionName: myLambdaToTestIaC
      Code:
        S3Bucket: myiacsourcebucket
        S3Key: lambdacode.zip
      Handler: >-
        index.handler
      Role: arn:aws:iam::<account_id>:role/lambda_basic_execution
      Runtime: nodejs8.10
      Timeout: 15

This template creates a new lambda function in aws plateform, why i choose it as this creation will be free in your environment for a learning purpose.

Now , we need to build our CI/CD process , by using CodePipeline we construct this important step but before wee need to have our first part.

Lets do theses steps:

  1. Upload template to S3
  2. Launch Cloud formation Stack
  3. Implement the source of Pipeline
  4. Implement the Deploy step

S3 Bucket:

  • In Aws Console create a new bucket called myiaccourcebucket
  • Upload the template you have already saved on local drive
Aucun texte alternatif pour cette image

Click next , accept all by default and continue bucket creation steps

Now, Upload zipped template to your bucket

Aucun texte alternatif pour cette image

You need to zip the template and upload it on a standard s3 with all default config, just do next and finally upload.

You need to give cloud formation to find the template on your bucket, by default the buckets are not public , for learning purpose we make the bucket public.

You Need to Enable Versioning on the bucket.

CloudFormation : You need to launch the CloudFormation Stack for the first time.

Go to Cloud Formation and select launch stack as bellow

Aucun texte alternatif pour cette image

Launch stack by Selecting the yaml template from your local or upload it to S3 bucket

Aucun texte alternatif pour cette image

In the Next screen you will be asked for the stackname ,

Aucun texte alternatif pour cette image

For the rest accept all defaults and go ahead , once the stack created go to CodePipeline service.

CodePipeline:

Codepipeline helps us to Build , Test and deploy our sources in a structured manner, for example you can get your java or C# code from GitHub and build it and finally deliver it to your QA environment or production. you can automate the deployment .

Create Pipeline : by creating the pipeline you can implement the CI/CD process using CodeCommit , CodeBuild , CodeDeploy but in a connected and managed fashion.

let's start it by selecting the create pipeline button, in the first step we configure our source to create the artifact .

Aucun texte alternatif pour cette image

Type a name and select a role and the artifact store default, you can select a custom location for artifact , but at this point use the default on , and consider that the default artifact source name will be as SourceArtifact. we need to use it later

Now, Configure the source stage , here we configure how and where discover our source

Aucun texte alternatif pour cette image

The change detection can be done by CodePipeline or by CloudWatch events

In the next screen skip the build step, we don't need a build on CloudFormation templates.

Configure Deploy Screen as bellow ,

Aucun texte alternatif pour cette image

The Stack Name will be the name of stack you have already created before , and the template consists of the source artifact and the template file in the artifact, for the role use a role customized or a role with admin access.

Select Next and click on create pipeline then. within some seconds the pipeline will be started. the source and deploy stage will run in sequence.

The stack status will be changed as UPDATE_COMPLTE.

Let's test the cloudformation versioning by modifing the name of lambda in the template and re-uploading the zip file. as soon as you upload the file the codepipeline runs the process again as bellow , and your lambda name will be changed.

Aucun texte alternatif pour cette image

In the next article we will find how to test our templates before deploying and parameters in the templates.

要查看或添加评论,请登录

Omid Eidivandi的更多文章

  • Modular Software Coupling Pitfalls

    Modular Software Coupling Pitfalls

    Software is basically the composition of some modular / single perspective code components, theses components…

  • DISTRIBUTED Api

    DISTRIBUTED Api

    Following all discussions that I had recently with lots of SDE , SA and Tech Leaders there are some common parts they…

    1 条评论
  • Software Architecture Design Decision

    Software Architecture Design Decision

    Our today world rounds around a digital core, where any part of human and business needs are available on digital…

  • Serverless & Testing

    Serverless & Testing

    Serverless is modern but enough complicated, there is a need to know roughly the design and its components. it's hard…

  • Serverless Error Handling

    Serverless Error Handling

    It's a while i'm challenging Serverless where there is no permanent server or VM to manage , where all resiliency is…

  • Some AWS FaaS Unknown Points

    Some AWS FaaS Unknown Points

    When interacting with lambda we got sometime tired of microservice developed on serverless and their problems , when…

  • Some Coding Optimizations

    Some Coding Optimizations

    Recently i found some interesting coding challenges in some of our solutions developed in C# , when looking at the code…

  • LoadBalancer HealthCheck

    LoadBalancer HealthCheck

    In this article i would like to share two scenarios i was fronted with two clients i'm working with on Azure and AWS…

  • SMACS

    SMACS

    What is SMACS? Social, Mobility, Analytics, Cloud et Security Social Today, all social platforms such as Twitter…

  • Three tiers Applications in Cloud

    Three tiers Applications in Cloud

    in Today's world, Mostly we talk about cloud and cloud first, we are trying to migrate all our on-premises workloads to…

社区洞察

其他会员也浏览了