Code Monkey home page Code Monkey logo

aws_lambda_start_stop_ec2's Introduction

AWS Lambda EC2 Scheduler

This Terraform script automates the provisioning of an EC2 instance and a Lambda function that starts and stops the instance at specific times.

Prerequisites

  • Terraform installed on your local machine. You can download it here.
  • An AWS account with appropriate permissions to create EC2 instances, Lambda functions, and IAM roles.

Getting Started

  1. Generate an SSH key pair using the ssh-keygen command:

    ssh-keygen -t rsa

    Follow the prompts to choose a location and passphrase. Your private key (keyname.pem) will be saved in ~/.ssh/.

  2. Update the Terraform configuration with your SSH key name:

    Open modules/ec2/main.tf and replace YOUR_KEY_NAME with the name of your SSH key (without the .pem extension).

  3. Initialize Terraform and apply the configuration:

    cd lambda-function
    terraform init
    terraform plan
    terraform apply

    Review the plan and confirm the changes to deploy the EC2 instance and Lambda function.

Configuration

  • modules/lambda/main.tf: Contains the Terraform configuration for provisioning the EC2 instance and Lambda function.
  • modules/lambda/start.zip: Lambda function code to start the EC2 instance.
  • modules/lambda/stop.zip: Lambda function code to stop the EC2 instance.

Usage

The Lambda function is scheduled to run at specific times using Amazon EventBridge (formerly CloudWatch Events). By default, it starts the EC2 instance at 8:00 AM UTC and stops it at 8:00 PM UTC. You can adjust the schedule expressions in modules/lambdamain.tf as needed.

Contributing

Contributions are welcome! Please submit issues or pull requests if you encounter any problems or have suggestions for improvements.

Contact

For questions or support, contact Viresh Solanki.

aws_lambda_start_stop_ec2's People

Contributors

vireshsolanki avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.