Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I pass UserData to a Beanstalk instance with CloudFormation

I need the application server, which is beanstalk instances, to do some actions upon startup and I thought of running a bash script passed to the instance with the UserData property which is available to regular EC2 instances.

I've found several example CloudFormation templates which does this with regular EC2 instances, but no example with Beanstalk. I've tried to add this to the properties field for the application:

"MyApp" : {
  "Type" : "AWS::ElasticBeanstalk::Application",
  "Properties" : {
    "Description" : "MyApp description",
    "ApplicationVersions" : [{
      ...
    }],
    "UserData" : {
      "Fn::Base64" : { "Fn::Join" : ["", [
        "#!/bin/bash\n",
        "touch /tmp/userdata_sucess\n"
      ]]
    }},
    ...

I also tried to add to the environment part:

"MyAppEnv" : {
  "Type" : "AWS::ElasticBeanstalk::Environment",
  "Properties" : {
    "ApplicationName" : { "Ref" : "MyApp" },
    "Description" :  "MyApp environment description",
    "UserData" : {
      "Fn::Base64" : { "Fn::Join" : ["", [
        "#!/bin/bash\n",
        "touch /tmp/userdata_sucess\n"
      ]]
    }},
    "TemplateName" : "MyAppConfiguration",
    "VersionLabel" : "First Cloud version"
  }
},

In both cases this resulted in failure when trying to create the stack. Does anyone know if it is possible to pass UserData to a Beanstalk instance using CloudFormation. If so - can you provide an example.

like image 523
tronda Avatar asked Dec 07 '11 08:12

tronda


1 Answers

If you want to have all the advantages that Beanstalk offers - like not having to patch the OS which Amazon does for you - this isn't possible. One option is to create a custom AMI where you include the needed scripts, but then you must manage the OS yourself with security patches. Read more here.

like image 173
tronda Avatar answered Oct 15 '22 00:10

tronda