soto-project / soto

Swift SDK for AWS that works on Linux, macOS and iOS
https://soto.codes
Apache License 2.0
875 stars 83 forks source link

Null response when use SQS.QueueAttributeName.all - not working correctly #559

Closed Bartosz-Modento closed 2 years ago

Bartosz-Modento commented 2 years ago

Describe the bug I need all values from Amazon SQS but when use SQS.QueueAttributeName.all got error:

Unexpected Error dataCorrupted(Swift.DecodingError.Context(codingPath: 
[CodingKeys(stringValue: "Attribute", intValue: nil), EncodingWrapperKey(stringValue: "Name", intValue: nil)], 
debugDescription: "Cannot initialize QueueAttributeName from invalid String value SqsManagedSseEnabled", 
underlyingError: nil)).

After change to eg. SQS.QueueAttributeName.approximatenumberofmessages works fine

To Reproduce Steps to reproduce the behavior:

let sqsRequest = SQS.ListQueuesRequest()
    do {
        let myQueues = try mySqs.listQueues(sqsRequest).wait()
        guard let queues = myQueues.queueUrls else {
            NSLog("No queues found")
            exit(1)
        }
        for q in queues {
            print(q)
            let qRequest = SQS.GetQueueAttributesRequest(attributeNames: [SQS.QueueAttributeName.all],
                                                         queueUrl: q)
            let attr = try mySqs.getQueueAttributes(qRequest).wait()
            print(attr)
        }
    } catch {
        NSLog("Unexpected Error \(error).")
    }

Expected behavior Return all queue attributes.

Setup (please complete the following information):

Additional context Although I am just learning Swift and I do it as part of training and maybe I am doing something wrong, but ... I can easily extract the same data either manually by awscli or in a similar application written in golang or python.

adam-fowler commented 2 years ago

Hi Bartosz,

Can you run your code with

mySqs = SQS(..., middlewares: [AWSLoggingMiddleware()])

and report back the console output you are getting.

Thank you

adam-fowler commented 2 years ago

Also when you say "5.10 (latest from GitHub main branch)". Do you mean v5.10 or the main branch. The main branch has moved on considerably from v5.10.

Bartosz-Modento commented 2 years ago

Hi Bartosz,

Can you run your code with

mySqs = SQS(..., middlewares: [AWSLoggingMiddleware()])

Can't build with that: let mySqs = SQS(client: myClient, region:myRegion, middlewares: [AWSLoggingMiddleware()])

Got error: Extra argument 'middlewares' in call from Xcode

Ps. Same in line with: guard let queues = myQueues.queueUrls else { got: Type of expression is ambiguous without more context

adam-fowler commented 2 years ago

Sorry that should be

let mySqs = SQS(client: myClient, region:myRegion).with(middlewares: [AWSLoggingMiddleware()])
adam-fowler commented 2 years ago

I see your issue. It looks like the sqs service model files are not up to date. I will add a patch

Bartosz-Modento commented 2 years ago

Looks ok, I assume you only need the data? Headers won't be needed, are they? (http 200 etc)

  <GetQueueAttributesResponse xmlns="http://queue.amazonaws.com/doc/2012-11-05/">
  <GetQueueAttributesResult>
    <Attribute><Name>QueueArn</Name> <Value>arn:aws:sqs:us-west-2:blablabla</Value></Attribute>
    <Attribute><Name>ApproximateNumberOfMessages</Name><Value>0</Value></Attribute>
    <Attribute><Name>ApproximateNumberOfMessagesNotVisible</Name><Value>0</Value></Attribute>
    <Attribute><Name>ApproximateNumberOfMessagesDelayed</Name><Value>0</Value></Attribute>
    <Attribute><Name>CreatedTimestamp</Name><Value>1592592908</Value></Attribute>
    <Attribute><Name>LastModifiedTimestamp</Name><Value>1601472090</Value></Attribute>
    <Attribute><Name>VisibilityTimeout</Name><Value>120</Value></Attribute>
    <Attribute><Name>MaximumMessageSize</Name><Value>256000</Value></Attribute>
    <Attribute><Name>MessageRetentionPeriod</Name><Value>345600</Value></Attribute>
    <Attribute><Name>DelaySeconds</Name><Value>0</Value></Attribute>
    <Attribute><Name>ReceiveMessageWaitTimeSeconds</Name><Value>20</Value></Attribute>
    <Attribute><Name>SqsManagedSseEnabled</Name><Value>false</Value></Attribute>
  </GetQueueAttributesResult><ResponseMetadata>
  <RequestId>4ca74f21-68b3-5884-a0ff-15366fe132a7</RequestId></ResponseMetadata></GetQueueAttributesResponse>
adam-fowler commented 2 years ago

There is a fix in #561. If you use the branch sqs-managed-sse-enabled your code should work

Bartosz-Modento commented 2 years ago

Works fine, thank you.

adam-fowler commented 2 years ago

This is in release 5.11.0