I have a CloudFormation template which invokes a Lambda function to create a SNS topic. The create-stack works fine and the stack is created and then the topic is created. However, when I try to use update-stack on the same template to update the topic, I see some errors.
I have no idea what this "Internal Failure" is. And the CloudWatch log does not show any error, the Lambda function is also returning response for the "update" request.
I found a guy asking the similar question and the answer is
Important
After you create an Amazon SNS topic, you cannot update its properties
by using AWS CloudFormation. You can modify an Amazon SNS topic by
using the AWS Management Console.
As you know, my CloudFormation template is invoking a Lambda function to create the SNS topic. So, is it possible to call the CloudFormation template to invoke the Lambda function to update the SNS topic? Any help is appreciated.
One more thing: deleting and then creating the SNS topic cannot be considered as a good solution because there are queues subscribing to this topic.
Related
I am having an existing Cloudformation template to create a Codebuild, and I want to send a notification mail by updating the template when make a Codebuild fails. How to make a change in such a way ?
I'm completely new to Cloudformation, and it would be better if I get some inputs regarding the same. Thanks!
You can create a SNS topic in AWS for the notifications regarding the codebuild/codepipeline triggers. you can also manage what will trigger the SNS to send the email ( such as build fail/success, etc).
Please refer this AWS document for your reference:
https://docs.aws.amazon.com/codebuild/latest/userguide/sample-build-notifications.html
If I understood your question correctly. You want to update the cloud formation template if the build fails on codebuild.
You can get notified from codebuild by creating a notification rule on build failures.It will send messages to SNS. This message can be consumed with lambda to update the cloud formation template. There are many
ways as notification to SNS can be consumed.
More information here
I have a question regarding the relationship between Lambda functions and Amazon SNS as a service.
In SNS you create subscriptions to a topic, one being a Lambda function. In my head I'd imagine this is to invoke and trigger the function when a message is sent out from that topic. But on the Lambda side you can create triggers to do that same thing, one of them being SNS.
What exactly is the difference, it kinda seems like they do the same thing. But if I create a subscription for a topic using a Lambda, it does not show up in the the triggers of the function in the Lambda services, which makes me wonder what exactly is the difference between these two?
What exactly is the difference?
There is no difference from the functional point of view. What you are observing are just console imperfections.
To make sure, I manually verified using my SNS and my lambda function.
When you use Create subscription in the SNS console, and add a lambda function, it does show up as a trigger in lambda console.
Similarly, if you use lambda console and add SNS trigger, you will find the function in the Subscriptions section of SNS console.
However, AWS console is not perfect. For example, if you remove the lambda function from Subscriptions, it will not remove it from triggers on lambda console. Instead you will see the following error:
For some this may be a bug, for others a feature. I learned not to rely heavily on what AWS console shows. Just double check if the subscription works or not.
I need to add 'SNS' based trigger to my Lambda function, But create-event-source-mapping — AWS CLI Command Reference says only DynamoDB, Kinesis, SQS.
The aws lambda create-event-source-mapping command for SNS, S3 etc based triggers fails with --event-source-arn:
An error occurred (InvalidParameterValueException) when calling the CreateEventSourceMapping operation: Unrecognized event source, must be kinesis, dynamodb stream or sqs. Unsupported source arn
However these can be accomplished through AWS console.
Any thoughts?
To have a SNS triggers a Lambda, the Lambda need to subscribe the SNS's topic. You can refer to Tutorial: Using AWS Lambda with Amazon Simple Notification Service on getting Lambda triggered when a message published to SNS's topic.
*the cdk construct lib links provided are in python but you can use a language or your choice
In order to set a sns trigger on Lambda you have do following things,
1) create a SNS Topic
2) create a Lambda function
3) create a Lambda event source
4) integrate all
You can use AWS CDK to do all this
Creating a SNS Topic:
https://docs.aws.amazon.com/cdk/api/latest/python/aws_cdk.aws_sns/Topic.html
Creating a Lambda Function
https://docs.aws.amazon.com/cdk/api/latest/python/aws_cdk.aws_lambda/Function.html
Use functuon_obj.add_ecent_source(SNS_obj) to integrate all.
The IAM permissions to invoke your function on sns event will automatically get handled and you see then under Lambda permissions tab on console.
Do mark the answer right if it helps.
I am trying to use boto3 to programmatically subscribe my lambda function to a sns topic. When I execute my script, I see the integration in the AWS Lambda Console but publishing to the SNS topic does not invoke the function.
I then created the integration between the SNS topic and Lambda function directly in the AWS console itself. The AWS Console adds an Identifier field with the sns arn as the value. Now, publishing to the topic invokes the function.
In my script,I have added permissions(lambda_client.add_permission) using the values:,
{'Action': 'lambda:InvokeFunction',
'FunctionName':'my_lambda',
'Principal': 'sns.amazonaws.com',
'SourceArn': 'arn:aws:sns:us-east-1:redacted_acct_no:my-topic',
'StatementId': 'lambda-03a99f95-f490-4b9c-8bf8-20ee85fb2bff'}
I also do
sns_client.subscribe() and have successfully subscribed the lambda function to the topic
For testing purposes, I created two integrations, to two different topics and I called lambda_client.get_policy() and the policies are identical(of course, the StatementIds are different.
I have a similar setup for S3 which works.
Can we subscribe an Amazon SNS topic using an AWS Lambda function?
Yes. With help of sns.subscribe()
Please keep in mind: dont forget to confirm it sns.confirmSubscription()
If you mean can you use a message from a SNS topic as the trigger for a lambda function, then the answer is yes.
If you mean can you write a lambda function that adds a subscription to an SNS topic then the answer is yes. Towards the bottom are links for the language-specific AWS SDKs. Your Lambda function would need to have the appropriate permissions to be able to add a subscription as well.