title: Setting SSM parameter as an Environment variable for EC2 - Does not work
body: <p>I am trying to get and export an SSM parameter as an environment variable to an EC2 using the <code>UserData</code> section of Cloudformation. </p>
  
  <p>The script is trying to append for e.g <code>export WHATS_HER_NAME=Sherlyn</code> to the <code>/etc/profile</code> file. But all i see in the <code>/etc/profile</code> is <code>export WHATS_HER_NAME=</code>. The value is not present. I use amazon linux 2 ami.</p>
  
  <p>here is my cloudformation template.</p>
  
  <pre><code>{
    "AWSTemplateFormatVersion": "2010-09-09",
    "Resources": {
      "Ec2Instance": {
        "Type": "AWS::EC2::Instance",
        "Properties": {
          "IamInstanceProfile": {
            "Ref": "Ec2instanceProfileTest"
          },
          "UserData": {
            "Fn::Base64": {
              "Fn::Join": [
                "\n",
                [
                  "#!/bin/bash -xe",
                  "yum update -y aws-cfn-bootstrap",
                  {
                    "Fn::Sub": "/opt/aws/bin/cfn-init -v --stack ${AWS::StackName} --resource Ec2Instance --configsets default --region ${AWS::Region}"
                  },
                  {
                    "Fn::Sub": "/opt/aws/bin/cfn-signal -e $? --stack ${AWS::StackName} --resource EC2Instance --region ${AWS::Region}"
                  },
                  {
                    "Fn::Sub": "echo \"export WHATS_HER_NAME=$(aws ssm get-parameter --name WhatsHerName --region ${AWS::Region} --query 'Parameter.Value')\" &gt;&gt; /etc/profile"
                  }
                ]
              ]
            }
          }
        }
      },
      "GetSSMParameterPolicy": {
        "Type": "AWS::IAM::Policy",
        "Properties": {
          "PolicyName": "GetSsmProperty",
          "PolicyDocument": {
            "Statement": [
              {
                "Effect": "Allow",
                "Resource": "arn:aws:ssm:ap-southeast-2:012345678901:parameter/WhatsHerName",
                "Action": [
                  "ssm:GetParameters",
                  "ssm:GetParameter"
                ]
              },
              {
                "Effect": "Allow",
                "Resource": "*",
                "Action": [
                  "ssm:DescribeParameters"
                ]
              }
            ]
          },
          "Roles": [
            {
              "Ref": "InstanceRole"
            }
          ]
        }
      },
      "InstanceRole": {
        "Type": "AWS::IAM::Role",
        "Properties": {
          "AssumeRolePolicyDocument": {
            "Version": "2012-10-17",
            "Statement": [
              {
                "Effect": "Allow",
                "Principal": {
                  "Service": [
                    "ec2.amazonaws.com"
                  ]
                },
                "Action": [
                  "sts:AssumeRole"
                ]
              }
            ]
          },
          "Path": "/"
        }
      },
      "BasicParameter": {
        "Type": "AWS::SSM::Parameter",
        "Properties": {
          "Name": "WhatsHerName",
          "Type": "String",
          "Value": "Sherlyn"
        }
      }
    }
  }
  </code></pre>
  
  <p>any help would be highly appreciated.</p>