4

Trying to post a message to an AWS SQS Queue that already exists using .Net Core.

Due to some deployment issues, I don't want to create a separate credentials file, I just want to manually add the credentials and add them to my client or request. I can't see how to do this using the documentation.

I've got a simple console app version of what I am trying to do below... I have created the Credentials, I just can't see how to inject them into the client or request so that it authenticates with my IAM user.

Currently the code just hangs creating the client.

var awsCreds = new BasicAWSCredentials("MYKEYGOESHERE", "MYSECRETGOESHERE");

var amazonSQSConfig = new AmazonSQSConfig();
                amazonSQSConfig.ServiceURL = "https://sqs.eu-west-1.amazonaws.com";

var amazonSQSClient = new AmazonSQSClient(amazonSQSConfig);
var sendRequest = new SendMessageRequest(); 

sendRequest.QueueUrl = "https://sqs.eu-west-1.amazonaws.com/[USERID]/[QUEUENAME]";
sendRequest.MessageBody = "{ 'message' : 'hello world' }";

var sendMessageResponse = amazonSQSClient.SendMessageAsync(sendRequest);

2 Answers 2

8

You have to pass the credentials to the AmazonSQSClient like so:

var amazonSQSClient = new AmazonSQSClient(awsCreds, amazonSQSConfig);
1
  • Yeah, had to add the region as well. Thanks! var amazonSQSClient = new AmazonSQSClient(awsCreds,Amazon.RegionEndpoint.EUWest1); Commented Mar 17, 2017 at 12:55
3

Five years later, here is what is working for me:

AmazonSQSClient sqsClient = new AmazonSQSClient("MYKEYGOESHERE", "MYSECRETGOESHERE", RegionEndpoint.USWest2);

No use of BasicAWSCredentials or AmazonSQSConfig.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.