AWS Lambda — Launch EC2 Instances

AWS Lambda — Launch EC2 Instances

There are a variety of situations where having a microservice available that can manage (Create, start, stop or terminate)EC2 instances at will can be handy.

There are a variety of situations where having a microservice available that can manage (Create, start, stop or terminate)EC2 instances at will can be handy. In this article, we are going to see how we can use an AWS Lambda to do such a thing on demand without using any extra servers or instances at all.

we will write a Lambda function that will create an EC2 instance. This Lambda function will be written in Python using the Boto3 library. We will also create a custom Lambda execution policy for our IAM role. When we’re done, we will be able to log in to the new EC2 instance via SSH.

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",
            "Effect": "Allow",
            "Action": "logs:CreateLogGroup",
            "Resource": "arn:aws:logs:*:*:*"
        }
    ]
}

Let’s Move on the AWS Lambda

  1. Select Functions > Create Function
  2. Enter the name of your lambda function.
  3. Select python as a runtime language.
  4. Click on *Choose or create an execution role *> SelectUse an existing role.
  5. Click Create Function.
  6. Navigate to AWS Lambda
  7. Select Functions > Create Function
  8. Click on **Choose or create an execution role**> SelectUse an existing role .

aws automation-testing aws-lambda devops aws-ec2

What is Geek Coin

What is GeekCash, Geek Token

Best Visual Studio Code Themes of 2021

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Top 10 Automation Testing Tools: 2020 Edition

The demand for delivering quality software faster — or “Quality at Speed” — requires organizations to search for solutions in Agile, continuous integration (CI), and DevOps methodologies. Test automation is an essential part of these aspects.

An Intro to Build Automation Tools for Selenium Automation Testing

In this post, we'll learn An Intro to Build Automation Tools for Selenium Automation Testing. Read more to find out how!

Measure Your Test Automation Maturity

Feel free to grade your team's maturity through my research. By the end of the article, you'll have your Test Automation Maturity Level.

DevOps Test Automation | DevOps Automation Tools | DevOps Testing | DevOps Training

This Edureka video on "DevOps Test Automation" will give you a brief understanding of what is DevOps Test Automation and the various tools used for it. In this DevOps Test Automation Tutorial, you will also understand the best Test Automation strategy to apply in the Continuous Integration/Continuous Deployment Pipeline. The following topics are covered in this DevOps Test

Accelerate Test Execution With Self-Healing Mechanism

Katalon Studio can determine test status, detect errors, analyze, and offer a solution to heal the broken test automatically.