Designing SNS receiver in python script - python-3.x

Hi I am new to Python as well as AWS SNS services.
I want to develop a Python utility which would perform a role of subscriber as well as publisher to automate some simulations.
I am stuck where I need to design endpoint which would act as a SNS message receiver.
Could you guys please guide me on this topic.

AWS Lambda is a nice service for such scenarios and also it is quite cheap so will keep your AWS bills low.
You need publisher and subscriber for SNS in python so use AWS Lambda which will give you a nice connectivity with AWS SNS and there are few samples for subscribers which will help you in configuring the same.
So now your events get into AWS SNS and through subscription of lambda you can invoke Lambda function and take the action accordingly.
Event ---> SNS ---> Lambda Subscriber ---> Python Functions
Here is a nice reference for the same.
For publisher, you can use scheduled Lambda Function which will keep on pooling for some event to occur and then depending upon event you can send the notification to same SNS endpoint or different.
Event <--(Pooling)- Lambda Publisher(Cron Based) --(Event Occurred)-> SNS
Here is the AWS Tutorial for the same.
I hope this helps.
PS: Just keep in mind that maximum runtime for any Lambda function should not exceed certain limit which is 5 mins currently.

Related

Invoke directly lambda vs SNS trigger lambda

In case of a event driven serverless stack with a HTTPS call in a Rest API and the trigger of another lambda to answer in a Websocket API, what is the best solution between SNS lambda trigger or aws sdk invoke in a asynchronus event architecture?
I can clearly see why choosing aws sdk invoke:
No need to implement another service, easier
Invoke is made by direct invoke from the code of lambda (fast, no duplicates, ...)
So I can't see the usefullness of adding SNS in between insted of a lot more configuration.
Just for more information, the second lambda is like a microservice to answer on websocket.

Subscribe non-exposed NodeJS Application to SNS

On my current architecture, I have a NodeJS application that posts a message on SQS, which triggers a lambda function that (finally) puts the result on MongoDB. While the lambda is running, the NodeJS app pools MongoDB until the status field changes to SUCCESS or FAILED.
I would like to change this architecture to be event-driven rather than relying on pooling. To achieve that I considered changing both the NodeJS app to subscribe to a SNS topic and the Lambda function to post the result to that topic.
However, I faced a challenge when attempting to subscribe to the SNS topic. The subscribe method demands an Endpoint to confirm the subscription, and the NodeJS in question is not exposed (it's not an API). So how could the subscription be confirmed?
I understand that AWS might want to avoid spams by implementing subscription confirmation for SMS and Email, but on this case, the subscriber is a simple application...
Is there any way to subscribe tot he topic without exposing the NodeJS application? Or SNS is not the appropriate solution here?
I have used RabbitMQ for this on the past, but I would rather not deploy an instance and instead leverage a platform-as-a-service type of product.

How do I read real time AWS Lambda logs using on-prem Python script?

I do not want to wait for 14 seconds to read CloudWatch Lambda logs.
Is there any way to read them in realtime in invoking shell on premises (outside VPC)?
Invoke async
result = lam.invoke(
InvocationType='Event',
FunctionName='my-lambda-func',
Payload=json.dumps(dict(test='test'))
)
Lambda writes logs to a service in question.
Loop/wait for real-time results in the same on separate shell.
A common way to use async invocation is to have your lambda publish your results to SQS queue or SNS topic. This way you can pull SQS queue on premise for results, or setup http endpoint subscription which will be automatically invoked by SNS when it gets a message from the lambda.
If you only want to focus on CloudWatch logs, then you can setup subscription filter on the logs for real-time processing of the incoming log events from lambda. Depending on your exact setup, you can use Kinesis, firehose or other lambda to get the log messages.

Sending notifications to Amazon SNS on AWS DMS task progress

Is it possible to pull AWS DMS replication task percentage progress and use that to create an AWS Lambda function for sending notifications to Amazon SNS for let's say, every 10% completion? I can't find any metrics/event categories anywhere in relation to this while I was browsing. Thanks.
You don't need a lambda here. You can monitor the progress using CloudWatch then set up an SNS notification.
monitoring: https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Monitoring.html
sns for cloudwatch: https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/US_SetupSNS.html

is it not possible to schedule aws-sns?

I am developing IOS and node.js application. And I want to use the push-notifications service. Finally, I decided to use Amazon's sns service.
And I want to send a push service to all registered devices at a specific time, one at a time. I do not know if Amazon's sns service can do it. Is this possible? If not, would I be better off using Firebases?
This can be done using Amazon CloudWatch Events. CloudWatch Events can invoke a SNS topic on a schedule that is user defined.

Resources