Passing a script while starting an instance in Amazon EC2

0 votes

Is it possible to pass a script while starting an instance? Well, I want the script to be executed once the instance is initialized.

Any idea? The script will be kind of beginner script which I need to execute as soon as the instance is ready. Thanks in advance.

Mar 25, 2019 in AWS by datageek
• 3,090 points
859 views

1 answer to this question.

0 votes

Use the user data to pass a script to a new EC2 Instance. I am not sure if you can start a pre-existing instance and pass it data.

I have a pre-configured AMI that has a script saved on the root drive.  This script is used to configure the server and download the latest source.

So your request could look like the following:

var runInstance = new RunInstancesRequest();

        runInstance.WithImageId("{ami-id}")
            .WithInstanceType("{size}")
            .WithMaxCount(1)
            .WithMinCount(1)
            .WithSecurityGroup("{the security group}")
            .WithKeyName("{your key}")
            .WithUserData(Convert.ToBase64String(Encoding.ASCII.GetBytes(userData)));

        ec2.RunInstances(runInstance);

The user data can contain either a reference to a script or the script itself.

answered Mar 25, 2019 by Archana
• 5,640 points

Related Questions In AWS

0 votes
0 answers
0 votes
1 answer

nstalling phpMyAdmin in Amazon EC2 instance

I needed to update the /etc/httpd/conf.d/phpMyAdmin.conf to allow remote ...READ MORE

answered Jul 13, 2018 in AWS by Cloud gunner
• 4,670 points
1,863 views
0 votes
1 answer
0 votes
1 answer

How to upload a lib for Tomcat in Amazon EC2?

You need to set the proper privileges ...READ MORE

answered Aug 20, 2018 in AWS by Archana
• 4,170 points
925 views
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Graphical User Interface in Amazon EC2 instance

I am not exactly sure if an AMI of ...READ MORE

answered May 13, 2019 in AWS by Archana
• 5,640 points
814 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP