Admiral-Piett / goaws

AWS (SQS/SNS) Clone for Development testing
MIT License
770 stars 145 forks source link

Running goaws without a config file that defines AccountId will result in a ReceiveMessage returning invalid XML #231

Open tomtomau opened 3 years ago

tomtomau commented 3 years ago

I ran goaws as the compiled binary without passing in any config file.

When I received a message using the aws-sdk for node.js i got a cryptic XML parsing error which I traced back to the XML that goaws was returning was missing a <Value> for SenderId:

<ReceiveMessageResponse xmlns="http://queue.amazonaws.com/doc/2012-11-05/">
      <ReceiveMessageResult>                                                                                                          
          <Message>                                                                                                                   
              <MessageId>bb763f86-eddf-4217-90f5-857834d09e27</MessageId>                                                             
              <ReceiptHandle>bb763f86-eddf-4217-90f5-857834d09e27#71889a5d-720f-49fa-9019-f9b252106262</ReceiptHandle>                
              <MD5OfBody>5eb63bbbe01eeed093cb22bb8f5acdc3</MD5OfBody>                                                                 
              <Body>hello world</Body>                                                                                                
              <MD5OfMessageAttributes>96656da642fec3b345246d3753b407b8</MD5OfMessageAttributes>                                       
              <MessageAttribute>                                                                                                      
                  <Name>command</Name>                                                                                                
                  <Value>                                                                                                             
                      <DataType>String</DataType>                                                                                     
                      <StringValue>compile</StringValue>                                                                              
                  </Value>                                                                                                            
              </MessageAttribute>                                                                                                     
              <Attribute>                                                                                                             
                  <Name>SenderId</Name>                                                                                               
              </Attribute>                                                                                                            
              <Attribute>                                                                                                             
                  <Name>ApproximateReceiveCount</Name>                                                                                
                  <Value>1</Value>                                                                                                    
              </Attribute>                                                                                                            
              <Attribute>                                                                                                             
                  <Name>SentTimestamp</Name>                                                                                          
                  <Value>1606344521</Value>                                                                                           
              </Attribute>                                                                                                            
              <Attribute>                                                                                                             
                  <Name>ApproximateFirstReceiveTimestamp</Name>                                                                       
                  <Value>1606344521</Value>                                                                                           
              </Attribute>                                                                                                            
          </Message>                                                                                                                  
      </ReceiveMessageResult>                                                                                                         
      <ResponseMetadata>                                                                                                              
          <RequestId>00000000-0000-0000-0000-000000000000</RequestId>                                                                 
      </ResponseMetadata>                                          
  </ReceiveMessageResponse>  

I was super confused because when I used the AWS cli to interact with goaws per the examples at the bottom of the goaws README, the aws-cli would return a value for SenderId!:

{
    "Messages": [
        {
            "MessageId": "fa3f13bf-186a-41a6-9724-7580f06cab31",
            "ReceiptHandle": "fa3f13bf-186a-41a6-9724-7580f06cab31#feff7a77-1a0e-48a1-a7b7-5fc550a05935",
            "MD5OfBody": "5eb63bbbe01eeed093cb22bb8f5acdc3",
            "Body": "hello world",
            "Attributes": {
                "ApproximateFirstReceiveTimestamp": "1606346671",
                "SenderId": "1606346671",
                "ApproximateReceiveCount": "1",
                "SentTimestamp": "1606346671"
            },
            "MD5OfMessageAttributes": "96656da642fec3b345246d3753b407b8",
            "MessageAttributes": {
                "command": {
                    "StringValue": "compile",
                    "DataType": "String"
                }
            }
        }
    ]
}

A keen eye would notice that SenderId has the same value as ApproximateFirstReceiveTimestamp, so I assume that is a quirk of the XML => JSON process in the aws-cli.

Digging through the code, it appears as if there is an attempt to cover for this and set the AccountId to "queue" when not present in config.go. However, I think if you're not passing in any yaml file then this would not happen.

Once I created a config file that defined the account id, everything worked as expected:

Local:
  AccountId: "13371337"

Looking through other issues, I suspect this issue was caused by the same setup as well - as the slightly cryptic XML parsing error look equivalent.

I recommend either making the -config flag mandatory or properly setting the AccountId when the config file is not set

Admiral-Piett commented 10 months ago

@tomtomau Thanks for bringing this up. I did a change to sort out the default config file a little while ago. Let me double check that and see if it resolved this issue by happen stance. We'll see. I'll look at it and get back to you.