How do I pass UserData to a Beanstalk instance with CloudFormation

泄露秘密 提交于 2019-12-08 22:00:56

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/8412231/how-do-i-pass-userdata-to-a-beanstalk-instance-with-cloudformation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!