gpt4 book ai didi

amazon-web-services - Userdata Cloudformation 中资源的引用 ID

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

我正在编写 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

UserData script with Resource Attribute CloudFormation我正在关注此链接,但它仍然不起作用当新实例启动时。/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 文件。

附注

以下也是不正确的:

{LogstashVolume: Ref: LogstashVolume}

这不是一个有效的 bash 命令。

关于amazon-web-services - Userdata Cloudformation 中资源的引用 ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63388007/

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