sqs_sendmessage.go - AWS Code Sample


Sends a message to an SQS queue.

/* Copyright 2010-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. This file is licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with the License. A copy of the License is located at http://aws.amazon.com/apache2.0/ This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ package main import ( "fmt" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/sqs" ) // Usage: // go run sqs_sendmessage.go func main() { sess := session.Must(session.NewSessionWithOptions(session.Options{ SharedConfigState: session.SharedConfigEnable, })) svc := sqs.New(sess) // URL to our queue qURL := "QueueURL" result, err := svc.SendMessage(&sqs.SendMessageInput{ DelaySeconds: aws.Int64(10), MessageAttributes: map[string]*sqs.MessageAttributeValue{ "Title": &sqs.MessageAttributeValue{ DataType: aws.String("String"), StringValue: aws.String("The Whistler"), }, "Author": &sqs.MessageAttributeValue{ DataType: aws.String("String"), StringValue: aws.String("John Grisham"), }, "WeeksOn": &sqs.MessageAttributeValue{ DataType: aws.String("Number"), StringValue: aws.String("6"), }, }, MessageBody: aws.String("Information about current NY Times fiction bestseller for week of 12/11/2016."), QueueUrl: &qURL, }) if err != nil { fmt.Println("Error", err) return } fmt.Println("Success", *result.MessageId) }

Sample Details

Service: sqs

Last tested: 2018-03-16

Author: Doug-AWS

Type: full-example