Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reference Parameter Value in UserData in AWS Cloudformation

I have this under parameter section ,

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

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!!

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

like image 503
Vineeth Avatar asked Dec 06 '25 08:12

Vineeth


1 Answers

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

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}
like image 168
MaiKaY Avatar answered Dec 08 '25 22:12

MaiKaY



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!