'how to get AWS SMS publish results in code

I've scoured the AWS documentation to see if there is a a way to get the SMS delivery log via code, but i'm at a miss, I can get the logs via cloud watch but I want to get them in code so if there is a failure ( like delivery.providerResponse Unknown error attempting to reach phone) I can dequeue the number

this is my code for sending texts, it gets a response code OK all the time even if i've hit my credit limit, the number isnt valid. Viewing failures in the console is great and all, but i want to update my queue programmatically based on success/failure

 Regex rgx = new Regex(@"^(07\d{8,12}|447\d{7,11})$");
    foreach (var item in accountTextDatas)
    {
        if (rgx.IsMatch(item.Phone1))
        {
            item.Phone1 = ReplaceFirst(item.Phone1, "0", "+44");
        }


        await Task.Delay(2000);
        var request = new PublishRequest()
        {
            Message = $"words go here"
            PhoneNumber = item.Phone1,
           
        };
        var response = await client.PublishAsync(request);
        context.Logger.LogInformation("Response Code to " + item.Phone1 + " " + response.HttpStatusCode);
    }


Solution 1:[1]

You can fetch the delivery status logs in your code through the CloudWatch API

The CLI equivalent would be something like:

aws logs describe-log-streams --log-group-name sns/$REGION/$ACCOUNT_ID/DirectPublishToPhoneNumber/Failure

{
    "logStreams": [
        {
            "logStreamName": "SOME_LOG_STREAM_NAME", ...

aws logs get-log-events --log-group-name sns/$REGION/$ACCOUNT_ID/DirectPublishToPhoneNumber/Failure --log-stream-name SOME_LOG_STREAM_NAME

{
    "events": [
        {
            "timestamp": 1650659779468,
            "message": "{\"notification\":{\"messageId\": ...

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 bjrnt