在UserData块的脚本内传递逗号分隔的参数

时间:2019-06-20 11:35:29

标签: amazon-web-services amazon-ec2 amazon-cloudformation

我在CloudFormation模板中有commadelimited参数:

Parameters:  
  BlockDevices:
    Type: CommaDelimitedList
    Description: Comma Delimited size for sda1 and sdb on NFS server
    Default: 90, 100

稍后在Ec2Instance中,我可以在参考资料部分中引用此参数:

Resources:
  Ec2Instance:
    Type: 'AWS::EC2::Instance'
    Properties:
      BlockDeviceMappings: 
        -
          DeviceName: "/dev/sda1"
          Ebs:
            VolumeSize: !Select [0, !Ref BlockDevices]
            VolumeType: gp2
            Encrypted: true
        -  
          DeviceName: "/dev/sdb"
          Ebs:
            VolumeSize: !Select [1, !Ref BlockDevices]
            VolumeType: gp2
            Encrypted: true

问题:如何在我的Shell脚本主体中的Userdata块中引用此commadelimited参数?

我需要类似的东西:

UserData:          
        Fn::Base64: 
          !Sub |
            #!/bin/bash -xe
            echo ${!Select [0, !Ref BlockDevices]}

但是我收到Ec2实例上的/var/log/cloud-init-output.log中的错误:

$ {选择[0,!Ref BlockDevices]}:替换错误

0 个答案:

没有答案