gpt4 book ai didi

amazon-web-services - AWS Cloudformation : Order of Execution among ConfigSets, 用户数据,云初始化

转载 作者:行者123 更新时间:2023-12-03 07:14:14 25 4
gpt4 key购买 nike

我创建了一个模板,在其中创建了 EC2 实例,并使用 cfn-init 来处理配置集,在实例的 Userdata 部分中,我编写了一些由 cloud-init 执行的命令和一些要执行的命令没有云初始化。

我不确定哪些命令按哪个顺序运行?我的意思是,命令执行的顺序是什么?例如:

  1. 配置集中的命令
  2. 用户数据的 cloud-init 部分中的命令
  3. 用户数据中的命令

我的部分代码如下:

UserData:
Fn::If:
- DatadogAgentEnabled
-
Fn::Base64: !Sub |
#!/bin/bash -xe
yum update -y
yum update -y aws-cfn-bootstrap
/opt/aws/bin/cfn-init --stack ${AWS::StackName} --resource GhostServer --configsets prepare_instance_with_datadog --region ${AWS::Region}
/opt/aws/bin/cfn-signal -e $? --stack ${AWS::StackName} --resource GhostServer --region ${AWS::Region}

#cloud-config <----cloud-init section inside the Userdata
runcmd:
- [ sh, -c, "sed 's/api_key:.*/api_key: {DatadogAPIKey}/' /etc/datadog-agent/datadog.yaml.example > /etc/datadog-agent/datadog.yaml" ]
- systemctl restart datadog-agent

最佳答案

来自 AWS 文档

UserData :The user data to make available to the instance. For moreinformation, see Running commands on your Linux instance at launch(Linux) and Adding User Data (Windows). If you are using a commandline tool, base64-encoding is performed for you, and you can load thetext from a file. Otherwise, you must provide base64-encoded text.User data is limited to 16 KB.

因此,基本上我们定义 UserData 来在启动 EC2 实例时执行一些命令。

引用:https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ec2-instance.html

要回答您的问题,首先将执行所有 UserData 命令,并且本节中指定的所有命令将按顺序执行,因此在您的示例中,您首先调用 cfn 帮助程序脚本,然后调用 cloud init,因此 configsets 将首先应用,然后调用云初始化命令。

UserData 部分中,我们调用 cfn 帮助程序脚本,该脚本读取 cloudformation 模板元数据并执行 AWS::CloudFormation::Init 下定义的所有 configsets:

来自 AWS 文档:

The cfn-init helper script reads template metadata from theAWS::CloudFormation::Init key and acts accordingly to:

Fetch and parse metadata from AWS CloudFormation

Install packages

Write files to disk

Enable/disable and start/stop services

引用:https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/cfn-init.html

关于amazon-web-services - AWS Cloudformation : Order of Execution among ConfigSets, 用户数据,云初始化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65842527/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com