How do I customize message in SNS topic notification triggered on cloudwatch rules? - amazon-sns

I have a cloudwatch alarm for my s3 bucket, if there are no changes to the bucket in a day, the alarm is triggered and an SNS topic is sent.
I have set a cloudwatch event rule to schedule the target SNS topic daily if it meets the conditions.
However, I am having trouble customizing the SNS message needed to provided detail to the notifications.
I have attempted to use the input transformer, but I cannot wrap my head around keys I need to map for this service.
How can I map the details required? How can I find the key-value details to send to my Input Transformer to formulate a message?

The easiest method would be to trigger an AWS Lambda function that can read the incoming information, customize the content, and then send it as a message through Amazon SNS.
I don't think Amazon CloudWatch can directly trigger an AWS Lambda function, so you'll probably need two SNS topics:
One SNS topic used by CloudWatch, that triggers the Lambda function
One SNS topic that where Lambda sends the customized message and people can subscribe to receive it
The Lambda function can also do additional work, such as reporting on the size of the bucket and retrieving additional stats you would like mentioned.

Related

Create a named push-subscription to a Google Cloud Pub/Sub topic using firebase cloud functions

I know I can create an "anonymous" subscription for a topic like this:
functions.pubsub.topic('topic-name').onPublish(console.log)
But this doesn't allow me to distribute different messages to multiple listeners on a single subscription and, more importantly, it doesn't allow me to bind a subscription to a dead-letter topic, because, as I understand it, this subscriptions are ephemeral (i.e. they are tied to the lifecycle of the Firebase Cloud Function).
Is there a way to achieve this without creating a "real" Google Cloud Function and only using Firebase?

Flutter FCM Topic named like a document

I am new to firebase cloud messaging and i search the best way to send notifications to clients.
I want people to be able to subscribe to new entry in subcollection like this :
books/{bookID}/comments/{commentId}/reply/{replyId}}
Is that bad if i use that kind of syntax?
so i can push notification on that topic when new reply are created
void fcmSubscribe(String bookId,String commentId) {
firebaseMessaging.subscribeToTopic('book-${bookiD}_comment-${commentId}');
}
or i need to use Individual Device Notifications and create entries like this
books/{bookID}/comments/{commentId}/notifications/{tokenId}}
i want to avoid firestore Read and Write.
You can use whatever valid topic names that you want. Use whatever you like - it's your choice. There is nothing particularly "bad" about your choice of name, as long as it works for you. Things can only go badly for you if you exceed one of the documented limits for topic messaging:
Topic messaging supports unlimited subscriptions for each topic. However,
FCM enforces limits in these areas:
One app instance can be subscribed to no more than 2000 topics.
If you are using batch import to subscribe app instances, each request is limited to 1000 app instances.
The frequency of new subscriptions is rate-limited per project. If you send too many subscription requests in a short period of time, FCM
servers will respond with a 429 RESOURCE_EXHAUSTED ("quota exceeded")
response. Retry with exponential backoff.
If you're thinking that FCM is tied in any way to Firestore, that's not the case. You are not obliged to make anything match between your Firesore documents and your FCM topics.

How to set up email notification for identify the last commit user and send codepipline status

I am working on AWS Codepipeline, How to set up e-mail notifications for developer did last commit and build was failed. Now identify the user and send automatic email for the developer along with manager. Can anyone please help on this
Thanks in Advance
You can use notification rules to notify users of important changes, such as when a pipeline starts execution. Notification rules specify both the events and the Amazon SNS topic that is used to send notifications. On the SNS topic, a subscription could be a User/Manager email address. Details here: [0]
Currently the notification message that is sent in case of, for example, pipeline success, does not include the Commit id or the Committer information [1].
As a work-around I suggest to implement additional stages within the pipeline that would Invoke a Lambda Function. The Lambda Function can then be programmed to publish the detailed event message [2] to the SNS using AWS SDKs. Detailed instructions for this set-up are documented at [3].
References:
[0] https://docs.aws.amazon.com/codebuild/latest/userguide/notification-rule-create.html
[1] https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/EventTypes.html#codepipeline_event_type
[2] Example JSON Event - https://docs.aws.amazon.com/codepipeline/latest/userguide/actions-invoke-lambda-function.html#actions-invoke-lambda-function-json-event-example
[3] Invoke an AWS Lambda Function in a Pipeline in AWS CodePipeline - https://docs.aws.amazon.com/codepipeline/latest/userguide/actions-invoke-lambda-function.html

Amazon SNS Filter control and access

Looking to setup a aws SNS topic - I intend to subscribe a third party to this topic and I’m hoping that I can use its message filtering to ensure said third party only gets the messages they need.
Is that possible? Since I control the SNS topic I’m hoping I can also control who gets to see what but the docs are not super clear.
From Amazon SNS Message Filtering - Amazon Simple Notification Service:
By default, an Amazon SNS topic subscriber receives every message published to the topic. To receive a subset of the messages, a subscriber must assign a filter policy to the topic subscription.
A filter policy is a simple JSON object containing attributes that define which messages the subscriber receives. When you publish a message to a topic, Amazon SNS compares the message attributes to the attributes in the filter policy for each of the topic's subscriptions. If any of the attributes match, Amazon SNS sends the message to the subscriber. Otherwise, Amazon SNS skips the subscriber without sending the message. If a subscription doesn't have a filter policy, the subscription receives every message published to its topic.

SNS getEndpointAttributes Returns Old Data After EventEndpointUpdated Event

When attaching a topic to a SNS application's "Endpoint updated" configurable topic I'm experiencing some unexpected behavior. Per AWS's documentation on SNS Application Events, I should receive an event on my configured topic when a platform endpoint has been updated to disabled or it's token changed.
In my case I have a lambda function subscribed to this topic that then retrieves the platform endpoint's attributes via a call to AWS's javascript sdk SNS.getEndpointAttributes so that I can check what attribute have changed to either delete the endpoint or update the associated token in my persistent storage. This call however is returning the endpoints as Enabled = true which then prevents me from taking the corrective actions. However if I look in the AWS SNS console I can see the endpoint has been disabled as Enabled = false.
Have others experienced similar inconsistencies and if so what's the best practice to get around them? Thanks for any input!
I was also facing the similar problem when amazon notified me sns application events via http. To work around this problem i actually delayed the execution of code that sync these endpoint updates with my database. To achieve this i scheduled a job for my background queue worker and delayed its execution after 30 seconds from the time amazon notified via http. I don't know whether it is a best practice or not but it is working in my scenario.

Resources