aws-sdk-go-v2 icon indicating copy to clipboard operation
aws-sdk-go-v2 copied to clipboard

SQS ReceiveMessageInput.AttributeNames should be of type MessageSystemAttributeName

Open denniscfeng opened this issue 2 years ago • 2 comments

Describe the bug

In the SQS API, the ReceiveMessageInput field AttributeNames should be of type []types.MessageSystemAttributeName instead of []types.QueueAttributeName

https://github.com/aws/aws-sdk-go-v2/blob/main/service/sqs/api_op_ReceiveMessage.go#L96

The documentation indicates the possible fields that can be listed in this argument include ApproximateFirstReceiveTimestamp, ApproximateReceiveCount, SentTimestamp, etc. But those are contained in the type MessageSystemAttributeName, whereas the QueueAttributeName type contains attributes pertaining to the whole queue rather than metadata pertaining to individual messages (MaximumMessageSize, MessageRetentionPeriod, QueueArn).

This prevents us from requesting specific message attributes to be returned with each SQS message.

Expected Behavior

ReceiveMessage should be able to accept a ReceiveMessageInput that includes a list of Attributes that we want to receive with each message. These attributes have been enumerated in types.MessageSystemAttributeName.

Desired:

...
client.ReceiveMessage(ctx, &sqs.ReceiveMessageInput{
		QueueUrl:              aws.String(endpoint),
		WaitTimeSeconds:       5,
		VisibilityTimeout:     10,
		MaxNumberOfMessages:   10,
		MessageAttributeNames: []string{"All"},
		AttributeNames:        []types.MessageSystemAttributeName{types.MessageSystemAttributeNameApproximateReceiveCount},
	})
...

Current Behavior

Cannot use '[]types.MessageSystemAttributeName{types.MessageSystemAttributeNameApproximateReceiveCount}' (type []types.MessageSystemAttributeName) as type []types.QueueAttributeName

Reproduction Steps

package test

import (
	"context"
	"github.com/aws/aws-sdk-go-v2/aws"
	"github.com/aws/aws-sdk-go-v2/config"
	"github.com/aws/aws-sdk-go-v2/service/sqs"
	"github.com/aws/aws-sdk-go-v2/service/sqs/types"
	"testing"
)

func Test(t *testing.T)  {
	cfg, err := config.LoadDefaultConfig(
		context.TODO(),
		config.WithRegion("us-west2"),
	)
	if err != nil {
		t.Fail()
	}
	
	sqsClient := sqs.NewFromConfig(cfg)
	_, _ = sqsClient.ReceiveMessage(context.TODO(), &sqs.ReceiveMessageInput{
		QueueUrl:              aws.String("queue url"),
		WaitTimeSeconds:       5,
		VisibilityTimeout:     10,
		MaxNumberOfMessages:   10,
		MessageAttributeNames: []string{"All"},
		AttributeNames:        []types.MessageSystemAttributeName{types.MessageSystemAttributeNameApproximateReceiveCount},
	})
}

Possible Solution

Change the type of ReceiveMessageInput.AttributeNames from []types.QueueAttributeName to []types.MessageSystemAttributeName

Additional Information/Context

No response

AWS Go SDK V2 Module Versions Used

        github.com/aws/aws-sdk-go v1.39.1
        github.com/aws/aws-sdk-go-v2 v1.18.0
        github.com/aws/aws-sdk-go-v2/config v1.18.22
        github.com/aws/aws-sdk-go-v2/service/sqs v1.22.0
        github.com/aws/aws-sdk-go-v2/credentials v1.13.21 // indirect
        github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.3 // indirect
        github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.33 // indirect
        github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.27 // indirect
        github.com/aws/aws-sdk-go-v2/internal/ini v1.3.34 // indirect
        github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.27 // indirect
        github.com/aws/aws-sdk-go-v2/service/sso v1.12.9 // indirect
        github.com/aws/aws-sdk-go-v2/service/ssooidc v1.14.9 // indirect
        github.com/aws/aws-sdk-go-v2/service/sts v1.18.10 // indirect
        github.com/aws/smithy-go v1.13.5 // indirect

Compiler and Version used

go version go1.17.13 darwin/amd64

Operating System and version

macOS Big Sur Version 11.7.6

denniscfeng avatar May 10 '23 22:05 denniscfeng

This does indeed look like a model issue (the type is correct but it should include all possible values in the QueueAttributeName enum in the model, which overlaps with MessageSystemAttrributeName) but you can workaround it for now by using the raw string values:

_, _ = sqsClient.ReceiveMessage(context.TODO(), &sqs.ReceiveMessageInput{
    ...
    AttributeNames: []types.QueueAttributeName{ types.QueueAttributeName("ApproximateReceiveCount") },
})

related: https://github.com/awslabs/aws-sdk-kotlin/issues/857#issuecomment-1440141886

aajtodd avatar May 11 '23 14:05 aajtodd

This seems like a really simple bug to fix...any plans on getting it fixed in a release at some point soon?

mwillfox avatar Apr 18 '24 15:04 mwillfox

This is now released https://github.com/aws/aws-sdk-go-v2/releases/tag/release-2024-05-08

RanVaknin avatar May 16 '24 19:05 RanVaknin

This issue is now closed. Comments on closed issues are hard for our team to see. If you need more assistance, please open a new issue that references this one.

github-actions[bot] avatar May 16 '24 19:05 github-actions[bot]