0

CloudFormationの新機能で、テキスト行、サーバーの公開DNS名、およびAWS領域を表示するNginxを使用してindex.htmlページを作成しようとしています。私はYAMLで私のスタックコードをやっています。私はechoコマンドでのindex.htmlにメタデータを渡す方法がわからないAWS CloudFormation - Ubuntu Nginxメタデータ

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 

:これはUserDataの下のコードの一部です。私は!Sub {EC2Instance.PublicDnsName}を試しましたが動作しませんでした。どうやら、AmazonメタデータWebサービスを使用して特定のコマンドを使用して値を取得し、index.htmlに渡しているようですが、スタックでコーディングしていてコンソールを使用していないため、構文がわかりません。誰でも何か指針がありますか?

答えて

0

申し訳ありませんが、私のコードは長すぎますので、コメントに投稿できません。 私は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" 
     ] 
    ] 
    } 
} 
関連する問題