I created a simple code in AWS Lambda for listing my buckets
import boto3
import botocore
s3 = boto3.client('s3')
response = s3.list_buckets()
print('Existing buckets:')
for bucket in response['Buckets']:
print(f' {bucket["Name"]}')
When I Deploy and test it, it gives me the right logs (my list of buckets) but it also gives me the error
Handler 'lambda_handler' missing on module 'lambda_function'
Do i have to write lambda_function(event,context)
for everything?
CodePudding user response:
Yes, you need it. It should be
import boto3
import botocore
def lambda_handler(event,context):
s3 = boto3.client('s3')
response = s3.list_buckets()
print('Existing buckets:')
for bucket in response['Buckets']:
print(f' {bucket["Name"]}')
because AWS needs to know / have a function to invoke and pass its event
and context
parameters.