Local Amazon Web Services (AWS)
- Docker
- Docker Compose
- Python 3
After installation if using Git Bash:
# ~/.bashrc
alias aws="/c/'Program Files'/Amazon/AWSCLIV2/aws.exe"
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
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
-
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
-
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" # } # } # ] # }
-
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
-
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 # }
-
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
-
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