aws-sdk-js-v3 icon indicating copy to clipboard operation
aws-sdk-js-v3 copied to clipboard

In Typescript, SQS.ReceiveMessageRequest.AttributeNames does not allow MessageSystemAttributeName

Open baumac opened this issue 2 years ago • 7 comments

Checkboxes for prior research

Describe the bug

The ReceiveMessageRequest.AttributeNames only allows values from the AttributeNames enum, and does not allow values from the MessageSystemAttributeName enum. This contradicts the docs which list MessageSystemAttributeName as valid values for the AttributeNames field.

AttributeNames are defined as:

  A list of attributes that need to be returned along with each message. These attributes include:
  All – Returns all values.
  ApproximateFirstReceiveTimestamp – Returns the time the message was first received from the queue (epoch time  in milliseconds).
  ApproximateReceiveCount – Returns the number of times a message has been received across all queues but not deleted.
  AWSTraceHeader – Returns the X-Ray trace header string.
  SenderId
  For a user, returns the user ID, for example ABCDEFGHI1JKLMNOPQ23R.
  For an IAM role, returns the IAM role ID, for example ABCDE1F2GH3I4JK5LMNOP:i-a123b456.
  SentTimestamp – Returns the time the message was sent to the queue (epoch time  in milliseconds).
  SqsManagedSseEnabled – Enables server-side queue encryption using SQS owned encryption keys. Only one server-side encryption option is supported per queue (for example, SSE-KMS  or SSE-SQS ).
  MessageDeduplicationId – Returns the value provided by the producer that calls the SendMessage action.
  MessageGroupId – Returns the value provided by the producer that calls the SendMessage action. Messages with the same MessageGroupId are returned in sequence.
  SequenceNumber – Returns the value provided by Amazon SQS.

SDK version number

@aws-sdk/[email protected]

Which JavaScript Runtime is this issue in?

Node.js

Details of the browser/Node.js/ReactNative version

v18.18.1

Reproduction Steps

Example code that worked in v3.427.0:

const sqsClient = new SQSClient();
const receiveMessageCommand = new ReceiveMessageCommand({
  MessageAttributeNames: ['All'],
  AttributeNames: ['SentTimestamp', 'ApproximateReceiveCount']
})

This works because AttributeNames is defined as:

AttributeNames?: (QueueAttributeName | string)[];

Observed Behavior

In v3.428.0 the code gives the following error because of the type definition to AttributeNames:

ReceiveMessageRequest.AttributeNames?: QueueAttributeName[] | undefined

Expected Behavior

The provided example should work in both v3.427.0 and v3.428.0.

Possible Solution

The quick fix is to update AttributeNames to accept an Array of both MessageSystemAttributeName and QueueAttributeName i.e define it as AttributeNames?: (QueueAttributeName | MessageSystemAttributeName)[];

The longer fix might requiring updating every place that uses Attribute names to allow using MessageSystemAttributeName, QueueAttributeName, or both.

Additional Information/Context

No response

baumac avatar Oct 23 '23 10:10 baumac

@kuhe tagging you as this closely relates to https://github.com/aws/aws-sdk-js-v3/issues/5387

baumac avatar Oct 23 '23 10:10 baumac

Related: https://github.com/aws/aws-sdk/issues/623

yenfryherrerafeliz avatar Oct 23 '23 13:10 yenfryherrerafeliz

We want the service to update their model (@yenfryherrerafeliz has an internal ticket open and will relay updates), which generates the types here. Please use a typecast as a workaround until then.

We will not likely go back to using open enums, since it is too loose for most models, even though it unfortunately breaks this use case.

kuhe avatar Oct 23 '23 18:10 kuhe

Hello @baumac - I just wanted to follow up here with an update that we're still waiting on a fix from service team and it's currently being worked on (ref: V1073281478). In the meantime, please refer to the workaround mentioned above. Feel free to check back in for updates in the near future.

Thanks, John

aBurmeseDev avatar Nov 14 '23 22:11 aBurmeseDev

@aBurmeseDev Is there an estimation on when this issue is going to be fixed? It prevents us from upgrading above version 3.428.0

dormesica avatar Dec 10 '23 15:12 dormesica

Hi @dormesica - thanks for checking in. Upon checking, I don't see any new updates from the service team but I reached out asking if there's any update they can provide. Meanwhile, please use a typecast as workaround mentioned above. I'll check back in when I hear back.

aBurmeseDev avatar Jan 04 '24 01:01 aBurmeseDev

@aBurmeseDev any updates one this?

renarsvilnis avatar Feb 21 '24 19:02 renarsvilnis

Hi everyone - thank you all for your patience. I wanted to share an update that the fix has now been released by service team as of last week and I was able to confirm it with latest version of SDK.

cc: @baumac @renarsvilnis @dormesica

aBurmeseDev avatar May 14 '24 18:05 aBurmeseDev

@aBurmeseDev is it there as of 3.576.0 version (seeing still the issue) or it's going to the next release?

Our code Screenshot 2024-05-14 at 22 52 38

Library types Screenshot 2024-05-14 at 22 51 39

renarsvilnis avatar May 14 '24 19:05 renarsvilnis

@renarsvilnis per the JSDoc comment, the AttributeNames property has been deprecated and you should use the MessageSystemAttributeNames property which is of type MessageSystemAttributeName[]. The MessageSystemAttributeName enum should contain all the attributes you are looking for.

export declare const MessageSystemAttributeName: {
    readonly AWSTraceHeader: "AWSTraceHeader";
    readonly All: "All";
    readonly ApproximateFirstReceiveTimestamp: "ApproximateFirstReceiveTimestamp";
    readonly ApproximateReceiveCount: "ApproximateReceiveCount";
    readonly DeadLetterQueueSourceArn: "DeadLetterQueueSourceArn";
    readonly MessageDeduplicationId: "MessageDeduplicationId";
    readonly MessageGroupId: "MessageGroupId";
    readonly SenderId: "SenderId";
    readonly SentTimestamp: "SentTimestamp";
    readonly SequenceNumber: "SequenceNumber";
};

baumac avatar May 21 '24 20:05 baumac

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread.

github-actions[bot] avatar Jun 06 '24 00:06 github-actions[bot]