How do I add trigger to an AWS Lambda function using AWS CLI?
I was able to add SNS trigger for lambda using below AWS CLI
aws lambda add-permission \
--function-name {{LAMBDA-FUNCTION-NAME}} \
--statement-id {{UNIQUE-ID}} \
--action "lambda:InvokeFunction" \
--principal sns.amazonaws.com \
--source-arn arn:aws:sns:us-east-1:77889900:{{SNS-TOPIC-ARN}}
The SNS topic can also be from other region.
Hope this helps.
The only event sources that are managed within lambda's own cli api are Kinesis Streams and DynamoDb Streams. You can manage them with the cli using aws lambda
S3 bucket events are managed within S3, as they can be sent to SNS topics, SQS queues, or Lambda functions. So you need to use the aws s3api
cli commands, specifically put-bucket-notification-configuration
In the --notification-configuration
arg, you'll have something like:
{
"LambdaFunctionConfigurations": [
{
"Id": "string",
"LambdaFunctionArn": "string",
"Events": [events]
}
]
}
Where events are list of s3 events