title: Running a shell script in CloudFormation cfn-init
body: <p>I am trying to run a script in the cfn-init command but it keeps timing out.
  What am I doing wrong when running the startup-script.sh?</p>
  
  <pre><code>"WebServerInstance" : {
        "Type" : "AWS::EC2::Instance",
        "DependsOn" : "AttachGateway",
        "Metadata" : {
          "Comment" : "Install a simple application",
          "AWS::CloudFormation::Init" : {
            "config" : {
              "files": {
                "/home/ec2-user/startup_script.sh": {
                  "content": {
                    "Fn::Join": [
                      "",
                      [
                        "#!/bin/bash\n",
                        "aws s3 cp s3://server-assets/startserver.jar . --region=ap-northeast-1\n",
                        "aws s3 cp s3://server-assets/site-home-sprint2.jar . --region=ap-northeast-1\n",
                        "java -jar startserver.jar\n",
                        "java -jar site-home-sprint2.jar --spring.datasource.password=`&lt; password.txt` --spring.datasource.username=`&lt; username.txt` --spring.datasource.url=`&lt;db_url.txt`\n"
                      ]
                    ]
                  },
                  "mode": "000755"
                }
              },
              "commands": {
                "start_server": {
                  "command": "./startup_script.sh",
                  "cwd": "~",
                }
              }
            }
          }
        },
  </code></pre>
  
  <p>The file part works fine and it creates the file but it times out at running the command. 
  What is the correct way of executing a shell script?</p>