localstack on Mac #
Install #
https://docs.localstack.cloud/getting-started/installation/
% brew install localstack/tap/localstack-cli
% localstack --version
2.3.2
% localstack start -d
__ _______ __ __
/ / ____ _________ _/ / ___// /_____ ______/ /__
/ / / __ \/ ___/ __ `/ /\__ \/ __/ __ `/ ___/ //_/
/ /___/ /_/ / /__/ /_/ / /___/ / /_/ /_/ / /__/ ,<
/_____/\____/\___/\__,_/_//____/\__/\__,_/\___/_/|_|
๐ป LocalStack CLI 2.3.2
[10:57:13] starting LocalStack in Docker mode ๐ณ localstack.py:495
preparing environment bootstrap.py:1206
[10:57:14] configuring container bootstrap.py:1214
[10:57:19] starting container bootstrap.py:1224
[10:58:15] detaching bootstrap.py:122
% localstack status services
โโโโโโโโโโโโโโโโโโโโโโโโโโโโณโโโโโโโโโโโโโโ
โ Service โ Status โ
โกโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฉ
โ acm โ โ available โ
โ apigateway โ โ available โ
โ cloudformation โ โ available โ
โ cloudwatch โ โ available โ
โ config โ โ available โ
โ dynamodb โ โ available โ
โ dynamodbstreams โ โ available โ
โ ec2 โ โ available โ
โ es โ โ available โ
โ events โ โ available โ
โ firehose โ โ available โ
โ iam โ โ available โ
โ kinesis โ โ available โ
โ kms โ โ available โ
โ lambda โ โ available โ
โ logs โ โ available โ
โ opensearch โ โ available โ
โ ram โ โ available โ
โ redshift โ โ available โ
โ resource-groups โ โ available โ
โ resourcegroupstaggingapi โ โ available โ
โ route53 โ โ available โ
โ route53resolver โ โ available โ
โ s3 โ โ available โ
โ s3control โ โ available โ
โ scheduler โ โ available โ
โ secretsmanager โ โ available โ
โ ses โ โ available โ
โ sns โ โ available โ
โ sqs โ โ available โ
โ ssm โ โ available โ
โ stepfunctions โ โ available โ
โ sts โ โ available โ
โ support โ โ available โ
โ swf โ โ available โ
โ transcribe โ โ available โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโดโโโโโโโโโโโโโโ
% brew install awscli
% which aws
/usr/local/bin/aws
% aws --version
aws-cli/2.13.32 Python/3.11.6 Darwin/21.6.0 source/x86_64 prompt/off
% aws configure --profile localstack
AWS Access Key ID [None]: dummy
AWS Secret Access Key [None]: dummy
Default region name [None]: us-east-1
Default output format [None]: json
% cat ~/.aws/credentials
[localstack]
aws_access_key_id = dummy
aws_secret_access_key = dummy
% cat ~/.aws/config
[profile localstack]
region = us-east-1
output = json
SQS (Simple Queue Service) #
- ๆฆ่ฆ
- ใทในใใ ใใใกใใปใผใธใๅใๅใใไธๆ็ใซไฟๅญใใไธใงๅฆ็
- ๅคง้ใฎใกใใปใผใธใๅนณๆบๅใใฆ(ๅ็ญใชไฝๆฅญ้ใง)ๅฆ็ใใใใใฎใใใใก(็ทฉ่กๆ)ใจใใฆ
ใพใใฏใMicroservice้ใฎใฟในใฏใฎ้ๅๆๅฆ็ใจใใฆไฝฟ็จ - FIFO (First-In-First-Out)ใญใฅใผใไฝฟ็จใใใจใกใใปใผใธใฎ้ ๅบใไธ่ฒซๆงใไฟ่จผ
SQSใญใฅใผใฎไฝๆ
% aws sqs create-queue --queue-name test-queue --endpoint-url http://localhost:4566 --profile localstack
SQSใญใฅใผใฎไธ่ฆง
% aws sqs list-queues --endpoint-url http://localhost:4566 --profile localstack
{
"QueueUrl": "http://localhost:4566/000000000000/test-queue"
}
SQSใญใฅใผใฎๅฑๆง
SQSใญใฅใผใฎๅฑๆง
% aws sqs get-queue-attributes --queue-url http://localhost:4566/000000000000/test-queue --attribute-names All --endpoint-url http://localhost:4566 --profile localstack
{
"Attributes": {
"ApproximateNumberOfMessages": "0",
"ApproximateNumberOfMessagesNotVisible": "0",
"ApproximateNumberOfMessagesDelayed": "0",
"CreatedTimestamp": "1693055519",
"DelaySeconds": "0",
"LastModifiedTimestamp": "1693055519",
"MaximumMessageSize": "262144",
"MessageRetentionPeriod": "345600",
"QueueArn": "arn:aws:sqs:us-east-1:000000000000:test-queue",
"ReceiveMessageWaitTimeSeconds": "0",
"VisibilityTimeout": "30",
"SqsManagedSseEnabled": "false"
}
}
SQSใญใฅใผใธใกใใปใผใธใ้ไฟก
% aws sqs send-message --queue-url "http://localhost:4566/000000000000/test-queue" --message-body "hello sqs" --endpoint-url http://localhost:4566 --profile localstack
{
"MD5OfMessageBody": "3b7bef57d06c0021d0aafe8f6d587241",
"MessageId": "24b091c2-63fa-4814-bb84-30ff1930f5fd"
}
SQSใญใฅใผใฎ็พๅจใฎใกใใปใผใธๆฐใ็ขบ่ช
% aws sqs get-queue-attributes --queue-url 'http://localhost:4566/000000000000/test-queue' --attribute-names ApproximateNumberOfMessages --query 'Attributes.ApproximateNumberOfMessages' --endpoint-url http://localhost:4566 --profile localstack
"1"
SQSใญใฅใผใฎๆถ่ฒป
% aws sqs receive-message --queue-url 'http://localhost:4566/000000000000/test-queue' --endpoint-url http://localhost:4566 --profile localstack
{
"Messages": [
{
"MessageId": "24b091c2-63fa-4814-bb84-30ff1930f5fd",
"ReceiptHandle": "YzNjMDIzZTEtNTBkZC00NmE5LTg3NmItYTYxOTI3YzE3MWIzIGFybjphd3M6c3FzOnVzLWVhc3QtMTowMDAwMDAwMDAwMDA6dGVzdC1xdWV1ZSAyNGIwOTFjMi02M2ZhLTQ4MTQtYmI4NC0zMGZmMTkzMGY1ZmQgMTY5MzA1NTk5MC42ODAyMTQ2",
"MD5OfBody": "3b7bef57d06c0021d0aafe8f6d587241",
"Body": "hello sqs"
}
]
}
SQSใญใฅใผใฎใกใใปใผใธใๅ้ค
% aws sqs delete-message --queue-url 'http://localhost:4566/000000000000/test-queue' --receipt-handle "YzNjMDIzZTEtNTBkZC00NmE5LTg3NmItYTYxOTI3YzE3MWIzIGFybjphd3M6c3FzOnVzLWVhc3QtMTowMDAwMDAwMDAwMDA6dGVzdC1xdWV1ZSAyNGIwOTFjMi02M2ZhLTQ4MTQtYmI4NC0zMGZmMTkzMGY1ZmQgMTY5MzA1NTk5MC42ODAyMTQ2" --endpoint-url http://localhost:4566 --profile localstack
SQSใญใฅใผใฎใกใใปใผใธๆฐใ็ขบ่ช
% aws sqs get-queue-attributes --queue-url 'http://localhost:4566/000000000000/test-queue' --attribute-names ApproximateNumberOfMessages --query 'Attributes.ApproximateNumberOfMessages' --endpoint-url http://localhost:4566 --profile localstack
"0"
SNS #
- ๆฆ่ฆ
- ้็ฅใฎ็บ่ก่ ใใใกใใปใผใธใๅใๅใใ่ณผ่ชญ่ (ใตใในใฏใฉใคใใผ)ใซ้ ไฟก
- ่คๆฐใฎใจใณใใใคใณใ(SQSใญใฅใผใLambda้ขๆฐใใกใผใซใSMSใHTTP/HTTPS etc)ใซ้ไฟกๅฏ
- ใทในใใ ้ใฎ้ๅๆใฎใกใใปใผใธใฎไบคๆใใคใใณใ้งๅๅใฎใฏใผใฏใใญใผ(ใใผใฟใฎ็ป้ฒใปๅคๆด็ญใฎ
็นๅฎใฎใคใใณใใ็บ็ใใ้ใใกใใปใผใธใ้ไฟกใใๅใๅใฃใใทในใใ ใๅฆ็ใๅฎ่กใใ็ญ)ใๅฎ็พ
SNSใใใใฏใฎไฝๆ
% aws sns create-topic --name test-topic --endpoint-url=http://localhost:4566 --profile localstack
{
"TopicArn": "arn:aws:sns:us-east-1:000000000000:test-topic"
}
SQSใญใฅใผใฎไฝๆ
% aws sqs create-queue --queue-name test-queue --endpoint-url=http://localhost:4566 --profile localstack
{
"QueueUrl": "http://localhost:4566/000000000000/test-queue"
}
SNSใใใใฏใSQSใญใฅใผใง่ณผ่ชญใใSNSใใใใฏใซๅฏพใใฆใกใใปใผใธใ็บ่กใใใใ SQSใซ่ชๅ้ไฟกใใใใใ่จญๅฎ
% aws sns subscribe --topic-arn arn:aws:sns:us-east-1:000000000000:test-topic --protocol sqs --notification-endpoint arn:aws:sqs:us-east-1:000000000000:test-queue --endpoint-url=http://localhost:4566 --profile localstack
{
"SubscriptionArn": "arn:aws:sns:us-east-1:000000000000:test-topic:7284befa-eb97-4f8e-a76e-63891be75bd3"
}
SNSใใใใฏใธใฎใกใใปใผใธใ็บ่ก
% aws sns publish --topic-arn arn:aws:sns:us-east-1:000000000000:test-topic --message 'Hello, world!' --endpoint-url http://localhost:4566 --profile localstack
{
"MessageId": "63af4d31-59c3-4222-bc73-1ad0724592f4"
}
SNSใใใใฏใ่ณผ่ชญใใฆใใSQSใญใฅใผใใใกใใปใผใธใๅไฟกใงใใใใจใ็ขบ่ช
(ใใใงใฏไธ่จใฎMessageId 63af4d31-59c3-4222-bc73-1ad0724592f4
ใ Body
ใซๅซใพใใฆใใใใจใ็ขบ่ช)
% aws sqs receive-message --queue-url http://localhost:4566/000000000000/test-queue --endpoint-url http://localhost:4566 --profile localstack
{
"Messages": [
{
"MessageId": "10ba045a-6c00-44b2-b3df-6774eacd97a2",
"ReceiptHandle": "MjM5OTk2ZjctMzJhNC00OTRkLWJjZTYtMDgyMzEwYTA5M2EwIGFybjphd3M6c3FzOnVzLWVhc3QtMTowMDAwMDAwMDAwMDA6dGVzdC1xdWV1ZSAxMGJhMDQ1YS02YzAwLTQ0YjItYjNkZi02Nzc0ZWFjZDk3YTIgMTY5OTA2NDYyOS42ODU2NzQ=",
"MD5OfBody": "095875699e9fdb2ea41cf6385f0ea1e9",
"Body": "{\"Type\": \"Notification\", \"MessageId\": \"63af4d31-59c3-4222-bc73-1ad0724592f4\", \"TopicArn\": \"arn:aws:sns:us-east-1:000000000000:test-topic\", \"Message\": \"Hello, world!\", \"Timestamp\": \"2023-11-04T02:20:13.239Z\", \"SignatureVersion\": \"1\", \"Signature\": \"EXAMPLEpH+..\", \"SigningCertURL\": \"https://sns.us-east-1.amazonaws.com/SimpleNotificationService-0000000000000000000000.pem\", \"UnsubscribeURL\": \"http://localhost:4566/?Action=Unsubscribe&SubscriptionArn=arn:aws:sns:us-east-1:000000000000:test-topic:7284befa-eb97-4f8e-a76e-63891be75bd3\"}"
}
]
}