DEV Community

Cover image for AWS-Lambda (Start/Stop EC2 Instance)
Kannan
Kannan

Posted on

AWS-Lambda (Start/Stop EC2 Instance)

AWS Lambda is a serverless, event-driven compute service that lets you run code for virtually any type of application or backend service without provisioning or managing servers.

  • Lambda functions are efficient whenever you want to create a function that will only contain simple expressions

  • Each Lambda function runs in its own container. When a function is created, Lambda packages it into a new container and then executes that container on a multi-tenant cluster of machines managed by AWS.

Step-1.Create the EC2 Instance.

Image description

Step-2. Create IAM Roles and policies.

  • Create a policy > Select EC2 type >Access level -Write (Stop Instance).

Image description

  • Add Specific ARN (Details of the EC2 Instance which we need to start/stop)

Image description

Image description

  • We have created separate policy for start/stop the EC2 Instance.

Image description

  • Create a Role > select entity (AWS Service)>select the use case as "Lambda".

Image description

Image description

Image description

  • We have created separate Roles for start/stop the EC2 Instance.

Image description

Step-3. Create Lambda function.

Image description

Image description

Image description

  • We can add the trigger rule "Event Bridge"

Image description

  • The similar we create another lambda function for start the EC2 instance and schedule corn job using add trigger"Event bridge"

  • It will start/stop EC2 instance using Lambda function.

Top comments (0)