How to send parameters to EC2 instance aws

Solution for How to send parameters to EC2 instance aws
is Given Below:

I am fairly new to AWS and would like your suggestions. The problem I would like to solve is that I want to automate the process. I have this ec2 image running ubuntu and I want to call this executable “executable_hello_world_repeat” inside the image which prints “Hello World” every second. and when calling the executable I want to add input parameters such as “executable_hello_world_repeat -n10” this would print “hello world” 10 times.

Manually I can do the following:

  1. go to AWS management console and choose the ec2 image to start
  2. check if the instance is running successfully
  3. from the terminal call “executable_hello_world_repeat -n10”
  4. it prints the “Hello World”

I want to write a program to do them all programatically. Eventually I will have a web page in React/JS and automate this process.

Thanks for reading.

When an Amazon EC2 instance is first launched, a User Data script can be provided, which is automatically executed as the root user towards the end of the boot process. You can use this script to install software, configure settings, start process, etc.

Please note that this script only runs on the first boot, because the software does not need to be installed on subsequent boots.

If you want a script to run on every boot, put it in the /var/lib/cloud/scripts/per-boot/ directory.

If you later want to trigger a script to run, then you will need some mechanism that receives this request and runs the script. A few ways you could do this are:

  • Run a web server on the instance and the request comes via an HTTP / REST request, or
  • Trigger the AWS Systems Manager Run Command that will cause a script to be run on the instance, or even multiple instances, or
  • Have a program or script running on the instance that is continuously polling an Amazon SQS queue. When a message is received from the queue, trigger a program/script to process the message. This is known as a “Worker” that pulls from the Queue

The EC2 instance is basically just a normal Linux instance, so you’ll need to somehow get something to trigger on the instance when desired.