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
Please Like, Share & Subscribe
Great video. Good to watch at 1.5 playback speed.
@SrceCde
3 ай бұрын
Glad it was helpful! Please like, share & subscribe :)
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?
Hey sre, which is faster for sending data to ec2 instance, ssh or ssm ?
Very helpful
@SrceCde
9 ай бұрын
Glad it helped! Please like, share & subscribe :)
Great video many thanks, a question i have how can we pass a random command in commands section?
great video
@SrceCde
2 жыл бұрын
Thanks, Norman! Please like, share & subscribe :)
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?
Great Tutorial! I need copy files from ec2 (win) to s3. Can i use this method and execute UPLOAD command in ec2?
"halt" command passed:))) Thanx:)))
Hello, how to send a working directory path and s3 output path in ssm command?
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????
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
Жыл бұрын
Glad you found it helpful. Please like, share & subscribe :)
if my lambda function is in a different region from EC2 how can make lambda access ec2 viaSSM?
Hi , Thank for your video , its really useful , how we can ftech tags , can you please advice
@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. :)
how to pass output of the result back to my front end ?
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
Жыл бұрын
Pass shell script
Not able to install snap package in amazon linux
thanks, what will be the code if i just want to run the commands on one particular instance?
@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. :)
How to pass a python variable into SSM command as argument with shell script
Bro, this is awesome, but how do we execute command on one particular instance?
@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. :)
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
Hello Sir, I am getting a timeout error. Exact error msg: Task timed out after 60.00 seconds
@SrceCde
2 жыл бұрын
Thanks for stopping by Rupesh Patil. Please increase the Lambda timeout and try again.
@rupeshpatil6957
2 жыл бұрын
@@SrceCde Lambda timeout is 1 min. In Ec2 security group tcp 22 inbound rule is enough Right?
can you share the code please
@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 :)