roribio / alpine-sqs

Dockerized ElasticMQ server + web UI over Alpine Linux for local development
GNU Affero General Public License v3.0
255 stars 56 forks source link

Docs for using with AWSSDK #35

Open mikejr83 opened 4 years ago

mikejr83 commented 4 years ago

I'm trying to use this to do local development since our org locks down our AWS account (even our dev). If it isn't deployed through our ops terraform and scripts it can't interact with AWS. This means that the AWS CLI is impractical. Hence, this image is a godsend for individuals like me who are forced to mock AWS services.

The problem I'm running into is that all of my .NET Core usage of the AWSSDK errors with "Operation timeout". I know this isn't this service's fault as I was able to beg/borrow/steal some credentials for a bit to use the CLI and I was able to create a ~/.aws/credentials file that let me run the AWS CLI commands listed in the README.MD. I was also able to give the .NET appsettings.json the profile name and it too was able to push a message to the service.

Is there a way to do this with faked AWS credentials (I know mine are going to expire at some point) seeing that I'm not really doing anything with AWS to communicate with this service? Could a quick document or link be given to point to this info?

I've used a S3 mock service before but I don't recall having to have a profile and credentials setup to get the AWSSDK to be tricked into using it.

Sorry if this isn't the place for this but I don't see any discussion forum other than an issue.

Again, thanks for providing this image for those of us who don't have access into AWS!

osmanghoni1 commented 4 years ago

Hi, I believe I am having similar issues as @mikejr83

$sqsClient = new SqsClient(['debug' => true, 'endpoint' => 'http://localhost:9324','region' => 'eu-central-1', 'version' => '2012-11-05']);

$message = [ 'QueueUrl' => 'http://localhost:9324/queue/service-queue', 'MessageBody' => 'Some message', 'MessageGroupId' => 'GROUP' ];

$sqsClient->sendMessage($message);

I am also adding message attributes here but committed in example above

I have tried with the default queue as well, my code works with a queue on aws, using the credentials file

Debug output from the client sqs-debug.txt

Any help would be appreciated

WesleyBuck commented 3 years ago

Hi, @mikejr83 @osmanghoni1 found a work around for the .net AWS SDK dependency injection not working with a local docker instance: `

if DEBUG

            // Connect to local sqs instance, leveraging using for disposal and proper managment of the entity.
            using IAmazonSQS lsqs = new AmazonSQSClient(new AmazonSQSConfig
            {
                ServiceURL = "http://localhost:9324",
            });
            sqs = lsqs;

endif

`

WASDi commented 3 years ago

As I have no credentials at all yet, I was able to send a message using the Java SDK like this:

AmazonSQS sqs = AmazonSQSClientBuilder.standard()
        .withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration("http://localhost:9324", null))
        .withCredentials(new AWSStaticCredentialsProvider(new AnonymousAWSCredentials()))
        .build();

sqs.sendMessage("http://localhost:9324/queue/default", "Hello World");
WesleyBuck commented 3 years ago

@WASDi I actually recommend using ElasticMQ. It does not have the same long polling issues as Alpine SQS and it still allows you to use AWS SDK to connect to it.