Using userdata in Cloudformation

纵饮孤独 提交于 2020-07-06 09:54:21

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/48197526/using-userdata-in-cloudformation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!