Coder Social home page Coder Social logo

aws-cost-optimization's Introduction

Automatically Deleting Unused Snapshots to Save AWS Costs

Problem :

Developers sometimes create EC2 instances with attached volumes and take snapshots for backup. When these instances are terminated, they often forget to delete the snapshots, leading to unnecessary storage costs.

Solution :

We use AWS to reduce storage costs with a Smart Lambda function. This function checks all snapshots and EC2 instances, and if it finds any snapshots not connected to active EC2 instances, it deletes them. This helps us save money by eliminating unused snapshots.

Steps :

  1. Log into your AWS Console.
  2. Navigate to the EC2 Console.
  3. In the Instances section, select 'Instances,' and then click on 'Launch Instance'.

d4

  1. Next, navigate to the 'Elastic Block Store' section and select 'Volumes'.
  2. You will notice that a default volume has already been created for us.
  3. Next, click on 'Snapshots,' and then click the 'Create Snapshot' button.
  4. In Volume ID section choose your default Volume ID created when we create instance.
  5. Next, click 'Next,' provide a name for your Snapshot, and then scroll down and click 'Create Snapshot'.

d6

  1. After creating a Snapshot, navigate to the Lambda Console and create the function.
  2. Next, clear the existing code and replace it with the 'ebs-stale-snapshot.py' code.

d1

  1. Click 'Deploy' to save your changes, and then click 'Test.' It will prompt a page that looks like the one given below.

d2

  1. Next, click on 'Create Event'. Once you've created the event, proceed to the IAM Console(Identity and Access Management) and then navigate policies section to create a new policy.
  2. In the 'Actions' section, grant permissions for the following actions: DescribeInstances, DescribeVolumes, DescribeSnapshots, DeleteSnapshots.
  3. Then scroll down and click 'Add Permissions'.

d3

  1. You can terminate the EC2 instance to test our Lambda function. Under the Code section, click 'Test code', it will display an output like this.

d7

aws-cost-optimization's People

Contributors

subodhbagde 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.