AWS :: CloudFormation :: Init它是如何工作的?

时间:2020-12-26 23:33:12

We can use AWS::CloudFormation::Init to execute commands and upload files after starting an instance. But does anybody know what are the internals of this operation (from Amazon's side)?

我们可以使用AWS :: CloudFormation :: Init在启动实例后执行命令和上传文件。但是有人知道这次行动的内部是什么(来自亚马逊方面)?

When we pass a template in, at what point are the files or commands transmitted to the VM? Is this is a Xen feature (through special pipe), or via the network?

当我们传入模板时,文件或命令在什么时候传输到VM?这是Xen功能(通过特殊管道),还是通过网络?

"Resources": {
  "MyInstance": {
    "Type": "AWS::EC2::Instance",
    "Metadata" : {
      "AWS::CloudFormation::Init" : {
        "config" : {
          "packages" : {
            :
          },
          "sources" : {
            :
          },
          "commands" : {
            :
          },
          "files" : {
            :
          },
          "services" : {
            :
          },
          "users" : {
            :
          },
          "groups" : {
            :
          }
        }
      }
    },
    "Properties": {
      :
    }
  }
}

1 个解决方案

#1


28  

Creating a AWS::CloudFormation::Init resource as metadata to an EC2 instance does not cause the instance to do anything by itself.

将AWS :: CloudFormation :: Init资源创建为EC2实例的元数据不会导致实例自行执行任何操作。

For the instance to actually perform all the operations specified in that resource, it must run the cfn-init command line tool. On Amazon EC2 AMIs that command is already installed at /opt/aws/bin/cfn-init. The command takes several options, including the name of the AWS::CloudFormation::Init resource, the name of the EC2 server resource, and the region you are running in. You also need to provide AWS security credentials.

对于实际执行该资源中指定的所有操作的实例,它必须运行cfn-init命令行工具。在Amazon EC2 AMI上,该命令已安装在/ opt / aws / bin / cfn-init中。该命令有多个选项,包括AWS :: CloudFormation :: Init资源的名称,EC2服务器资源的名称以及您运行的区域。您还需要提供AWS安全凭证。

If you'd like this to run automatically when you create a new instance (I sure did) you'll have to use the EC2 instance's UserData to create a shell script that the instance will run on first boot, and put the cfn-init command in it.

如果您希望在创建新实例时自动运行(我确实这样做),您将必须使用EC2实例的UserData来创建实例将在首次启动时运行的shell脚本,并放入cfn-init命令在里面。

I've written about this specific issue in my blog recently.

我最近在博客中写过这个具体问题。

#1


28  

Creating a AWS::CloudFormation::Init resource as metadata to an EC2 instance does not cause the instance to do anything by itself.

将AWS :: CloudFormation :: Init资源创建为EC2实例的元数据不会导致实例自行执行任何操作。

For the instance to actually perform all the operations specified in that resource, it must run the cfn-init command line tool. On Amazon EC2 AMIs that command is already installed at /opt/aws/bin/cfn-init. The command takes several options, including the name of the AWS::CloudFormation::Init resource, the name of the EC2 server resource, and the region you are running in. You also need to provide AWS security credentials.

对于实际执行该资源中指定的所有操作的实例,它必须运行cfn-init命令行工具。在Amazon EC2 AMI上,该命令已安装在/ opt / aws / bin / cfn-init中。该命令有多个选项,包括AWS :: CloudFormation :: Init资源的名称,EC2服务器资源的名称以及您运行的区域。您还需要提供AWS安全凭证。

If you'd like this to run automatically when you create a new instance (I sure did) you'll have to use the EC2 instance's UserData to create a shell script that the instance will run on first boot, and put the cfn-init command in it.

如果您希望在创建新实例时自动运行(我确实这样做),您将必须使用EC2实例的UserData来创建实例将在首次启动时运行的shell脚本,并放入cfn-init命令在里面。

I've written about this specific issue in my blog recently.

我最近在博客中写过这个具体问题。