Skip to content

Instantly share code, notes, and snippets.

@dmalberto
Forked from lobster1234/localstack.md
Last active December 30, 2021 14:25
Show Gist options
  • Save dmalberto/9f742e04c53ee1c817325babd51cb8e4 to your computer and use it in GitHub Desktop.
Save dmalberto/9f742e04c53ee1c817325babd51cb8e4 to your computer and use it in GitHub Desktop.
Working with localstack on command line

S3

Create a bucket

aws --endpoint-url=http://localhost:4566 s3 mb s3://mytestbucket
make_bucket: mytestbucket

aws --endpoint-url=http://localhost:4566 s3 ls
2006-02-03 08:45:09 mytestbucket

Copy a file over

aws --endpoint-url=http://localhost:4566 s3 cp /tmp/mongo.log s3://mytestbucket
upload: ../../../../tmp/mongo.log to s3://mytestbucket/mongo.log

aws --endpoint-url=http://localhost:4566 s3 ls s3://mytestbucket
2017-04-05 01:18:39       4789 mongo.log

Delete this file

aws --endpoint-url=http://localhost:4566 s3 rm s3://mytestbucket/mongo.log
delete: s3://mytestbucket/mongo.log

aws --endpoint-url=http://localhost:4566 s3 ls s3://mytestbucket


SNS

Create a topic

aws --endpoint-url=http://localhost:4566 sns list-topics
{
    "Topics": []
}

aws --endpoint-url=http://localhost:4566 sns create-topic --name test-topic
{
    "TopicArn": "arn:aws:sns:us-east-1:123456789012:test-topic"
}
aws --endpoint-url=http://localhost:4566 sns list-topics
{
    "Topics": [
        {
            "TopicArn": "arn:aws:sns:us-east-1:123456789012:test-topic"
        }
    ]
}

Subscribe to the topic

(use any random email)

aws --endpoint-url=http://localhost:4566 sns subscribe --topic-arn arn:aws:sns:us-east-1:123456789012:test-topic --protocol email --notification-endpoint [email protected]
{
    "SubscriptionArn": "arn:aws:sns:us-east-1:123456789012:test-topic:5aacffbe-ccf7-40d5-be97-c55af7392935"
}

aws --endpoint-url=http://localhost:4566 sns list-subscriptions
{
    "Subscriptions": [
        {
            "Owner": "", 
            "Endpoint": "[email protected]", 
            "Protocol": "email", 
            "TopicArn": "arn:aws:sns:us-east-1:123456789012:test-topic", 
            "SubscriptionArn": "arn:aws:sns:us-east-1:123456789012:test-topic:5aacffbe-ccf7-40d5-be97-c55af7392935"
        }
    ]
}

Publish to this topic

aws --endpoint-url=http://localhost:4566 sns publish  --topic-arn arn:aws:sns:us-east-1:123456789012:test-topic --message 'Test Message!'
{
    "MessageId": "n/a"
}

SQS

Create a Queue

aws --endpoint-url=http://localhost:4566 sqs create-queue --queue-name test_queue
{
    "QueueUrl": "http://localhost:4566/123456789012/test_queue"
}

aws --endpoint-url=http://localhost:4566 sqs list-queues
{
    "QueueUrls": [
        "http://localhost:4566/123456789012/test_queue"
    ]
}

Send a message to this queue

 aws --endpoint-url=http://localhost:4566 sqs send-message --queue-url http://localhost:4566/123456789012/test_queue --message-body 'Test Message!'
{
    "MD5OfMessageBody": "df69267381a60e476252c989db9ac8ad", 
    "MessageId": "a6ed436b-076a-0d8d-73e1-cc3291a19c28"
}

Receive the message from this queue

 aws --endpoint-url=http://localhost:4566 sqs receive-message --queue-url http://localhost:4566/123456789012/test_queue
{
    "Messages": [
        {
            "Body": "Test Message!", 
            "Attributes": {
                "ApproximateFirstReceiveTimestamp": "1.49138149959e+12", 
                "SenderId": "AIDAIT2UOQQY3AUEKVGXU", 
                "ApproximateReceiveCount": "1", 
                "SentTimestamp": "1.49138142195e+12"
            }, 
            "ReceiptHandle": "xuazrzyjcgpgzpzlxlyxmujbgzfkswixjkywshturlylrfwzyccutlumitgduyzddwkaoypcmswlkxrrjghdyztfewrpmkxdufptyketrfumwzicmggogdbaucwztvorplibccpfhirmalnixvfbklzrgncpisdsiuiajqwefxueqhuygfibmgqwx", 
            "MD5OfBody": "df69267381a60e476252c989db9ac8ad", 
            "MessageId": "a6ed436b-076a-0d8d-73e1-cc3291a19c28"
        }
    ]
}

If you do this many times, the process seems to sleep. May be to simulate the message visibility? Here are 2 consecutive runs.

real	0m15.185s
user	0m0.291s
sys	0m0.158s
real	0m26.829s
user	0m0.291s
sys	0m0.167s

Delete this message

aws --endpoint-url=http://localhost:4566 sqs delete-message --queue-url http://localhost:4566/123456789012/test_queue --receipt-handle 'yugzzebhnnksfuvbjlibfnlejyqbulxqfegsnrgafjeabxaatxbmeiyfkfliedslohseosgjwkxhdzllpudhccjhorpkwbgjgyzeyzjwkfvqflathnvsmugeyevbqmfyqanuxetvdhcetseuwzrqpexogzggznndxmbqowtlalvqtffntdahhihel'

Delete all messages

aws sqs --endpoint-url=http://localhost:4566 purge-queue --queue-url http://localhost:4566/000000000000/test_queue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment