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 in AWS by datageek
• 3,040 points
42 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 by Archana
• 5,560 points

Related Questions In AWS

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,260 points
144 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,090 points
44 views
0 votes
1 answer

In Amazon Data Pipeline, how to make sure only once instance of a pipeline is running at any time?

On the CopyTablesActivity, you could set a lateAfterTimeout attribute ...READ MORE

answered Sep 19, 2018 in AWS by Priyaj
• 56,520 points
271 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 in AWS by Archana
• 5,560 points
24 views