How to Use AWS SQS from Go

Use the AWS SDK for Go v2 to initialize an SQS client and send or receive messages from a queue URL.

Use the AWS SDK for Go v2 to create an SQS client, then call SendMessage or ReceiveMessage with your queue URL and message body.

package main

import (
	"context"
	"fmt"
	"log"

	"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"
)

func main() {
	cfg, err := config.LoadDefaultConfig(context.TODO())
	if err != nil {
		log.Fatalf("unable to load SDK config: %v", err)
	}

	client := sqs.NewFromConfig(cfg)

	result, err := client.SendMessage(context.TODO(), &sqs.SendMessageInput{
		QueueUrl: aws.String("https://sqs.us-east-1.amazonaws.com/123456789012/MyQueue"),
		MessageBody: aws.String("Hello from Go"),
	})
	if err != nil {
		log.Fatalf("unable to send message: %v", err)
	}

	fmt.Println("Message sent:", *result.MessageId)
}