Has anyone ever programmatically added an SNS Topic as a trigger to a Lambda function in AWS and also programmatically enabled it? I am trying the following with the Powershell AWS SDK and can do everything, but enable it.
First, I locate one of my topics (myTopic):
$snsTopicArn = (Get-SNSTopic | {$_.TopicArn -match "myTopic"}).TopicArn
Prepare to subscribe to the lambda endpoint ($lambdaARN)
Connect-SNSNotification -TopicArn $snsTopicArn -Protocol lambda -Endpoint $lambdaArn `
-Confirm:$FALSE | Out-Null
Since this function returns a subscription arn and not a token, the documentation has told me to assume that the subscription has been autoconfirmed and does not need a "ConfirmSubscription" (Confirm-SNSSubscription) call.
Next, I add permission to the Lambda's resource policy for this topic to run the Lambda.
Add-LMPermission -FunctionName $lambdaName -Action "lambda:Invoke" `
-Principal sns.amazonaws.com -SourceArn $snsTopicArn `
-StatementId (Get-Random) | Out-Null
At this point the topic appears in the list of triggers for the topic, but is not enabled.
Any ideas?