'I am trying to find a way to count all of the objects within an s3 bucket using Amazon's AWS lambda using python

I am trying to find a way to count all of the objects within an s3 bucket using Amazon's AWS lambda using python

import os
import boto3

os.environ['input_bucket'] = 'demo-bucket-ak'

s3_client = boto3.client("s3") # Importing s3 client 

def lambda_handler(event,context):
    
    print("Loading the function...")

    response = s3_client.list_objects_v2(Bucket=os.environ['input_bucket'])
    s3_bucket = os.environ['input_bucket']
    json_file = response['Contents'][0]['Key']
    print(s3_bucket)
    print(json_file)


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source