Skip to content

kamataryo/sandbox-amazon-sqs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 

Repository files navigation

My Amazon SQS samples

Create queue

$ aws sqs create-queue --queue-name my-test-queue --attributes ReceiveMessageWaitTimeSeconds=20
{
    "QueueUrl": "https://ap-northeast-1.queue.amazonaws.com/000000000000/my-test-queue"
}

List queues

$ aws sqs list-queues
{
    "QueueUrls": [
        "https://ap-northeast-1.queue.amazonaws.com/000000000000/my-test-queue"
    ]
}

Get queue URL

$ QUEUE_URL=$(aws sqs get-queue-url --queue-name my-test-queue |  npx jqf --raw-string-output 'x => x.QueueUrl')

Send message

$ aws sqs send-message --queue-url $QUEUE_URL --message-body '{"hello":"SQS"}'
{
    "MD5OfMessageBody": "23759ae80d00f2b3e9c5eb026b74fdd8",
    "MessageId": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
}

Receive message

$ aws sqs receive-message --queue-url $QUEUE_URL
{
    "Messages": [
        {
            "MessageId": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
            "ReceiptHandle": "<base 64 value>",
            "MD5OfBody": "23759ae80d00f2b3e9c5eb026b74fdd8",
            "Body": "{\"hello\":\"SQS\"}"
        }
    ]
}

Delete message

$ aws sqs delete-message --receipt-handle "<base 64 value>" --queue-url $QUEUE_URL

Receive message when polling

# shell A
$ QUEUE_URL=$(aws sqs get-queue-url --queue-name my-test-queue |  npx jqf --raw-string-output 'x => x.QueueUrl')
$ aws sqs receive-message --queue-url $QUEUE_URL
# shell B
QUEUE_URL=$(aws sqs get-queue-url --queue-name my-test-queue |  npx jqf --raw-string-output 'x => x.QueueUrl')
$ aws sqs send-message --queue-url $QUEUE_URL --message-body '{"hello":"SQS"}'

Delete queue

$ aws sqs delete-queue --queue-url $QUEUE_URL

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published