0

What I need to do is: When a EC2 instance is launched, the lambda function or other installs the script to monitor memory and disk usage in the host.

I'm thinking in how I can do that.. Anyone can give me a idea?

3 Answers 3

2

You don't need a lambda. Pass your install script as user data.

See: Running Commands on Your Linux Instance at Launch

Sign up to request clarification or add additional context in comments.

2 Comments

Yes, it is a solution. But what I need is: Whenever a EC2 instance will be launched, this script will be installed
Right, @MaiconBaum, so... exactly as this answer says, "pass your install script as user data." It runs on first boot.
0

It appears that your requirement is to monitor Memory and Disk usage from an Amazon EC2 instance. I will assume that you want to monitor it via Amazon CloudWatch.

Amazon CloudWatch provides default metrics for EC2 instances including CPU utilization, network traffic and disk access. These metrics are visible from the hypervisor. However, CloudWatch cannot see 'inside' the EC2 instance, so it is necessary to run scripts from within the instance to track things like free memory and free disk space. The scripts talk to the operating system to retrieve these metrics, which is why they have to run 'within' the instance.

Some standard monitoring scripts are available for Linux instances: Monitoring Memory and Disk Metrics for Amazon EC2 Linux Instances

You can, of course, write your own scripts to send custom metrics to CloudWatch. Once installed, the scripts will run automatically when the instance is restarted.

If you wish to install these scripts (or your own scripts) on new EC2 instances, there are a couple of methods:

  • Install the scripts on one instance, then create an Amazon Machine Image (AMI) of that instance that contains a copy of the disk. You can then launch new instances using that AMI, and the scripts will already be installed on the new instances.
  • Launch the instance(s) with a User Data script to install the monitoring script. Any script passed through User Data will automatically be run the first time that the instance is started.

1 Comment

Hi, thanks for answer me! So.. I'm using the script to monitor Memory and Disk Usage via CloudWatch! I was thinking about these two options that you gave me, but I was searching for others options, just like "RunCommand" or maybe a Lambda Function when a EC2 is launched, but I found nothing. I will use a AMI with the script + agent to "RunCommand" to future updates. Thanks!
0

When you are using a scaling group you must specify a LaunchConfig. Part of the LaunchConfig is the user-data script which is executed when the instance boots. This can be also easily done from CloudFormation scripts if that is what you use to create the new EC2 VM. You can find here samples of scripts. enter link description here

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.