AWS Cloudformation中UserData中的参考参数值 [英] Reference Parameter Value in UserData in AWS Cloudformation

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

问题描述

我在参数部分下有这个,

I have this under parameter section ,

Parameters:
  PlatformSelect:
    Description: Cockpit platform Select.
    Type: String
    Default: qa-1
    AllowedValues: [qa-1, qa-2, staging, production]

我需要在UserData中引用此值。我在两者之间使用映射。

I need to reference this value in my UserData. I’m using Mappings in between.

Mappings:
  bootstrap:
    ubuntu:
      print: echo ${PlatformSelect} >>test.txt

Resources:
  EC2Instance:
    Type: AWS::EC2::Instance
    Properties:
      InstanceType: !Ref ‘InstanceType’
      KeyName: !Ref ‘KeyName’
      Tags:
      - Key: Name
        Value: Test
      UserData:
        Fn::Base64:
          Fn::Join:
          - ‘’
          - - |
              #!/bin/bash
            - Fn::FindInMap:
              - bootstrap
              - ubuntu
              - print
            - |2+

这不起作用。不确定我首先提到的方式是错误的!

This is not working. Not sure the way I refer it is wrong in first place!!

我应该在它之前使用一些东西,例如'$ {AWS :: Parameters:PlatformSelect}'吗?

Should I use something before it like, ‘${AWS::Parameters:PlatformSelect}’ ?

推荐答案

您是否有理由在两者之间使用 Mapping

Is there a reason why you are using Mapping in between?

您可以轻松使用 !Sub 代替

You could easily use !Sub instead

Resources:
  EC2Instance:
    Type: AWS::EC2::Instance
    Properties:
      InstanceType: !Ref InstanceType
      KeyName: !Ref KeyName
      Tags:
        - Key: Name
          Value: Test
      UserData:
        Fn::Base64:
          !Sub |
            #!/bin/bash
            ${PlatformSelect}

这篇关于AWS Cloudformation中UserData中的参考参数值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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