SQSメッセージ受信時に送信時刻を含めて取得する

SQSからメッセージ受信時に送信時刻も含めて取得するサンプルです

### デフォルト（送信時刻は含まれない)

```golang:main.go
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"

	"os"
)

func main() {
	session := session.Must(session.NewSession(&aws.Config{Region: aws.String("ap-northeast-1")}))
	sqsSvc := sqs.New(session)
	queueURL := aws.String(os.Getenv("SQS_URL"))
	params := &sqs.ReceiveMessageInput{
		QueueUrl:            queueURL,
		MaxNumberOfMessages: aws.Int64(1),
		VisibilityTimeout:   aws.Int64(60),
		WaitTimeSeconds:     aws.Int64(20),
	}
	resp, _ := sqsSvc.ReceiveMessage(params)
	fmt.Printf("%s¥n", resp)
}
```

#### 実行&結果

```terminal
$ export SQS_URL=https://sqs.ap-northeast-1.amazonaws.com/123456789012/hogequeue
$ go run main.go
{
  Messages: [{
      Body: "test",
      MD5OfBody: "d8e8fca2dc0f896fd7cb4cb0031ba249",
      MessageId: "6d5b0fbb-5531-48bc-854b-5fa5fe46cd9f",
      ReceiptHandle: "AQEBPAuuJWCVY5s9+zuzlfB6NyiKuTnr3dnW3qcEWPRBm8pkQdoT9eB8DkI0Knk51Krq8s/HJzYn4ano0jrK0g4vf2HwJ61Wu9hUey+n6hPyvuzfv/ciqpawZ0JgN3NAErUMGWJgv/8ZdvA65s7n7/5gylXQS+eG7adM+OJhFw696p4FPLyYrX/9bBX2CLIq38u5Lb6AelYx/G6CaniJxaiApPZyLPyGa0PDRP4yjHO/eToMQLob31TRGZTfV//f26eIXyfH735MkUMIw3CcgkWmlD8uoMwVuo5K/6Bqj3UTi9WLuw4rzsyr3TxammKQKCx6"
    }]
}
```

### 送信時刻指定

```golang:main.go
package main

import (
	"fmt"
	"strconv"
	"time"

	"github.com/aws/aws-sdk-go/aws"
	"github.com/aws/aws-sdk-go/aws/session"
	"github.com/aws/aws-sdk-go/service/sqs"

	"os"
)

func main() {
	session := session.Must(session.NewSession(&aws.Config{Region: aws.String("ap-northeast-1")}))
	sqsSvc := sqs.New(session)
	queueURL := aws.String(os.Getenv("SQS_URL"))
	params := &sqs.ReceiveMessageInput{
		QueueUrl:            queueURL,
		MaxNumberOfMessages: aws.Int64(1),
		VisibilityTimeout:   aws.Int64(60),
		WaitTimeSeconds:     aws.Int64(20),
		AttributeNames:      aws.StringSlice([]string{"SentTimestamp"}),
	}
	resp, _ := sqsSvc.ReceiveMessage(params)
	fmt.Printf("%s\n", resp)
	sentTs, _ := strconv.ParseInt(*resp.Messages[0].Attributes["SentTimestamp"], 10, 64)
	fmt.Printf("%s\n", time.Unix(sentTs/1000, 0))
}
```

#### 結果

```terminal
$ export SQS_URL=https://sqs.ap-northeast-1.amazonaws.com/123456789012/hogequeue
$ go run main.go
{
  Messages: [{
      Attributes: {
        SentTimestamp: "1583145040500"
      },
      Body: "test",
      MD5OfBody: "d8e8fca2dc0f896fd7cb4cb0031ba249",
      MessageId: "93248f73-b742-4390-ba17-e83720a1c98c",
      ReceiptHandle: "AQEB2CPd4+vtO9lmme5K6nWSzDtn8ryr5M8yaPeYB46IxoarcfHRvnHC23lMlG0MdcopA0v+jMO7KhPoXugNxDFUkBpDHzHUlLPfcdzupqO1K0JdbtznN62ZgDjXZbt6MzeNT0jpoC5E6FHWcljWkGvLGm9ozZVMMf5XkcXshIninIfB8lky1ArFzLua9rQCUdtqkSQt18bzZNDBSYdrdgq4t82lU0TnM8SIiIU1iGggeK1Wjqa6sDhJdGEvbax3pzV1BnQHSFfe5gsiMpqoi78bplnEN0mOS0Ysv+3BTXkTfPZnHIqZ+rJSZYEcjeVt29Fh"
    }]
}
2020-03-02 19:30:40 +0900 JST
```

`SentTimestamp: "1583145040500"` が増えてる！

### 解説

環境変数`SQS_URL`で指定したキューからメッセージを取得するコードです。
送信時刻を取得するには、ReceiveMessageInputにAttributeNames(`SentTimestamp`)を追加するだけです。

```diff
	params := &sqs.ReceiveMessageInput{
		QueueUrl:            queueURL,
		MaxNumberOfMessages: aws.Int64(1),
		VisibilityTimeout:   aws.Int64(60),
		WaitTimeSeconds:     aws.Int64(20),
+		AttributeNames:      aws.StringSlice([]string{"SentTimestamp"}),
	}
```

`SentTimestamp`の部分を`All`に変えると他にもいろいろ取得できます。 [公式リファレンス](https://docs.aws.amazon.com/es_es/sdk-for-go/v1/api/service.sqs.ReceiveMessageInput.html)
`SentTimestamp`で得られる値はエポックタイム(ミリ秒)なのでサンプルコードで示したようにtime.Unixで
変換すると使いやすいはず。
以上