Skip to content

Instantly share code, notes, and snippets.

@guitarrapc
Created March 9, 2023 10:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save guitarrapc/4320befbdf694b2fff669f76f6912dfe to your computer and use it in GitHub Desktop.
Save guitarrapc/4320befbdf694b2fff669f76f6912dfe to your computer and use it in GitHub Desktop.
C# SQS request on local with LocalStack. https://github.com/localstack/localstack
# see: https://github.com/localstack/localstack/blob/master/docker-compose.yml
# you don't need env and volumes on ↑ sample.
services:
localstack:
image: localstack/localstack:1.4.0
ports:
- "127.0.0.1:4566:4566" # LocalStack Gateway
- "127.0.0.1:4510-4559:4510-4559" # external services port range
volumes:
- "./sqs.sh:/docker-entrypoint-initaws.d/sqs.sh"
// using Amazon;
// using Amazon.Runtime;
// using Amazon.SQS;
// using Amazon.SQS.Model;
// using System.Threading.Tasks;
async Task Main()
{
// for LocalStack
var credentials = new Amazon.Runtime.BasicAWSCredentials("test", "test");
var client = new Amazon.SQS.AmazonSQSClient(credentials, new AmazonSQSConfig
{
AuthenticationRegion = "ap-northeast-1",
ServiceURL = "http://localhost:4566"
});
// create your queue....
// list queue name
var queues = await client.ListQueuesAsync(new ListQueuesRequest());
queues.Dump();
/*
QueueUrls List<String> (6 items)•••
http://localhost:4566/000000000000/foo-queue
http://localhost:4566/000000000000/foo-deadletter-queue
*/
// get queue url
var queue = await client.GetQueueUrlAsync("foo-queue");
queue.Dump();
/*
QueueUrl http://localhost:4566/000000000000/foo-queue
*/
}
#!/bin/bash
set -eo pipefail
# NOTE: use awslocal to access localstack service.
region=ap-northeast-1
queues=("foo-queue" "foo-deadletter-queue")
# create queues
for i in "${!queues[@]}"; do
awslocal sqs create-queue --queue-name "${queues[i]}" --region "${region}"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment