Cloudformation: User-data in EC2 as well as in Launch Templateunable to pass the user-data to the ec2 ubuntu instancebash causes invalid json for ec2 cli requestUnable to update .bashrc file from AWS CloudFormation scriptAWS - cfn-init not creating a fileWhy is the script in the DataUser section of my Ubuntu EC2 instance not running? I am using Cloudformationappending/prepending to userdata passed to cloudformation?Cfn-hup does not run on updating the StackFailing to create AWS EC2 instance sbin/plymouthd: No such filehow to tell cloud formation init it shall use a specific repository by installing yum packagesuser data is not running at launch aws ec2

Can a Beholder use rays in melee range?

Black-and-white film where monster/alien gets fried

How current works

What F1 in name of seeds/varieties means?

Can a non-EU citizen travel within schengen zone freely without passport?

Future enhancements for the finite element method

How to properly maintain eye contact with people that have distinct facial features?

Plot exactly N bounce of a ball

Were pen cap holes designed to prevent death by suffocation if swallowed?

Could I be denied entry into Ireland due to medical and police situations during a previous UK visit?

Terminology about G- simplicial complexes

Employer demanding to see degree after poor code review

Is a post-climate apocolypse city in which many or most insects have disappeared realistic?

Is this story about US tax office reasonable?

How do you deal with an abrupt change in personality for a protagonist?

Is CD audio quality good enough for the final delivery of music?

How do I subvert the tropes of a train heist?

Is there any use case for the bottom type as a function parameter type?

Yandex Programming Contest: Alarms

Is there an evolutionary advantage to having two heads?

Draw a checker pattern with a black X in the center

Crossing US border with music files I'm legally allowed to possess

Is there an explanation for Austria's Freedom Party virtually retaining its vote share despite recent scandal?

How does apt-get work, in detail?



Cloudformation: User-data in EC2 as well as in Launch Template


unable to pass the user-data to the ec2 ubuntu instancebash causes invalid json for ec2 cli requestUnable to update .bashrc file from AWS CloudFormation scriptAWS - cfn-init not creating a fileWhy is the script in the DataUser section of my Ubuntu EC2 instance not running? I am using Cloudformationappending/prepending to userdata passed to cloudformation?Cfn-hup does not run on updating the StackFailing to create AWS EC2 instance sbin/plymouthd: No such filehow to tell cloud formation init it shall use a specific repository by installing yum packagesuser data is not running at launch aws ec2






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















It seems like EC2 User-Data takes preference here and never executes Launch Template User-Data.
if I remove User-Data from EC2 it executes LaunchTemplate User-Data without any problem.
The AMI id being used is of CentOS 7.
How can i achieve to run both User-Data in some order.



I have already played around with cloudformation a lot and looked at forums.




"Resources":
"BSLaunchTemplate":
"Type": "AWS::EC2::LaunchTemplate",
"Properties":
"LaunchTemplateName": "BroadSoftLaunchTemplate2",
"LaunchTemplateData":
"KeyName": "haystackaccess",
"ImageId": "ami-014b38e758721be30",
"InstanceType": "t2.medium",
"SecurityGroupIds":["sg-e0b92fa7"],
"UserData":
"Fn::Base64":
"Fn::Join":["", [
"#!/bin/bash n",
"yum update -y n",
"yum –y install epel-release n",
"yum -y install python-pip n",
"pip install pystache n",
"pip install argparse n",
"pip install python-daemon n",
"pip install requests n",
"yum install -y https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-latest.amzn1.noarch.rpm n",
"echo UD_OF_LT_1 >> /var/log/user-data.log n",
"echo UD_OF_LT_2 >> /var/log/user-data.log n",
"echo UD_OF_Lt_3 >> /var/log/user-data.log n"
]
]




,
"primaryec2":
"Type": "AWS::EC2::Instance",
"Properties":
"LaunchTemplate":
"LaunchTemplateId":"Ref":"BSLaunchTemplate",
"Version":"1",
,
"Tags": [

"Key": "Name",
"Value": "Network Server"
],
"UserData":
"Fn::Base64":
"Fn::Join": ["",[
"#!/bin/bash n",
"echo UD_OF_EC2_1 >> /var/log/user-data.log n",
"echo UD_OF_EC2_2 >> /var/log/user-data.log n",
"echo UD_OF_EC2_3 >> /var/log/user-data.log n"
]
]

















