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)
3 Answers
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:*']}]})
1 Comment
MattoTodd
you're the bext
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
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
sax
I'm working on the same topic, can you share a code snippet ? Willbe very useful.