I have a problem with testing the Lambda destination - SNS.
Message is not published after Lambda has successfully run. I invoked the lambda in AWS cloud console using a test event.
Destination and topics are properly configured.
Side note, I can programmatically publish a message via sns.publish().
Question:
Is there a way to publish a message automatically to SNS once Lambda has successfully run via AWS console (using a test event)?
No. The console "synchronously invokes your function with the test event". It must be invoked asynchronously to use the destinations.
Call the lambda invoke API with --invocation-type Event for asynchronous invocation.
Related
I have a node.js application where I am invoking a lambda function through AWS SDK and I'm trying to handle lambda's errors in such a way that when it fails it calls an https endpoint from my application.
My application flow is as follow:
Invoke lambda with object with data
Lambda receives the object in the "event" and run its processes.
if lambda fails either by runtime error, timeout, etc I need it to call an endpoint on my application, including the same object that I sent when invoking the lambda function.
I have thought of using CloudWatch alarms along with SNS to call my application endpoint, but I am not aware if that's entirely possible, specially if CloudWatch alarm can receive the lambda 'event' object.
How could I achieve calling an endpoint after Lambda has failed?
I've a slack workflow setup which will take approval in different channel and invoke AWS lambda from another private channel to restrict the access to AWS chatbot. But after the lambda is invoked, Chatbot is again asking for confirmation which requires some one to manually approve it again. Is there any way to bypass this.?
The aim is to automate this and remove user intervention, any workaround is appreciated
The documentation of AWS Bot states that :
https://aws.amazon.com/blogs/devops/running-aws-commands-from-slack-using-aws-chatbot/
Invoke a Lambda function from Slack To trigger a workflow or a runbook
from Slack, you can invoke a Lambda function by running #aws lambda
invoke FUNCTION_NAME. AWS Chatbot will ask for a confirmation.
I have a lambda function which is triggered by an Eventbridge rule. When I delete that Eventbridge rule, the trigger still appears in the lambda console.
screenshot of lambda console, under configuration tab
Is there any api or sdk method like deleteTrigger or something?
However aws internally call this post method https://ap-south-1.console.aws.amazon.com/lambda/services/ajax?operation=deleteRelation&locale=en
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.