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.

Billboard image

Deploy and scale your apps on AWS and GCP with a world class developer experience

Coherence makes it easy to set up and maintain cloud infrastructure. Harness the extensibility, compliance and cost efficiency of the cloud.

Learn more

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay