Skip to content

User data with !FindInMap [RegionMap, !Ref "AWS::Region", URL]

0

Hello,

I'm trying to refer to a URL based on the Region map, but I'm not sure what I'm doing wrong here. I want to refer the URL parameter from the region map into the user data. This is under a launch template. Can anyone please guide of what's the correct syntax to do this?

    ap-southeast-2:
      AMI: "ami-12134"
      URL: "https://aws-codedeploy-ap-southeast-2.s3.amazonaws.com/latest/install"
        UserData:
          'Fn::Base64': >
            #!/bin/bash

            # SSM

            cd /tmp

            apt-get update -y

            wget
            https://s3.amazonaws.com/ec2-downloads-windows/SSMAgent/latest/debian_amd64/amazon-ssm-agent.deb

            dpkg -i amazon-ssm-agent.deb

            # Codedploy

            apt-get install ruby2.0 -y

            curl -O {URL}
            - URL: !FindInMap [RegionMap, !Ref "AWS::Region", URL]

            chmod +x ./install

            ./install auto

            apt install uuid -y
asked 3 years ago840 views
1 Answer
0

The snippets you've provided are a bit small and lacking context so I'm making some guesses here.

Your first snippet is part of a mapping called RegionMap, right?

You need the !FindInMap to resolve while CloudFormation is executing. Right now it's just treated as plain text in your UserData. So do something like:

UserData:
  Fn::Base64: !Sub
    - |
           #!/bin/bash
           ...
           curl -O ${UrlSubParam}
           ...
    - UrlSubParam: !FindInMap [RegionMap, !Ref "AWS::Region", URL]
EXPERT
answered 3 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.