1

I am trying to publish a message to a topic using the AWS SNSClient from the c++ SDK.

Can someone help me to find a way to figure out what is wrong with my approach? The error message I am getting only says that the "endpoint could not be reached".

I am trying to figure out where my request hangs - in my point of view it could be one of the following:

  • the docker container the c++ app is running in is blocking the requests somehow (new to docker)
  • the client configuration is wrong (region, arn, creditials wrong?)
  • the request is malformed (some parameters not set? Message type maybe?)

Does someone know how I can debug my request and see what the issue is?

Thanks! My code looks something like this (api init and shutdown is omitted):

Aws::SNS::SNSClient client(credentials , config);
Aws::SNS::Model::PublishRequest pubReq;
pubReq.SetTopicArn("...");
pubReq.SetMessage("Test message");

pubOutcome = client.Publish(pubReq);

if(! pubOutcome.IsSuccess() ){
    std::cout << "outcome: " << pubOutcome.GetError().GetMessage() << std::endl;
}
Edub
  • 508
  • 7
  • 24

1 Answers1

3

My guess without being able to see your code is that you have not specified the correct region. If your code hangs for a few seconds then this is most likely the problem.

Add a line of code like this before your create the SNS Client:

config.region = "us-west-2";

To enable debugging add this line before Aws::InitAPI(options)

options.loggingOptions.logLevel = Aws::Utils::Logging::LogLevel::Debug;

The headers for logging:

#include <aws/core/utils/logging/DefaultLogSystem.h>
#include <aws/core/utils/logging/AWSLogging.h>

Then you can review the logfile that is generated. It will start with "aws_sdk"

I use Visual Studio, so I prefer to step into the code to figure out what is wrong. Sometimes it is simpler to review the logfile.

John Hanley
  • 74,467
  • 6
  • 95
  • 159
  • FWIW that seems to be a bug, and it's still present today. There's no situation in which code should hang because of valid-but-incorrect parameters to a function. – Code Abominator Oct 15 '20 at 02:46