在Cloudformation中使用用户数据 [英] Using userdata in Cloudformation

查看:78
本文介绍了在Cloudformation中使用用户数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在用户数据中添加一些简单的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

输出: 专用IP: 值:!GetAtt RHELInstance.PrivateIp

解决方案

您正在使用ami-26ebbc5c,它是 RHEL-7.4_HVM-20180103-x86_64-2-Hourly2-GP2 .. >

很可能(但我可能错了),此AMI上未安装cloud-init(用于处理用户数据).结果,什么也看不到用户数据.

您可以使用以下命令安装cloud-init:

yum install cloud-init

但是,这必须手动完成,然后生成一个新的AMI.

或者,您可以使用Amazon Linux或Ubuntu,它们默认都安装了cloud-init.

I am trying to add some simple bash commands in my userdata but it looks like they do not run?

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

解决方案

You are using ami-26ebbc5c, which is 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.

You could install cloud-init with:

yum install cloud-init

However, this would have to be done manually, and then a new AMI generated.

Alternatively, you could use Amazon Linux or Ubuntu, both of which have cloud-init installed by default.

这篇关于在Cloudformation中使用用户数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