0

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?

2
  • Yes, you have to. Because that way AWS knows which function to run. Commented Sep 14, 2021 at 16:20
  • @luk2302 and where do i have to put it for it to be correct? Commented Sep 14, 2021 at 16:21

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

3 Comments

when i put it there, it gives me the error "errorMessage": "Syntax error in module 'lambda_function'", do you know what can it be?
@Hamilton sorry, blindly copied your code which was missing an indentation. Should work now.
tysm! it worked now, you saved my day haha

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.