Reputation: 17498
Is there a simple way for me to add to an AWS SQS queue from an AWS lambda?
From my google search research findings, it seems that the suggested workflow is to publish to an SNS topic, which can then push the message to the queue.
Question: Is there a reason to use SNS
on top of SQS
instead of using SQS
only?
Context (FYI): My scenario is that I am using SQS as a logger queue. I need to push logs to this queue from a lambda.
Upvotes: 1
Views: 914
Reputation: 235
It is possible to push from Lambda to SQS, you can try and make sense of the code below not sure if its gonna help or not
public async Task<string> FunctionHandler(ILambdaContext context, int count )
{
{
StringBuilder sb = new StringBuilder(1024);
using (StringWriter sr = new StringWriter(sb))
{
try
{
var credentials = new BasicAWSCredentials("AWS_ACCESS_KEY", "AWS_SECRET_KEY");
var client = new AmazonSQSClient(credentials, RegionEndpoint.EUWest1);
SendMessageRequest request = new SendMessageRequest();
request.DelaySeconds = 0;
request.QueueUrl = "queue url";
request.MessageBody = "text of what you logging to SQS";
for (int i = 0; i < count; i++)
{
SendMessageResponse response = client.SendMessageAsync(request);
}
}
catch (Exception e)
{
throw e;
}
return "";
}
}
}
Upvotes: 1
Reputation: 107
You can just use the AWS SDK to send your messages to your SQS queue. There is no magic here.
Upvotes: 0