El proceso de enseñanza-aprendizaje desde una perspectiva socio-constructivista
Fase 4 - Orientación libre
6. Tipología de los errores según Astolfi (1999, 2001)
</ListBucketResult>
Calling the API directly using plain HTTPS requests is inconvenient. The easy way to talk to AWS is by using the command-line interface or SDKs, as you learn in this chap-ter. But the API is the foundation of all those tools.
4.1 Infrastructure as code
Infrastructure as code describes the idea of using a high-level programming language to control IT systems. In software development tools like automated tests, code reposito-ries, and build servers are increasing the quality of software engineering. If your infra-structure can be treated as code, you can apply the same techniques to infrainfra-structure code that you do to your application code. In the end, you’ll improve the quality of your infrastructure by using automated tests, code repositories, and build servers.
WARNING Don’t mix up the terms infrastructure as code and infrastructure as a service (IaaS)! IaaS means renting servers, storage, and network with a pay-per-use pricing model.
4.1.1 Automation and the DevOps movement
DevOps (Development operations) is an approach driven by software development to bring development and operations closer together. The goal is to deliver rapidly devel-oped software to the customer without a negative impact on quality. Communication and collaboration between development and operations are therefore necessary.
Multiple deploys per day are possible only if your pipeline from code changes to deployment is fully automated. If you commit into the repository, the source code is automatically built and tested against your automated tests. If the build passes the tests, it’s automatically installed in your testing environment. Perhaps some integra-tion tests are triggered. After the integraintegra-tion tests have been passed, the change is propagated into production. But this isn’t the end of the process; now you need to carefully monitor your system and analyze the logs in real time to ensure that the change was successful.
If your infrastructure is automated, you can spawn a new system for every change introduced to the code repository and run the integration tests isolated from other changes that were pushed to the repository at the same time. Whenever a change is made to the code, a new system is created (servers, databases, networks, and so on) to run the change in isolation.
94 CHAPTER 4 Programming your infrastructure: the command line, SDKs, and CloudFormation
4.1.2 Inventing an infrastructure language: JIML
For the purpose of understanding infrastructure as code in detail, let’s invent a new language to describe infrastructure: JSON Infrastructure Markup Language (JIML).
Figure 4.2 shows the infrastructure that will be created.
The infrastructure consists of the following:
■ Load balancer (LB)
■ Virtual servers
■ Database (DB)
■ DNS entry
■ Content delivery network (CDN)
■ Bucket for static files
To reduce issues with syntax, let’s say JIML is based on JSON. The following JIML program creates the infrastructure shown in figure 4.2. The $ indicates a reference to an ID.
{
Listing 4.1 Infrastructure description in JIML
Database
Figure 4.2 From JIML blueprint to infrastructure: infrastructure automation
"server": {
2 The JIML interpreter creates a dependency graph by connecting the resources with their dependencies.
3 The JIML interpreter derives a linear flow of commands from the dependency graph by traversing the tree from the bottom (leaves) to the top (root). The commands are expressed in a pseudo language.
4 The commands in pseudo language are translated into AWS API calls by the JIML runtime.
Let’s look at the dependency graph created by the JIML interpreter, shown in figure 4.3.
Traverse the dependency graph from bottom to top and from left to right. The nodes at the bottom have no children: DB
B
and bucketD
. Nodes without children have no dependencies. The serverC
nodes depend on the DBB
node. The LBE
96 CHAPTER 4 Programming your infrastructure: the command line, SDKs, and CloudFormation
depends on the server
C
nodes. The CDNF
node depends on the LBE
node and the bucketD
node. Finally, the DNSG
node depends on the CDN node.The JIML interpreter turns the dependency graph into a linear flow of commands using pseudo language. The pseudo language represents the steps that are needed to create all the resources in the correct order. The nodes at the bottom have no depen-dencies and are therefore easy to create; that’s why they’re created first.
References
"defaultSource": "$LB", "sources": [{
"path": "/static/*", "source": "$BUCKET"
}]
"password": ***", "engine": "MySQL"
} }, {
"type": "dns", "config": {
"from": "www.mydomain.com", "to": "$CDN"
}
Figure 4.3 The JIML interpreter figures out the order in which resources need to be created.
$DB = database create {"password": "***", "engine": "MySQL"}
$BUCKET = bucket create {}
await $DB
$SERVER1 = server create {"cpu": 2, "ram": 4, "os": "ubuntu"}
$SERVER2 = server create {"cpu": 2, "ram": 4, "os": "ubuntu"}
await [$SERVER1, $SERVER2]
$LB = loadbalancer create {"servers": [$_SERVER1, $_SERVER2]}
await [$LB, $BUCKET]
$CDN = cdn create {...}
await $CDN
$DNS = dns create {...}
await $DNS
The last step—translating the commands of the pseudo language into AWSAPI calls—
is skipped. You already learned everything you need to know about infrastructure as code: it’s all about dependencies.
Now that you know how important dependencies are to infrastructure as code, let’s see how you can use the command line to create infrastructure. The command line is one tool to implement infrastructure as code.