How to execute command remotely on EC2 via Lambda function using SSM

Welcome to this video tutorial on how to execute the command remotely on an EC2 instance using the AWS lambda function and SSM that is systems manager. Here, we have considered a scenario where we want to fetch the last access time or login information of all the running instances.
---
Support my work:
---
Patreon: / srcecde
PayPal: paypal.me/srcecde
Paytm | Gpay: 9023197426
---
Series Tutorial
---
---
Another channel:
---
Srce Cde in Hindi: / @srcecdehindi
---
Connect with me
---
Twitter: / srcecde
GitHub: github.com/srcecde
Facebook: / srcecde
Instagram: / srcecde
LinkedIn: / srcecde
Reddit: / srcecde

Пікірлер: 35

  • @SrceCde
    @SrceCde3 жыл бұрын

    Please Like, Share & Subscribe

  • @ss76845
    @ss768454 ай бұрын

    Great video. Good to watch at 1.5 playback speed.

  • @SrceCde

    @SrceCde

    3 ай бұрын

    Glad it was helpful! Please like, share & subscribe :)

  • @camiladiaz5572
    @camiladiaz55723 жыл бұрын

    Great Tutorial! Just what I needed :). But i have a little question, if i dont use the ssm.get_command_invocation, my code will wait till the ec2 has executed the hole code? or it will just send the command and thats it?

  • @mayankpant5471
    @mayankpant54713 жыл бұрын

    Hey sre, which is faster for sending data to ec2 instance, ssh or ssm ?

  • @sameerambre2696
    @sameerambre26969 ай бұрын

    Very helpful

  • @SrceCde

    @SrceCde

    9 ай бұрын

    Glad it helped! Please like, share & subscribe :)

  • @anshulsoni3980
    @anshulsoni3980 Жыл бұрын

    Great video many thanks, a question i have how can we pass a random command in commands section?

  • @normanmartinez7305
    @normanmartinez73052 жыл бұрын

    great video

  • @SrceCde

    @SrceCde

    2 жыл бұрын

    Thanks, Norman! Please like, share & subscribe :)

  • @sairahul5842
    @sairahul58423 жыл бұрын

    I am getting an error of invalid instance id. I tried to hardcode the instance id directly to the lambda function but still facing the same issue. Can u provide any solution?

  • @IngenieroCastillo
    @IngenieroCastillo2 жыл бұрын

    Great Tutorial! I need copy files from ec2 (win) to s3. Can i use this method and execute UPLOAD command in ec2?

  • @andreykulikov3760
    @andreykulikov37603 жыл бұрын

    "halt" command passed:))) Thanx:)))

  • @nithinreddyable
    @nithinreddyable2 жыл бұрын

    Hello, how to send a working directory path and s3 output path in ssm command?

  • @chaitanyamhatre1670
    @chaitanyamhatre16703 жыл бұрын

    Nice bro I have one doubt about AWS API Gateway as this is latest video so I am posting over here. My UI is In angular and REST is in Sping Boot(EC2) and API gateway is in between so why i need do deploy API gateway frequently. and if I was not doing so it is giving CORS issue but I already Enable CORS. And after deploying it ,it is working fine but for very next hour if I have to use then i have deploy it again, Why????

  • @prashantcruise
    @prashantcruise Жыл бұрын

    I was searching for soln links this 🤫 . I know this is possible but what role I can give, do I need layers! this video makes this clear.

  • @SrceCde

    @SrceCde

    Жыл бұрын

    Glad you found it helpful. Please like, share & subscribe :)

  • @wijdanmaanitakrouri4838
    @wijdanmaanitakrouri48382 жыл бұрын

    if my lambda function is in a different region from EC2 how can make lambda access ec2 viaSSM?

  • @deepikak4238
    @deepikak42383 жыл бұрын

    Hi , Thank for your video , its really useful , how we can ftech tags , can you please advice

  • @SrceCde

    @SrceCde

    3 жыл бұрын

    Thanks for stopping by deepika k. You can use the describe_instances method to fetch the instance details including tags. For ex client = boto3.client('ec2') response = client.describe_instances() I hope this helps. Please like, share & subscribe. :)

  • @nikhilbhoyar1993
    @nikhilbhoyar1993 Жыл бұрын

    how to pass output of the result back to my front end ?

  • @amitgope1132
    @amitgope11322 жыл бұрын

    Thank you for the wonderful tutorial. While executing I am facing some problems: 1. How can we execute multiple commands? In your code you are executing only "last" command..but what if we want to execute 2-3 commands, how to do that? Can you please write the code?

  • @prashantcruise

    @prashantcruise

    Жыл бұрын

    Pass shell script

  • @animeshsrivastava2398
    @animeshsrivastava23982 жыл бұрын

    Not able to install snap package in amazon linux

  • @aboodbinjafar4874
    @aboodbinjafar48743 жыл бұрын

    thanks, what will be the code if i just want to run the commands on one particular instance?

  • @SrceCde

    @SrceCde

    3 жыл бұрын

    Thanks for stopping by abood binjafar. For single instance, all you need pass the instance id here ans remove the for loop: response = ssm.send_command( InstanceIds=[instanceid], DocumentName="AWS-RunShellScript", Parameters={'commands': ['command_to_be_executed']} # replace command_to_be_executed with command ) I hope this helps. Please like, share & subscribe. :)

  • @FlexWidSahil
    @FlexWidSahil2 жыл бұрын

    How to pass a python variable into SSM command as argument with shell script

  • @JagsRaina
    @JagsRaina3 жыл бұрын

    Bro, this is awesome, but how do we execute command on one particular instance?

  • @SrceCde

    @SrceCde

    3 жыл бұрын

    Thanks for stopping by Jagjot Singh. To execute on a particular instance, fetch the instance ID for the same. In case you are fetching all the instance ID's then you need to filter that list based on Tag or something. And once you have the instance id, you can execute the command as shown in a video. I hope this helps. Please like, share & subscribe. :)

  • @vikki5329
    @vikki5329 Жыл бұрын

    Bro please write one python code which display the get operatiion REST call get the values in the lambda logs by calling the python file which is located in EC2

  • @rupeshpatil6957
    @rupeshpatil69572 жыл бұрын

    Hello Sir, I am getting a timeout error. Exact error msg: Task timed out after 60.00 seconds

  • @SrceCde

    @SrceCde

    2 жыл бұрын

    Thanks for stopping by Rupesh Patil. Please increase the Lambda timeout and try again.

  • @rupeshpatil6957

    @rupeshpatil6957

    2 жыл бұрын

    @@SrceCde Lambda timeout is 1 min. In Ec2 security group tcp 22 inbound rule is enough Right?

  • @madhavapulagam2551
    @madhavapulagam25512 жыл бұрын

    can you share the code please

  • @SrceCde

    @SrceCde

    2 жыл бұрын

    Here it is: github.com/srcecde/aws-tutorial-code/blob/master/lambda/lambda_ec2_ssm.py I hope this helps. Please like, share & subscribe :)