bash 在 Cloudformation 中使用用户数据
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/48197526/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Using userdata in Cloudformation
提问by mitechniq
I am trying to add some simple bash commands in my userdata but it looks like they do not run?
我正在尝试在我的用户数据中添加一些简单的 bash 命令,但看起来它们没有运行?
AWSTemplateFormatVersion: '2010-09-09'
Resources:
RHELInstance:
Type: AWS::EC2::Instance
Properties:
IamInstanceProfile: Super-Agent
ImageId: ami-26ebbc5c
KeyName: Super-Agent
InstanceType: m4.large
SecurityGroupIds:
- sg-XXXXXX
SubnetId: subnet-XXXXXXX
BlockDeviceMappings:
-
DeviceName: "/dev/sda1"
Ebs:
VolumeSize: 24
VolumeType: gp2
UserData:
Fn::Base64:
!Sub |
#!/bin/bash -xe
yum update -y
cd /tmp
wget https://s3.amazonaws.com/ec2-downloads-windows/SSMAgent/latest/debian_amd64/amazon-ssm-agent.deb
sudo dpkg -i amazon-ssm-agent.deb
sudo start amazon-ssm-agent
mkdir /tmp/folder/
Tags:
- Key: Name
Value: RHEL07102.00
Outputs: PrivateIP: Value: !GetAtt RHELInstance.PrivateIp
输出:PrivateIP:值:!GetAtt RHELInstance.PrivateIp
回答by John Rotenstein
You are using ami-26ebbc5c
, which is RHEL-7.4_HVM-20180103-x86_64-2-Hourly2-GP2.
您正在使用ami-26ebbc5c
,即RHEL-7.4_HVM-20180103-x86_64-2-Hourly2-GP2。
Most likely (but I could be wrong), cloud-init (which processes the User Data) is not installed on this AMI. As a result, nothing is looking at the User Data.
很可能(但我可能是错的),此 AMI 上未安装 cloud-init(处理用户数据)。因此,没有任何内容查看用户数据。
You could install cloud-init with:
您可以使用以下命令安装 cloud-init:
yum install cloud-init
However, this would have to be done manually, and then a new AMI generated.
但是,这必须手动完成,然后生成新的 AMI。
Alternatively, you could use Amazon Linux or Ubuntu, both of which have cloud-init installed by default.
或者,您可以使用 Amazon Linux 或 Ubuntu,它们都默认安装了 cloud-init。