share|improve this question




























    0















    It seems like EC2 User-Data takes preference here and never executes Launch Template User-Data.
    if I remove User-Data from EC2 it executes LaunchTemplate User-Data without any problem.
    The AMI id being used is of CentOS 7.
    How can i achieve to run both User-Data in some order.



    I have already played around with cloudformation a lot and looked at forums.




    "Resources":
    "BSLaunchTemplate":
    "Type": "AWS::EC2::LaunchTemplate",
    "Properties":
    "LaunchTemplateName": "BroadSoftLaunchTemplate2",
    "LaunchTemplateData":
    "KeyName": "haystackaccess",
    "ImageId": "ami-014b38e758721be30",
    "InstanceType": "t2.medium",
    "SecurityGroupIds":["sg-e0b92fa7"],
    "UserData":
    "Fn::Base64":
    "Fn::Join":["", [
    "#!/bin/bash n",
    "yum update -y n",
    "yum –y install epel-release n",
    "yum -y install python-pip n",
    "pip install pystache n",
    "pip install argparse n",
    "pip install python-daemon n",
    "pip install requests n",
    "yum install -y https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-latest.amzn1.noarch.rpm n",
    "echo UD_OF_LT_1 >> /var/log/user-data.log n",
    "echo UD_OF_LT_2 >> /var/log/user-data.log n",
    "echo UD_OF_Lt_3 >> /var/log/user-data.log n"
    ]
    ]




    ,
    "primaryec2":
    "Type": "AWS::EC2::Instance",
    "Properties":
    "LaunchTemplate":
    "LaunchTemplateId":"Ref":"BSLaunchTemplate",
    "Version":"1",
    ,
    "Tags": [

    "Key": "Name",
    "Value": "Network Server"
    ],
    "UserData":
    "Fn::Base64":
    "Fn::Join": ["",[
    "#!/bin/bash n",
    "echo UD_OF_EC2_1 >> /var/log/user-data.log n",
    "echo UD_OF_EC2_2 >> /var/log/user-data.log n",
    "echo UD_OF_EC2_3 >> /var/log/user-data.log n"
    ]
    ]

















    share|improve this question
























      0












      0








      0








      It seems like EC2 User-Data takes preference here and never executes Launch Template User-Data.
      if I remove User-Data from EC2 it executes LaunchTemplate User-Data without any problem.
      The AMI id being used is of CentOS 7.
      How can i achieve to run both User-Data in some order.



      I have already played around with cloudformation a lot and looked at forums.




      "Resources":
      "BSLaunchTemplate":
      "Type": "AWS::EC2::LaunchTemplate",
      "Properties":
      "LaunchTemplateName": "BroadSoftLaunchTemplate2",
      "LaunchTemplateData":
      "KeyName": "haystackaccess",
      "ImageId": "ami-014b38e758721be30",
      "InstanceType": "t2.medium",
      "SecurityGroupIds":["sg-e0b92fa7"],
      "UserData":
      "Fn::Base64":
      "Fn::Join":["", [
      "#!/bin/bash n",
      "yum update -y n",
      "yum –y install epel-release n",
      "yum -y install python-pip n",
      "pip install pystache n",
      "pip install argparse n",
      "pip install python-daemon n",
      "pip install requests n",
      "yum install -y https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-latest.amzn1.noarch.rpm n",
      "echo UD_OF_LT_1 >> /var/log/user-data.log n",
      "echo UD_OF_LT_2 >> /var/log/user-data.log n",
      "echo UD_OF_Lt_3 >> /var/log/user-data.log n"
      ]
      ]




      ,
      "primaryec2":
      "Type": "AWS::EC2::Instance",
      "Properties":
      "LaunchTemplate":
      "LaunchTemplateId":"Ref":"BSLaunchTemplate",
      "Version":"1",
      ,
      "Tags": [

      "Key": "Name",
      "Value": "Network Server"
      ],
      "UserData":
      "Fn::Base64":
      "Fn::Join": ["",[
      "#!/bin/bash n",
      "echo UD_OF_EC2_1 >> /var/log/user-data.log n",
      "echo UD_OF_EC2_2 >> /var/log/user-data.log n",
      "echo UD_OF_EC2_3 >> /var/log/user-data.log n"
      ]
      ]

















      share|improve this question














      It seems like EC2 User-Data takes preference here and never executes Launch Template User-Data.
      if I remove User-Data from EC2 it executes LaunchTemplate User-Data without any problem.
      The AMI id being used is of CentOS 7.
      How can i achieve to run both User-Data in some order.



      I have already played around with cloudformation a lot and looked at forums.




      "Resources":
      "BSLaunchTemplate":
      "Type": "AWS::EC2::LaunchTemplate",
      "Properties":
      "LaunchTemplateName": "BroadSoftLaunchTemplate2",
      "LaunchTemplateData":
      "KeyName": "haystackaccess",
      "ImageId": "ami-014b38e758721be30",
      "InstanceType": "t2.medium",
      "SecurityGroupIds":["sg-e0b92fa7"],
      "UserData":
      "Fn::Base64":
      "Fn::Join":["", [
      "#!/bin/bash n",
      "yum update -y n",
      "yum –y install epel-release n",
      "yum -y install python-pip n",
      "pip install pystache n",
      "pip install argparse n",
      "pip install python-daemon n",
      "pip install requests n",
      "yum install -y https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-latest.amzn1.noarch.rpm n",
      "echo UD_OF_LT_1 >> /var/log/user-data.log n",
      "echo UD_OF_LT_2 >> /var/log/user-data.log n",
      "echo UD_OF_Lt_3 >> /var/log/user-data.log n"
      ]
      ]




      ,
      "primaryec2":
      "Type": "AWS::EC2::Instance",
      "Properties":
      "LaunchTemplate":
      "LaunchTemplateId":"Ref":"BSLaunchTemplate",
      "Version":"1",
      ,
      "Tags": [

      "Key": "Name",
      "Value": "Network Server"
      ],
      "UserData":
      "Fn::Base64":
      "Fn::Join": ["",[
      "#!/bin/bash n",
      "echo UD_OF_EC2_1 >> /var/log/user-data.log n",
      "echo UD_OF_EC2_2 >> /var/log/user-data.log n",
      "echo UD_OF_EC2_3 >> /var/log/user-data.log n"
      ]
      ]














      amazon-web-services amazon-cloudformation






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 24 at 8:44









      Adarsh ChauhanAdarsh Chauhan

      83




      83






















          1 Answer
          1






          active

          oldest

          votes


















          0














          What's the purpose of the primary ec2 instance? I guess you need to run the extra commands on the primary. I mean you could just duplicate the commands - putting them into external bash files might make life a bit easier there. Or create an AMI with the commands you used in the launch template and then use your custom AMI in the primary instance. You might be able to do something with conditionals too, but I think you'd have to be a bit more creative with that since I don't think you can use them directly in the user data itself.



          Tim






          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55322035%2fcloudformation-user-data-in-ec2-as-well-as-in-launch-template%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            What's the purpose of the primary ec2 instance? I guess you need to run the extra commands on the primary. I mean you could just duplicate the commands - putting them into external bash files might make life a bit easier there. Or create an AMI with the commands you used in the launch template and then use your custom AMI in the primary instance. You might be able to do something with conditionals too, but I think you'd have to be a bit more creative with that since I don't think you can use them directly in the user data itself.



            Tim






            share|improve this answer



























              0














              What's the purpose of the primary ec2 instance? I guess you need to run the extra commands on the primary. I mean you could just duplicate the commands - putting them into external bash files might make life a bit easier there. Or create an AMI with the commands you used in the launch template and then use your custom AMI in the primary instance. You might be able to do something with conditionals too, but I think you'd have to be a bit more creative with that since I don't think you can use them directly in the user data itself.



              Tim






              share|improve this answer

























                0












                0








                0







                What's the purpose of the primary ec2 instance? I guess you need to run the extra commands on the primary. I mean you could just duplicate the commands - putting them into external bash files might make life a bit easier there. Or create an AMI with the commands you used in the launch template and then use your custom AMI in the primary instance. You might be able to do something with conditionals too, but I think you'd have to be a bit more creative with that since I don't think you can use them directly in the user data itself.



                Tim






                share|improve this answer













                What's the purpose of the primary ec2 instance? I guess you need to run the extra commands on the primary. I mean you could just duplicate the commands - putting them into external bash files might make life a bit easier there. Or create an AMI with the commands you used in the launch template and then use your custom AMI in the primary instance. You might be able to do something with conditionals too, but I think you'd have to be a bit more creative with that since I don't think you can use them directly in the user data itself.



                Tim







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Mar 24 at 21:22









                timdtimd

                164




                164



























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55322035%2fcloudformation-user-data-in-ec2-as-well-as-in-launch-template%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                    SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

                    은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현