Question

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.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top