AWS - Lambda | Clean your AWS account with ONE Lambda Function | PYTHON boto3



In this practical video, we will write a #Lambda Function in PYTHON which investigates your #AWS account and deletes the resources which are costing you money.

You will also learn how to use boto3 Python library. A detailed interactive video with #DEMO of every step.

boto3 Documentation —

PYTHON Code —

———————————————————————-

I would request to look at our playlists to learn systematically for AWS Certifications —
Solutions Architect –
&&&
SysOps Administrator –

++++++++++++++++++++++++++++++++++++++++
SUBSCRIBE to our youtube channel – youtube.com/knowledgeindia

I have answered lot of AWS Interview questions in LIVE sessions here —

Connect with me on LinkedIn to read interesting AWS updates & Practical Scenario Questions —

Don’t miss any updates, please follow my FB page
&
Twitter –

And for AWS exercises & case-studies, you can refer our blog —

++++++++++++++++++++++++++++++++++++++++

source

25 thoughts on “AWS – Lambda | Clean your AWS account with ONE Lambda Function | PYTHON boto3”
  1. awesome . here i have a query that what if the execution time would takes more then a 5 min. since the max execution time is 5 min and if it doesnot complete within that time does we need to execution again .

  2. I was looking for this for quite sometime. So thanks for a great video. But my lamda is timing out, trying to iterate thru the regions. Any idea what must be going wrong. I am just trying to delete ASGs

    import boto3

    def lambda_handler(event, context):
    ec2 = boto3.client('ec2')

    # Get list of regions
    regions = ec2.describe_regions().get('Regions',[] )

    # Iterate over regions
    for region in regions:

    # Running following for a particular region
    print ("************* Checking region — %s " % region['RegionName'])
    reg=region['RegionName']

    ################################ Auto Scaling Groups ASG ####################################
    print ("+++++++++++++ Starting Auto Scaling Group now —————–")
    clientAS = boto3.client('autoscaling', region_name=reg)
    print("The client is %s" %clientAS)
    result = clientAS.describe_auto_scaling_groups()

    for asg1 in result['AutoScalingGroups']:
    print ("About to delete %s | in %s" % (asg1['AutoScalingGroupName'], region['RegionName']))

    result = clientAS.delete_auto_scaling_group(AutoScalingGroupName=asg1['AutoScalingGroupName'], ForceDelete= True)
    # Notice the ForceDelete part

    The error I am getting is

    START RequestId: dde365cf-8aa2-45ac-85bf-148c84eac56d Version: $LATEST

    ************* Checking region — eu-north-1

    +++++++++++++ Starting Auto Scaling Group now —————–

    The client is <botocore.client.AutoScaling object at 0x7febfe618208>

    ************* Checking region — ap-south-1

    +++++++++++++ Starting Auto Scaling Group now —————–

    The client is <botocore.client.AutoScaling object at 0x7febfe2788d0>

    END RequestId: dde365cf-8aa2-45ac-85bf-148c84eac56d

    REPORT RequestId: dde365cf-8aa2-45ac-85bf-148c84eac56d Duration: 3003.28 ms Billed Duration: 3000 ms Memory Size: 128 MB Max Memory Used: 80 MB Init Duration: 202.30 ms

    2021-01-21T03:26:35.782Z dde365cf-8aa2-45ac-85bf-148c84eac56d Task timed out after 3.00 seconds

    It times out after 3 secs no matter what is inside code.

  3. Awesome Work..requesting you to make tutorial on AWS integration with Onprem AD where user login with their ad domain Ids to console login and access aws resources not via iam
    users

  4. One request. If possible could you please make a tutorial on – How to make http-https header redirection in simple way, not with the complex manipulation of httpd in EC2.
    In ALB I could do through the UI, by redirection rule.
    But in CLB I'm finding difficulties.
    And thank you very much for your great tutorials.

  5. How do we add in this code to include CloudFormation templates which are running, S3 buckets, Route 53, CloudFront, etc… to delete by the Lambda function? By the way, I went through the code that you posted in the description of this video, I didn't find S3, RDS, etc… which you mentioned and planned to update… Please kindly notify… Thank you for posting all these videos.

  6. Forget the 10k classes or the fake institution which bribe us by saying do aws certification from our academy it will definitely bag you a job in cloud…Guys and then here are KI team which are trying to make a new generation of engineers like us and teaching each and every aspect of cloud computing selflessly…Man huge respect yaar…best in the world..

  7. 1 ? To you Sir. Please guide me.
    I have given an interview they asked to me about SQL so what is the point to asked about SQL when someone apply for Sys Opps. I have watched Sys Opps playlist I haven't found any video on SQL.

Leave a Reply

Your email address will not be published.

Captcha loading...