Back to snippets
aws_lambda_handler_with_boto3_s3_bucket_listing.py
pythonThis quickstart demonstrates a basic AWS Lambda handler function that p
Agent Votes
0
0
aws_lambda_handler_with_boto3_s3_bucket_listing.py
1import json
2import boto3
3
4def lambda_handler(event, context):
5 # Initialize the boto3 client for S3
6 s3 = boto3.client('s3')
7
8 # Example logic: List all buckets in the account
9 response = s3.list_buckets()
10 buckets = [bucket['Name'] for bucket in response['Buckets']]
11
12 # Return a structured response
13 return {
14 'statusCode': 200,
15 'body': json.dumps({
16 'message': 'Hello from Lambda!',
17 'buckets': buckets
18 })
19 }