📝
[小ネタ] SQS キュー作成時の仕様について
CreateQueue - Amazon Simple Queue Service
SQS キューの作成には以下の仕様があります。
- 既存のキューと同名のキューで作成してもエラーにはならない
- 既存のキューのキュー URL が返されるのみで上書きはされない
- 既存のキューと同名のキューで異なる設定値のキューは作成できない
- 削除したキューと同名のキューを作成する場合は最低 60 秒待つ必要がある
既存のキューと同名のキューで作成してもエラーにはならない
コンソール上で test というキューを作成しました。
この状態で再度 test というキューを作成してもエラーにはなりませんでした。
AWS CLI でもエラーにならず、キュー URL が返されることを確認できました。
$ aws sqs create-queue \/
--queue-name test
{
"QueueUrl": "https://sqs.ap-northeast-1.amazonaws.com/012345678901/test"
}
既存のキューと同名のキューで異なる設定値のキューは作成できない
test キューがある状態で可視性タイムアウトの値のみ 29 秒に変更したキューの作成を試みます。
既存のキューと同名で設定値が異なるためエラーが発生しました。
QueueNameExists: A queue already exists with the same name and a different value for attribute VisibilityTimeout
AWS CLI でも同様のエラーが発生しました。
$ aws sqs create-queue --queue-name test \
--attributes VisibilityTimeout=29
An error occurred (QueueAlreadyExists) when calling the CreateQueue operation: A queue already exists with the same name and a different value for attribute VisibilityTimeout
削除したキューと同名のキューを作成する場合は最低 60 秒待つ必要がある
test キューを削除後、60 秒以内に再度 test キューの作成を試みます。
60 秒待機する必要がある旨のエラーが発生しました。
QueueDeletedRecently: You must wait 60 seconds after deleting a queue before you can create another with the same name.
AWS CLI でも同様のエラーが発生しました。
$ aws sqs create-queue \
--queue-name test
An error occurred (AWS.SimpleQueueService.QueueDeletedRecently) when calling the CreateQueue operation: You must wait 60 seconds after deleting a queue before you can create another with the same name.
以上より、ドキュメントに記載通りの挙動であることを確認できました。
まとめ
今回は SQS キュー作成時の仕様について紹介しました。
どなたかの参考になれば幸いです。
Discussion