2 years ago (2018-11-16)  Technology |   First to comment  6 
post score 0 times, average 0.0

Familiar with AWS will certainly not be unfamiliar with Cloudformation, AWS official definition of Cloudformation is as follows:

AWS CloudFormation Cloud Resource Services enable developers and system administrators to create, manage, and update related AWS cloud resource templates in an easy and orderly manner.Use an AWS template or create your own cloud resources.

In order to be the fastest to Cloudformation in the heart a little bit of a concept, I distilled the following keywords for you:

  • Stakeholders: operations or DevOps areas
  • A service to manage cloud resources
  • Provided by AWS
  • Manage cloud resources with template files (or configuration files, code)

Code vs Visualization Operations

When it comes to the experience of using cloud services before, beginners should first be able to think, can I use Cloudformation to apply for a host, create Loadbalance, rather than manually "dot" on the AWS console (Console)?

Yes.If Cloudformation only makes visual interface manipulation code, this may only arouse the interest of code enthusiasts, and we know many of the benefits of code, such as higher efficiency and automatic machine execution.

However, because not everyone likes the code.For people with "code phobia," or professional operators accustomed to configuring on the interface, interface operations are clearly more intuitive than code and have more user-friendly operation guidance.

For the pursuit of efficient engineering practice, the code or interface operation is not "radish greens, love each other" interest hobbies, but the problem of productivity.

Infrastructure is code

A word called DevOps is popular these days, and Wikipedia is defined as follows:

DevOps (development and Operations combination words) is a culture, sport, or practice that values communication and collaboration between software Developers (Dev) and IT operations Technicians (OPS).Enable building, testing, and publishing software to be faster, more frequent, and more reliable by automating the process of "software delivery" and "schema change."

My personal understanding is that DevOps requires the ability to integrate operations into software development systems, such as the use of software development methods such as agile, automated continuous integration, testing, delivery, code management, and so on, and, second, the development of operational awareness, the delivery of infrastructure as part of the delivery of software, Dramatically improve R & amp; d performance by empowering developers with cloud computing to achieve end-to-end delivery of full stack capabilities.

In this sense, Cloudformation is one such tool that incorporates infrastructure as code into part of software development and uses software engineering methods to manage the infrastructure.

What does "infrastructure as code" bring to us?

In the author's team, the code that can write DevOps has been used as a standard skill for development.When we start a new Codebase, we often need to think about the content:  

Cloudformation and the "infrastructure as code" behind it

Screenshot of the file structure of a project
  • Infrastructure code (/INFRA catalog)
  • Continuous integration of pipeline code (/pipeline directory, this year there is also a word called "Pipeline is Code")
  • Business code (including front-end code, test code,/API,/test directory)

In the case of some large internet companies, the authority to carry out peacekeeping development is completely separate, and development may only focus on the business code part.

In fact, in the early stages after the start of a project, the first intervention may be the establishment of a set of online development environment (DEV), test Environment (QA), Production environment (PROD) for the development of daily debugging, tester testing and release projects, if the use of continuous integration of the way, You also need to build a continuous integration (CI/CD) pipeline.

  • Automatically build a cloud environment with one click

With the AWS platform and the Cloudformation it provides (or third-party tools such as TerraForm, now popular kubernet), using infrastructure code, we can quickly build a complete set of cloud environments.Using the same set of infrastructure code at the same time, and configuring different environment variables, you can quickly replicate different online environments.

Take Cloudformation as an example:

Writing Cloudformation code, such as writing through the following code, through the AWS Cloudformation command provided by AWS, enables you to create an elastic scalable instance at AWS.

At the same time, we can use AWS Cloudformation Designer to visually design our infrastructure and its previous topologies and associations, and export code.

Cloudformation and the "infrastructure as code" behind it
AWS Cloudformation Designer
  • Implement code version Management with GIT, etc.

A code-based infrastructure means that it can be managed by version control tools such as Git, which means that any changes to the infrastructure, such as changing server memory, replacing availability zones, modifying domain names, security groups, and so on, can be tracked in the form of review codes.

In the past, misoperation on the console interface made it difficult to record problems with the online environment, and if the problem caused by modifying the server environment configuration, you can quickly roll back the server environment through git rollback code.

  • Seamless switching between infrastructure versions

    • Declarative actions

Prior to Cloudformation, AWS had introduced command-line tools or SDKS to manage AWS resources, and unlike their "imperative" operations, Cloudformation provided a "declarative" feature.

The "imperative" action wants you to write the program one step at a pace to achieve the desired state, and the declarative only cares about the state of the resources and resources you want, and Cloudformation automatically analyzes what needs to be done to reach the desired state.(Understand the difference between declarative and imperative, refer to "Comparison of declarative programming and imperative programming")

  • Idempotent

Cloudformation's declarative operations provide it with idempotent features to run new Cloudformation code at any time, in any version of the infrastructure, and AWS will help you build the same infrastructure every time.

  • Atomic Sex

Most people learn about "atomicity" in database transactions.Cloudformation also supports an atomic operation that either succeeds or fails.Failure can be rolled back automatically, and resources generated in a failed operation are automatically deleted when rolled back.

  • Incorporating continuous integration/deployment lines (CI/CD)

The "Infrastructure is Code" code, automation, for the CI/CD pipeline management infrastructure to provide the possibility.

Ideally, as with modifying the business code, when we want to make changes to the infrastructure, by modifying the infrastructure code, submitting it to the GIT repository, triggering the CI/CD pipeline to run the infrastructure code, and then achieving the purpose of updating the infrastructure.  

Cloudformation and the "infrastructure as code" behind it
Continuous integration

At the same time, according to the feedback provided by the cloud computing service provider, update the deployment status of the CI/CD pipeline: Red is failed green.

QA or teams can move infrastructure and business code together to the next stage, based on test results and release plans, through the pipeline.

Cloudformation and the "infrastructure as code" behind it
GoCD Continuous Integration Pipeline

Extended thinking:

2018 ThoughtWorks Technology Radar Phase 19 introduces us to a Mock framework for cloud services called LocalStack, which means that we can debug infrastructure code locally or do unit or integration testing for infrastructure code.The original text is as follows:

One challenge when using cloud services is how to develop and test locally. LOCALSTACK solves this problem for AWS.It provides local test surrogate implementations for a variety of AWS services, including S3, Kinesis, Dynamodb, and Lambda.It builds on existing best tools such as Kinesalite, Dynalite, Moto, and increases the functionality of process isolation and error injection. The use of LocalStack is simple and comes with a simple JUnit runtime and JUnit 5 extensions.We've used LocalStack in a number of projects and are impressed with it.


This article has been in the copyright printing record, protected by copyright law, without permission shall not be reproduced!If you think this article is useful for you, you can click on the "sponsor author" below to hit the author!

Reprint Annotated Original source:Baiyuan's Blog> >https://wangbaiyuan.cn/en/cloudformation-infrastructure-code-behind-it-2.html

Post comment


No Comment


Forget password?