AWS Lambda — Managing EC2 Instances
We created an AWS Lambda function that creates an EC2 instance in my previous article. Today we will gonna talk about How can we manage EC2 Instance with AWS Lambda.
we will write a Lambda function that will manage an EC2 instance. This Lambda function will be written in Python using the Boto3 library as well as Javascript. We will also create a custom Lambda execution policy for our IAM role. When we’re done, we will be able to manage EC2 instances via the AWS Lambda function.
Let’s Move on the AWS Management Console
Let’s navigate to AWS Identity and Access Management (IAM) to create a role for our AWS Lambda function.
Select Role > Create Role > Select AWS service
> Select Lambda
As a use case and create a role with the below policy.
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "VisualEditor0",
"Effect": "Allow",
"Action": [
"logs:CreateLogStream",
"logs:PutLogEvents"
],
"Resource": "arn:aws:logs:*:*:*"
},
{
"Sid": "VisualEditor1",
"Effect": "Allow",
"Action": [
"ec2:*"
],
"Resource": "*"
},
{
"Sid": "VisualEditor2"…