Code Monkey home page Code Monkey logo

docker-localstack-hello's Introduction

localstack-sdx

Local Amazon Web Services (AWS)

Requirements

  • Docker
  • Docker Compose
  • Python 3

Setup

AWS CLI V2

After installation if using Git Bash:

# ~/.bashrc
alias aws="/c/'Program Files'/Amazon/AWSCLIV2/aws.exe"

AWS Local CLI

Github

Create a Python virtual environment:

python -m venv venv

Activate environment:

On windows

source venv/Scripts/activate

On Linux

source venv/bin/activate

Install deps:

pip install -r requirements.txt

Usage

Configure aws cli:

aws configure --profile localstack

AWS Access Key ID [None]: test

AWS Secret Access Key [None]: test

Default region name [None]: us-east-1

Default output format [None]:

Run Localstack:

docker-compose up localstack
  • Check Services Health: http://localhost:4566/health

  • In docker shell command:

    awslocal --endpoint-url=http://host.docker.internal:4566 s3 ls
  • In docker's host shell command:

    awslocal --endpoint-url=http://localhost:4566 s3 ls

S3

  • Create a S3 Bucket:

    awslocal --endpoint-url=http://localhost:4566 s3 mb s3://user-uploads
    # Output: make_bucket: user-uploads
  • Confirm that Bucket exists:

    awslocal --endpoint-url=http://localhost:4566 s3 ls
    # Output: 2022-03-25 13:36:46 user-uploads
  • Create folder:

    awslocal --endpoint-url=http://localhost:4566 s3api put-object --bucket user-uploads --key lambda
    # Output:
    # {
    #    "ETag": "\"d41d8cd98f00b204e9800998ecf8427e\""
    # }
  • List Buckets:

    awslocal --endpoint-url=http://localhost:4566 s3api list-buckets
  • Copy files to bucket:

    awslocal --endpoint-url=http://localhost:4566 s3 cp ./samples/lambda/ s3://user-uploads/lambda/ --recursive

SQS

  • Create an SQS queue named test-queue:

    awslocal sqs create-queue --queue-name test-queue
    # Output:
    # {
    #    "QueueUrl": "http://localhost:4566/000000000000/test-queue"
    # }
  • Send a message to the SQS created above:

    awslocal sqs send-message --queue-url http://localhost:4566/000000000000/test-queue --message-body "test message." --delay-seconds 0
    # Output:
    # {
    #     "MD5OfMessageBody": "5cbd04aaf0430ff7fac38ebd11b72083",
    #     "MessageId": "3a110fce-513c-b6f2-6059-05e145fe60db"
    # }
  • Receive the sent message from the SQS:

    awslocal sqs receive-message --queue-url http://localhost:4566/000000000000/test-queue --attribute-names All --message-attribute-names All
    # Output:
    # {
    #     "Messages": [
    #         {
    #             "MessageId": "3a110fce-513c-b6f2-6059-05e145fe60db",
    #             "ReceiptHandle": "uzbggdbobhtkovufriitjvjvrhfdemzqsgluxmohpuxjudarizabcmihywrvvfmmywamuogkhflgbtcpmlesijjeqviorfjwkooppbzqokazqkxhzciqbeiwvvtqqjamoxjmxuviwstjfuoqxafpdntlakygqkefzssemqzbvvkmlinznphlvoepn",
    #             "MD5OfBody": "5cbd04aaf0430ff7fac38ebd11b72083",
    #             "Body": "test message.",
    #             "Attributes": {
    #                 "SenderId": "AIDAIT2UOQQY3AUEKVGXU",
    #                 "SentTimestamp": "1648234565152",
    #                 "ApproximateReceiveCount": "1",
    #                 "ApproximateFirstReceiveTimestamp": "1648234611377"
    #             }
    #         }
    #     ]
    # }

Lambda

  • Create a lambda function named test-function:

    awslocal lambda create-function --function-name test-function --runtime python3.7 --zip-file fileb://test.zip --handler test.lambda_handler --role test

API Gateway

  • Create the api gateway called test-api:

    awslocal apigateway create-rest-api --name test-api
    # Output:
    # {
    #     "id": "br4h590g45",
    #     "name": "test-api",
    #     "createdDate": 1648235267,
    #     "version": "V1",
    #     "binaryMediaTypes": [],
    #     "apiKeySource": "HEADER",
    #     "endpointConfiguration": {
    #         "types": [
    #             "EDGE"
    #         ]
    #     },
    #     "tags": {},
    #     "disableExecuteApiEndpoint": false
    # }

Secrets manager

  • Create a secret named localstack-secret in secrets manager:

    awslocal --endpoint=http://localhost:4566 secretsmanager create-secret \
      --name test-secret \
       --description "This is secret" \
       --secret-string "Some secret" \
       --region=us-east-1
    # Output:
    # {
    #     "ARN": "arn:aws:secretsmanager:us-east-1:000000000000:secret:test-secret-d55114",
    #     "Name": "test-secret",
    #     "VersionId": "0072b882-3871-48e1-a40a-072ff354dcf5"
    # }
  • Get secret:

awslocal --endpoint=http://localhost:4566 secretsmanager get-secret-value \
  --secret-id test-secret

AWS CLI

  • Version:

    docker run --rm -it amazon/aws-cli --version
  • Check buckets:

    docker run --rm -it -v ~/.aws:/root/.aws amazon/aws-cli command
    docker run  \
          -e AWS_ACCESS_KEY_ID=test \
          -e AWS_SECRET_ACCESS_KEY=test \
          -e AWS_DEFAULT_REGION=us-east-1 \
          --rm \
          amazon/aws-cli --endpoint-url=http://host.docker.internal:4566 s3 ls

References

docker-localstack-hello's People

Contributors

dmenezesgabriel avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.