Skip to content

Instantly share code, notes, and snippets.

@abdul
Forked from lobster1234/localstack.md
Created August 10, 2017 20:27
Show Gist options
  • Save abdul/acdfd0130d1f99ce737a4afe02875e98 to your computer and use it in GitHub Desktop.
Save abdul/acdfd0130d1f99ce737a4afe02875e98 to your computer and use it in GitHub Desktop.

Revisions

  1. @lobster1234 lobster1234 revised this gist Apr 5, 2017. 1 changed file with 11 additions and 0 deletions.
    11 changes: 11 additions & 0 deletions localstack.md
    Original file line number Diff line number Diff line change
    @@ -49,6 +49,17 @@ upload: ../../../../tmp/mongo.log to s3://mytestbucket/mongo.log
    C02STG51GTFM:localstack mpandit$ aws --endpoint-url=http://localhost:4572 s3 ls s3://mytestbucket
    2017-04-05 01:18:39 4789 mongo.log
    ```
    ### Delete this file

    ```
    C02STG51GTFM:localstack mpandit$ aws --endpoint-url=http://localhost:4572 s3 rm s3://mytestbucket/mongo.log
    delete: s3://mytestbucket/mongo.log
    C02STG51GTFM:localstack mpandit$ aws --endpoint-url=http://localhost:4572 s3 ls s3://mytestbucket
    C02STG51GTFM:localstack mpandit$
    ```


    ## SNS

  2. @lobster1234 lobster1234 revised this gist Apr 5, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion localstack.md
    Original file line number Diff line number Diff line change
    @@ -75,7 +75,7 @@ C02STG51GTFM:localstack mpandit$ aws --endpoint-url=http://localhost:4575 sns li
    ```
    ### Subscribe to the topic

    (Get a temp email address from any of the temp email sites)
    (use any random email)

    ```
    C02STG51GTFM:localstack mpandit$ aws --endpoint-url=http://localhost:4575 sns subscribe --topic-arn arn:aws:sns:us-east-1:123456789012:test-topic --protocol email --notification-endpoint [email protected]
  3. @lobster1234 lobster1234 revised this gist Apr 5, 2017. 1 changed file with 64 additions and 1 deletion.
    65 changes: 64 additions & 1 deletion localstack.md
    Original file line number Diff line number Diff line change
    @@ -97,7 +97,7 @@ C02STG51GTFM:localstack mpandit$ aws --endpoint-url=http://localhost:4575 sns li
    }
    ```
    ### Publish
    ### Publish to this topic

    ```
    C02STG51GTFM:localstack mpandit$ aws --endpoint-url=http://localhost:4575 sns publish --topic-arn arn:aws:sns:us-east-1:123456789012:test-topic --message 'Test Message!'
    @@ -108,3 +108,66 @@ C02STG51GTFM:localstack mpandit$ aws --endpoint-url=http://localhost:4575 sns pu

    ## SQS

    ### Create a Queue
    ```
    C02STG51GTFM:localstack mpandit$ aws --endpoint-url=http://localhost:4576 sqs create-queue --queue-name test_queue
    {
    "QueueUrl": "http://localhost:4576/123456789012/test_queue"
    }
    C02STG51GTFM:localstack mpandit$ aws --endpoint-url=http://localhost:4576 sqs list-queues
    {
    "QueueUrls": [
    "http://localhost:4576/123456789012/test_queue"
    ]
    }
    ```
    ### Send a message to this queue
    ```
    C02STG51GTFM:localstack mpandit$ aws --endpoint-url=http://localhost:4576 sqs send-message --queue-url http://localhost:4576/123456789012/test_queue --message-body 'Test Message!'
    {
    "MD5OfMessageBody": "df69267381a60e476252c989db9ac8ad",
    "MessageId": "a6ed436b-076a-0d8d-73e1-cc3291a19c28"
    }
    ```
    ### Receive the message from this queue
    ```
    C02STG51GTFM:localstack mpandit$ aws --endpoint-url=http://localhost:4576 sqs receive-message --queue-url http://localhost:4576/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:4576 sqs delete-message --queue-url http://localhost:4576/123456789012/test_queue --receipt-handle 'yugzzebhnnksfuvbjlibfnlejyqbulxqfegsnrgafjeabxaatxbmeiyfkfliedslohseosgjwkxhdzllpudhccjhorpkwbgjgyzeyzjwkfvqflathnvsmugeyevbqmfyqanuxetvdhcetseuwzrqpexogzggznndxmbqowtlalvqtffntdahhihel'
    ```
  4. @lobster1234 lobster1234 created this gist Apr 5, 2017.
    110 changes: 110 additions & 0 deletions localstack.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,110 @@
    # Starting localstack

    ```
    C02STG51GTFM:localstack mpandit$ make infra
    . .venv/bin/activate; exec localstack/mock/infra.py
    Starting local dev environment. CTRL-C to quit.
    Starting local Elasticsearch (port 4571)...
    Starting mock ES service (port 4578)...
    Starting mock S3 server (port 4572)...
    Starting mock SNS server (port 4575)...
    Starting mock SQS server (port 4576)...
    Starting mock API Gateway (port 4567)...
    Starting mock DynamoDB (port 4569)...
    Starting mock DynamoDB Streams (port 4570)...
    Starting mock Firehose (port 4573)...
    Starting mock Lambda (port 4574)...
    Starting mock Kinesis (port 4568)...
    Starting mock Redshift server (port 4577)...
    Ready.
    ```

    Optionally, start the web interface (make sure you pull the latest code, as there were node compatibility issues up until 3/31/2017)

    ```
    C02STG51GTFM:localstack mpandit$ make web
    (. .venv/bin/activate; bin/localstack web --port=8080)
    * Running on http://0.0.0.0:8080/ (Press CTRL+C to quit)
    * Restarting with stat
    * Debugger is active!
    * Debugger PIN: 272-228-949
    ```

    ## S3

    ### Create a bucket
    ```
    C02STG51GTFM:localstack mpandit$ aws --endpoint-url=http://localhost:4572 s3 mb s3://mytestbucket
    make_bucket: mytestbucket
    C02STG51GTFM:localstack mpandit$ aws --endpoint-url=http://localhost:4572 s3 ls
    2006-02-03 08:45:09 mytestbucket
    ```

    ### Copy a file over
    ```
    C02STG51GTFM:localstack mpandit$ aws --endpoint-url=http://localhost:4572 s3 cp /tmp/mongo.log s3://mytestbucket
    upload: ../../../../tmp/mongo.log to s3://mytestbucket/mongo.log
    C02STG51GTFM:localstack mpandit$ aws --endpoint-url=http://localhost:4572 s3 ls s3://mytestbucket
    2017-04-05 01:18:39 4789 mongo.log
    ```

    ## SNS

    ### Create a topic
    ```
    C02STG51GTFM:localstack mpandit$ aws --endpoint-url=http://localhost:4575 sns list-topics
    {
    "Topics": []
    }
    C02STG51GTFM:localstack mpandit$ aws --endpoint-url=http://localhost:4575 sns create-topic --name test-topic
    {
    "TopicArn": "arn:aws:sns:us-east-1:123456789012:test-topic"
    }
    C02STG51GTFM:localstack mpandit$ aws --endpoint-url=http://localhost:4575 sns list-topics
    {
    "Topics": [
    {
    "TopicArn": "arn:aws:sns:us-east-1:123456789012:test-topic"
    }
    ]
    }
    ```
    ### Subscribe to the topic

    (Get a temp email address from any of the temp email sites)

    ```
    C02STG51GTFM:localstack mpandit$ aws --endpoint-url=http://localhost:4575 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"
    }
    C02STG51GTFM:localstack mpandit$ aws --endpoint-url=http://localhost:4575 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

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

    ## SQS