AWS - cfn-init not creating a file
<p>I am new to cloudformation.
I am using cfn-init to create a file. But doesnt create a file nor my stack fails. Stack successfully gets created with required resources like EC2 instance. Also it installs AWS CLI as mentioned in User data.
But it just does not create file i wish to create.
I tried using Advanced options of not allowing rollback of stack. But the /var/log/cfn-init.log does not get created.
See the template below? Am I doing anything wrong in this?</p>

<pre><code>{
  "Parameters" : {
    "KeyName" : {
      "Description" : "The EC2 Key Pair to allow SSH access to the instance",
      "Type" : "AWS::EC2::KeyPair::KeyName"
    }
  },
  "Resources" : {
    "Ec2Instance" : {
      "Type" : "AWS::EC2::Instance",
      "Metadata" : {
        "Comment" : "Install a simple application",
        "AWS::CloudFormation::Init" : {
          "config" : {
          "files" : {
              "/tmp/setup.mysql" : {
                "content" : { "Fn::Join" : ["", ["[default]\n","region=",{"Ref": "AWS::Region"}]]},
                "mode"    : "000775",
                "owner"   : "ec2-user",
                "group"   : "ec2-user"
              }       
          }
          }
          } },

      "Properties" : {
        "SecurityGroups" : [ { 
                "Ref" : "InstanceSecurityGroup" } 
                ],
        "IamInstanceProfile" : {"Ref" : "RootInstanceProfile"} ,
        "KeyName" : { "Ref" : "KeyName"},
        "InstanceType" : "t2.micro",
        "ImageId" : "ami-58277d3d",
        "UserData": {
                    "Fn::Base64": {
                        "Fn::Join": [
                            "",
                            [
                                "curl https://s3.amazonaws.com/aws-cli/awscli-bundle.zip -o awscli-bundle.zip\n",
                                "unzip awscli-bundle.zip\n",
                                "sudo ./awscli-bundle/install -i /usr/local/aws -b /usr/local/bin/aws\n",
                                "/opt/aws/bin/cfn-init -v ",
                                 "         --stack ", { "Ref" : "AWS::StackName" },
                                 "         --resource Ec2Instance ",
                                 "         --region ", { "Ref" : "AWS::Region" }, "\n",
                                "cfn-signal -e 0",
                                " --stack ",
                                {
                                    "Ref": "AWS::StackName"
                                },
                                " --region ",
                                {
                                    "Ref": "AWS::Region"
                                },
                                " --resource ",
                                "Ec2Instance",
                                "\n"
                            ]
                        ]
                    }
                }
      }
    },


      "RootRole": {
         "Type": "AWS::IAM::Role",
         "Properties": {
            "AssumeRolePolicyDocument": {
               "Version" : "2012-10-17",
               "Statement": [ {
                  "Effect": "Allow",
                  "Principal": {
                     "Service": [ "ec2.amazonaws.com" ]
                  },
                  "Action": [ "sts:AssumeRole" ]
               } ]
            },
            "Path": "/",
            "Policies": [ {
               "PolicyName": "root",
               "PolicyDocument": {
                  "Version" : "2012-10-17",
                  "Statement": [ {
                     "Effect": "Allow",
                     "Action": ["cloudwatch:PutMetricData"],
                     "Resource": "*"
                  } ]
               }
               } ]
            }
      },
      "RootInstanceProfile": {
         "Type": "AWS::IAM::InstanceProfile",
         "Properties": {
            "Path": "/",
            "Roles": [ {
               "Ref": "RootRole"
            } ]
         }
      },



    "InstanceSecurityGroup" : {
      "Type" : "AWS::EC2::SecurityGroup",
      "Properties" : {
        "GroupDescription" : "Enable SSH access via port 22",
        "Tags" : [{  "Key" : "Name",  "Value" : "SecurityGr_EC2WithParam" }],
        "SecurityGroupIngress" : [ {
          "IpProtocol" : "tcp",
          "FromPort" : "22",
          "ToPort" : "22",
          "CidrIp" : "0.0.0.0/0"
        } ]
      }
    }
  }
} 
</code></pre>