Source: medium.com

SSH with AWS Lambda

Category: automation

Lately, it has been used a lot to make automation of all kinds thanks to its low cost and easy implementation. A not very common, but very useful use for lambda is to execute commands through SSH, we can send commands to our EC2 instances and do some automation of tedious and repetitive processes, for example, you can get information about the machines and their processes, install Cloudwatch or SSM agent, etc., etc.

We have to the name of the layer then select compatibility with python 2.7 and very importantly we have to upload our zip folder from s3, if we upload it as .zip it could give problems.

Important once the layer is added click Save.Now we have to add import paramiko to our code. If it does not throw any error, it is that the installation of paramiko in the layer was successful.Now we can proceed to create a client with paramiko and throw commands to some instance, we can use the following code to obtain information about which operating is inside an instance.

Related Articles