[英]Reference ID of resource in Userdata Cloudformation
我正在編寫 YAML 格式的 cloudformation 模板。 現在我堅持將 ebs 卷的 id 附加到 ec2 用戶數據。
Type: AWS::EC2::Volume
Properties:
Size: 50
AvailabilityZone: ap-southeast-1b
Tags:
- Key: Name
Value: Logstash Volume
LogStashMountPoint:
Type: AWS::EC2::VolumeAttachment
Properties:
InstanceId:
Ref: LogstashInstance
VolumeId:
Ref: LogstashVolume
Device: "/dev/xvdf"
LogstashInstance:
Type: AWS::EC2::Instance
Properties:
IamInstanceProfile:
Ref: LogstashInstanceProfile
InstanceType: t2.micro
KeyName: chuongtest
ImageId: ami-0cd31be676780afa7
UserData:
Fn::Base64:
Fn::Sub:
- |
#!/bin/bash -xe
echo ${LogstashVolume} >> /home/ec2-user/ebsid.txt
{LogstashVolume: Ref: LogstashVolume}
touch /home/ec2-user/ebscomplete.txt
curl "http://169.254.169.254/latest/meta-data/instance-id" >> /home/ec2-user/ec2id.txt
touch /home/ec2-user/ec2complete.txt
touch /home/ec2-user/complete.txt
- LogstashVolume: !Ref LogstashVolume
SecurityGroupIds:
- Ref: LogstashSecurityGroup
SubnetId: subnet-0d0e0989f57b96389
Tags:
- Key: Name
Value: Logstash Instance
具有資源屬性 CloudFormation 的 UserData 腳本我正在關注此鏈接,但在啟動新實例時它仍然不起作用。 它在 /home/ec2-user 中沒有任何內容。 我到處看了看,這是我的最終結果,但沒有用有人可以幫我嗎?
您的UserData
中至少存在一個語法錯誤:
echo ${LogstashVolume}) >> /home/ec2-user/ebsid.txt
應該
echo ${LogstashVolume} >> /home/ec2-user/ebsid.txt
要進一步調試您的UserData
,請登錄到實例並檢查/var/log/could-init-output.log
文件。
ps
以下也是不正確的:
{LogstashVolume: Ref: LogstashVolume}
它不是有效的 bash 命令。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.