TraceId using SNS and SQS - java

Good evening!
I receive an SNS inside an SQS Listner, and then I publish another SNS. Inside the SNS that I receive has a TraceId, how can I propagate this trace Id in the SNS that I send?
I thought about using spring-cloud-starter-sleuth, but I didn't find any usage example for this scenario.
Can anyone help me or give me some direction?

Related

AWS SES auditing

I need to maintain the status in the database if the email was delivered successfully or not, if the user has actually received the email or not,
when was the email delivered, email contents etc. for the purpose of auditing. How to do this ? Is there any API for this in AWS sdk ?
Its not as simple as just turning it on, but AWS does provide all the pieces you will need. This is how I do it currently
Turn on AWS delivery notifications, which will send the notifications to an SNS topic
Have that SNS topic delivery those messages to an SQS queue
Have a background job processing those messages and move them to a DynamoDB database for permanent storage.
The key part is #1, how you handle #2 and #3 is up to you - if I had to do it again I would use Lambda to takeover #3 for me, instead of using a custom job running on a dedicated Ec2 instance.
You can find out more about delivery notifications here:
https://docs.aws.amazon.com/ses/latest/DeveloperGuide/configure-sns-notifications.html#configure-feedback-notifications-console
also keep in mind, the tracking is not perfect - no email tracker is - SES uses some of the same techniques that mailchimp/constant contact use to determine if an email was opened, but it is far from foolproof.
You can configure Amazon SES to notify an Amazon SNS topic when you receive bounces or complaints, or when emails are delivered. Amazon SNS notifications are in JavaScript Object Notation (JSON) format, which enables you to process them programmatically.
Follow the steps :
Create topic in SNS
Subscribe to topic for delivery notifications(notifications are
pushed to AWS SNS topic in JSON format).
Subscribe to SNS in one of the following way:
Lambda
SQS
HTTP/S
Email
SMS
Considering the requirement of saving the JSON parameters in db table for purpose of auditing, you can listen to HTTP/S or SQS.
JSON response will have useful information like message id, notification type like complaints, bounce, delivery etc.

AWS SNS response handling

Am new to implement AWS SNS SMS gateway for my Java program. After the successful publishing message to AWS, I would like to know is the message send or not? Its always giving a response with messageId even the message fails to send. Is there any specific method or API to expose for this?
From the SNS FAQ:
Q: How do I track the delivery status of my SMS messages?
By enabling the Delivery Status feature in Amazon SNS, you can get information on the following for each message: MessageID, Time Sent, Destination Phone Number, Disposition, Disposition Reason (if applicable), Price, and Dwell Time.
In other words from the docs:
Amazon Simple Notification Service (Amazon SNS) provides support to log the delivery status of push notification messages. After you configure application attributes, log entries will be sent to CloudWatch Logs for messages sent from Amazon SNS to mobile endpoints. Logging message delivery status helps provide better operational insight, such as the following:
* Know whether a push notification message was delivered from Amazon SNS to the push notification service.
* Identify the response sent from the push notification service to Amazon SNS.
* Determine the message dwell time (the time between the publish timestamp and just before handing off to a push notification service).
Reference, check for code examples:
https://docs.aws.amazon.com/sns/latest/dg/sns-msg-status.html
So it seems you're up to using cloudwatch for this. The messageid you get from the API will of course be useful to filter for the information.
I suggest that you open a ticket for AWS support (because of your further questions as comments):
For professional support I suggest to open a case with them: https://console.aws.amazon.com/support/home#/case/create?issueType=service-limit-increase&limitType=service-code-sns-text-messaging

Logback: send email via AWS SNS on error

I am using logback in our java application for logging.
I want to send emails via AWS SNS whenever I encounter an error in my logs.
How can I do it for SNS?
Do I have to write a custom appender for it?
Yes. you will have to write a custom appender.
And also make sure that the email id to whom you want to send the email to, should first subscribe to the SNS topic. With SNS you cannot send emails to arbitrary email IDs that are not subscribed to the topic

Amazon SNS with java, Send group SMS to all over the world

I am trying to integrate send promotional SMS messages to customers. For this can I use amazon SNS, and can I integrate this SNS with my web application?
I am using java and I want send group SMS with one click in my web application.
Also, is there any better solution rather than Amazon SNS?
Amazon SNS can send messages via SMS. Sending options are:
Send a message to a single recipient, or
Subscribe multiple recipients to an SNS topic, then send the message to the SNS topic. All subscribers will receive the message.
If you wish to send a different message to each recipient, use the first option. If you are regularly sending a message to the same group of recipients, use the second option. However, if the group of recipients frequently changes, it may be easiest to send each message individually.
See documentation: Sending SMS Messages with Amazon SNS

How to configure SNS delivery status with the AWS SDK?

If you create an SNS Topic and, in the Amazon Console, open the Delivery Status options under Other topic actions, you can see this:
As you can see, it's possible now to get SNS delivery status feedback by configuring success and failure IAM roles. This works fine and I can see all the logs in CloudWatch for all published messages to each subscriber.
What I can't do is to set these values with the Java AWS SDK, is there any way of doing this?
I'm using aws-java-sdk:1.10.23 (latest as of now)
As #david-murray pointed out in the documentation, this is the solution to configure the feedback for HTTP endpoints:
amazonSnsClient.setTopicAttributes(topicArn, "HTTPFailureFeedbackRoleArn", "arn:aws:iam::1234567890:role/SNSFailureFeedback");
The same idea can be used for Application, Lambda and SQS.
My mistake was trying to set all of them with a single call like the form in the screenshot does by using:
https://eu-west-1.console.aws.amazon.com/sns/v2/SetMultiTopicAttributes
Although this doesn't seem to be present in the SDK at the moment, 4 separate calls will have the same effect.
Thanks!

Categories