【发布时间】:2020-08-17 16:05:28
【问题描述】:
我想将我的 Instances UserData 更改为 MetaData:->AWS::CloudFormation::Init:->files:->content。
我的困难在于我现有的 UserData Bash 脚本,因为它有变量,我想在 cfn-init 文件 content 部分中包含变量。
这是现有的 UserData,它是我要传输到 cfn-init 的最后 6 行。 content 部分如何使用变量?
UserData:
Fn::Base64: |
#!/bin/bash -xe
yum update -y
yum install -y httpd
systemctl start httpd
systemctl enable httpd
ID=`curl -s http://169.254.169.254/latest/meta-data/instance-id`
AVAIL_ZONE=`curl -s http://169.254.169.254/latest/meta-data/placement/availability-zone`
REGION=`curl http://169.254.169.254/latest/dynamic/instance-identity/document|grep region|awk -F\" '{print $4}'`
echo "This is Server * $ID * in AWS Region $REGION in AZ $AVAIL_ZONE<br>" > /var/www/html/index.html
EC2_AVAIL_ZONE=$(curl -s http://169.254.169.254/latest/meta-data/placement/availability-zone)
echo "<h1>Hello World from $(hostname -f) in AZ $EC2_AVAIL_ZONE </h1><br>" >> /var/www/html/index.html
【问题讨论】:
标签: amazon-web-services amazon-cloudformation