Pulumi架构即是代码
Pulumi 是一个架构即是代码的开源项目,可在任何云上创建和部署使用容器,无服务器功能,托管服务和基础架构的云软件的最简单方法。
只需用您喜欢的语言编写代码,Pulumi就可以使用基础架构即代码方法自动配置和管理您的AWS,Azure,Google Cloud Platform和/或Kubernetes资源。 跳过YAML,使用您已经熟悉和喜爱的标准语言功能,如循环,函数,类和包管理。
如下代码可创建三个 Web 服务器:
let aws = require("@pulumi/aws");
let sg = new aws.ec2.SecurityGroup("web-sg", {
ingress: [{ protocol: "tcp", fromPort: 80, toPort: 80, cidrBlocks: ["0.0.0.0/0"]}],
});
for (let i = 0; i < 3; i++) {
new aws.ec2.Instance(`web-${i}`, {
ami: "ami-7172b611",
instanceType: "t2.micro",
securityGroups: [ sg.name ],
userData: `#!/bin/bash
echo "Hello, World!" > index.html
nohup python -m SimpleHTTPServer 80 &`,
});
}
或者一个简单的无服务器定时器,在每天早上八点半抓取 Hacker News 的信息:
const aws = require("@pulumi/aws");
const snapshots = new aws.dynamodb.Table("snapshots", {
attributes: [{ name: "id", type: "S", }],
hashKey: "id", billingMode: "PAY_PER_REQUEST",
});
aws.cloudwatch.onSchedule("daily-yc-snapshot", "cron(30 8 * * ? *)", () => {
require("https").get("https://news.ycombinator.com", res => {
let content = "";
res.setEncoding("utf8");
res.on("data", chunk => content += chunk);
res.on("end", () => new aws.sdk.DynamoDB.DocumentClient().put({
TableName: snapshots.name.get(),
Item: { date: Date.now(), content },
}).promise());
}).end();
});
更多的例子请看 pulumi/examples.
该项目包含 Pulumi 的命令行工具、语言 SDK 和核心引擎。
评论
