I am trying to create trigger for AWS lambda from SNS codestar-notifications
.
While creating a trigger using Console it automatically adds subscription to the SNS topic.
. Also, this works in alternate direction i.e. if I create a subscription for SNS as the Lambda function by explicitly adding its arn, it automatically links a trigger to Lambda function.
But when using terraform to create a subscription as below:
resource "aws_sns_topic_subscription" "subscribe_lambda_to_first_topic" {
topic_arn = module.first_topic.sns-topic-detail.arn
protocol = "lambda"
endpoint = module.lambda_function.lambda_function.arn
}
it doesn't create a trigger in AWS Lambda.
I tried creating a trigger using event source mapping in Terraform as below
resource "aws_lambda_event_source_mapping" "lambda_source" {
event_source_arn = module.first_topic.sns-topic-detail.arn
function_name = module.lambda_function.lambda_function.arn
starting_position = "LATEST"
}
it throws me an error saying it is possible only for
Error: error creating Lambda Event Source Mapping (arn:aws:sns:us-west-2:619867110810:codestar-notifications-emc-sns-to-lambda): InvalidParameterValueException: Unrecognized event source, must be kinesis, dynamodb stream or sqs. Unsupported source arn : arn:aws:sns:us-west-2:619867110810:codestar-notifications-emc-sns-to-lambda { RespMetadata: { StatusCode: 400, RequestID: "83bf57cb-b50d-49a8-9547-72fac69778d1" }, Message_: "Unrecognized event source, must be kinesis, dynamodb stream or sqs. Unsupported source arn : arn:aws:sns:us-west-2:619867110810:codestar-notifications-emc-sns-to-lambda", Type: "User" }
with aws_lambda_event_source_mapping.lambda_source, on main.tf line 43, in resource "aws_lambda_event_source_mapping" "lambda_source": 43: resource "aws_lambda_event_source_mapping" "lambda_source" {