【问题标题】:AWS CloudFormation - Ubuntu Nginx MetadataAWS CloudFormation - Ubuntu Nginx 元数据
【发布时间】:2018-03-12 23:49:54
【问题描述】:

所以我是 CloudFormation 的新手,我正在尝试使用 Nginx 创建一个 index.html 页面,该页面显示一行文本、服务器的公共 DNS 名称和 AWS 区域。我在 YAML 中做我的堆栈代码。这是 UserData 下代码的一部分:

sudo apt-get update
sudo apt-get install -y nginx
sudo service nginx start
cd /var/www/html
echo "<title>CloudFormation</title><h1>Name</h1><p>This page created entirely by CloudFormation</p>" > index.html

我不知道如何使用 echo 命令将元数据传递到 index.html。我试过!Sub {EC2Instance.PublicDnsName},但没用。显然方法是使用 Amazon Metadata Web Service 并使用某些命令获取值,然后将它们传递到 index.html 但由于我在堆栈中编码而不使用控制台,所以我不知道语法。有没有人指点一下?

【问题讨论】:

    标签: amazon-web-services nginx yaml metadata amazon-cloudformation


    【解决方案1】:

    对不起,我的代码太长了,所以我不能发表评论。 我不使用 yaml,但我可以在 json 中执行您预期的代码,如下所示。我使用Fn::Base64Fn::join 语法。你可以引用它并迁移到yaml。

    "UserData": {
      "Fn::Base64": {
        "Fn::Join": [
          "",
          [
            "#!/bin/bash",
            "\n",
            "sudo apt-get update\n",
            "sudo apt-get install -y nginx\n",
            "sudo service nginx start\n",
            "\n",
            "cat > /var/www/html/index.html << \"EOF\"\n",
            "<title>CloudFormation</title>\n",
            "<h1>Name</h1><p>This page created entirely by CloudFormation. Author: ",
            {
              "Ref": "Author_name_in_parameter"
            },
            "</p>\n",
            "EOF\n",
            "\n"
          ]
        ]
      }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-06-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多