2

how to add trigger s3 bucket to lambda function with boto3, then I want attach that lambda function to dynamically created s3 buckets using programmatically(boto3)

1
  • also I want add suffix to that bucket Commented Jul 8, 2017 at 6:33

3 Answers 3

6

This worked for me:

client = boto3.client(
                    's3',
                    aws_access_key_id=AWSAccessKeyID,
                    aws_secret_access_key=AWSSecretAccessKey)

response = client.put_bucket_notification_configuration(
Bucket=bucketName,
NotificationConfiguration= {'LambdaFunctionConfigurations':[{'LambdaFunctionArn': '<MyLambdaFunctionARN>', 'Events': ['s3:ObjectCreated:*']}]})
Sign up to request clarification or add additional context in comments.

1 Comment

you're the bext
3

The complete answer for this question with the source code is:

Functions to initiate at lambda client:

response1 = lambda1.add_permission(FunctionName='put*your*lambda*arn*here',
                               StatementId='response2-id-2',
                               Action='lambda:InvokeFunction',
                               Principal='s3.amazonaws.com',
                               SourceArn='put*your*s3*bucket*arn*here'
                              )
response2 = lambda1.get_policy(FunctionName='put*your*lambda*arn*here')

Function to initiate at the s3 bucket:

response3 = s3.put_bucket_notification_configuration(
                            Bucket='put*your*bucket-name*here',
                            NotificationConfiguration= {'LambdaFunctionConfigurations':[{'LambdaFunctionArn': 'put*your*lambda*arn*here', 'Events': ['s3:ObjectCreated:*']}]})

Your s3 trigger will be attached to you lambda.

Comments

1

Three steps I followed 1) connected to aws lambda with boto3 used add_permission API 2)also applyed get_policy 3)connected to S3 with boto resource to configuring BucketNotification API,put LambdaFunctionConfigurations

1 Comment

I'm working on the same topic, can you share a code snippet ? Willbe very useful.

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.