Mục đích sử dụng:
Localstack mô phỏng lại môi trường AWS trên máy local.
Nó giúp phát triển và kiểm thử các giải pháp như microservices hoặc functions và sử dụng các dịch vụ có trong AWS.
Các dịch vụ AWS trên Localstack:
API Gateway, Kinesis, DynamoDB, DynamoDB Streams, Elasticsearch, S3, Firehose, Lambda, SNS, SQS, Redshift, ES (Elasticsearch Service), SES, Route53, CloudFormation, CloudWatch, SSM, SecretsManager
Cài đặt và sử dụng:
Cài đặt localstack:
YAML
# docker-compose.yml
version: "3.2"
services:
localstack:
image: localstack/localstack:latest
container_name: localstack_demo
ports:
# - "127.0.0.1:4566:4566" # LocalStack Gateway
- "127.0.0.1:4510-4559:4510-4559" # external services port range
- "0.0.0.0:4566:4566"
environment:
- SERVICES=s3
- DEBUG=1
- DATA_DIR=/tmp/localstack/data
volumes:
- "./.localstack:/var/lib/localstack"
- "/var/run/docker.sock:/var/run/docker.sock"Start localstack:
Zsh
docker-compose up -dTạo profile cho Localstack:
Zsh
aws configure --profile localstack
AWS Access Key ID [****************demo]: dummy
AWS Secret Access Key [****************demo]: dummy
Default region name [ap-northeast-1]: ap-northeast-1
Default output format [json]: jsonOr
Zsh
vi ~/.aws/configVimL
[profile localstack]
output = json
region = ap-northeast-1Zsh
vi ~/.aws/credentialsVimL
[localstack]
aws_access_key_id = dummy
aws_secret_access_key = dummyTạo S3 trong Localstack:
Zsh
aws --endpoint-url=http://localhost:4566 --profile localstack s3api create-bucket --bucket test-bucket --create-bucket-configuration LocationConstraint=ap-northeast-1
# Kết quả:
{
"Location": "http://test-bucket.s3.localhost.localstack.cloud:4566/"
}Zsh
aws s3 ls --endpoint-url=http://localhost:4566 --profile localstack
# Kết quả:
2023-11-15 10:24:40 test-bucketYAML
# .env
# Cả 2 endpoint đều hoạt động với Localstack ở local.
#S3_ENDPOINT='http://localhost:4566'
S3_ENDPOINT='http://test-bucket.s3.localhost.localstack.cloud:4566/'
S3_AWS_ACCESS_KEY_ID='dummy'
S3_AWS_SECRET_KEY='dummy'
S3_AWS_BUCKET_NAME='test-bucket'Tạo Dynamodb trong Localstack:
YAML
version: "3.2"
services:
localstack:
image: localstack/localstack:latest
container_name: localstack_demo
ports:
# - "127.0.0.1:4566:4566" # LocalStack Gateway
- "127.0.0.1:4510-4559:4510-4559" # external services port range
- "0.0.0.0:4566:4566"
environment:
- SERVICES=dynamodb
- DEBUG=1
- DATA_DIR=/tmp/localstack/data
volumes:
- "./.localstack:/var/lib/localstack"
- "/var/run/docker.sock:/var/run/docker.sock"Zsh
aws dynamodb create-table \
--table-name test \
--key-schema AttributeName=id,KeyType=HASH \
--attribute-definitions AttributeName=id,AttributeType=S \
--billing-mode PAY_PER_REQUEST \
--region ap-northeast-1 \
--endpoint-url=http://localhost:4566 \
--profile localstack
# Kết quả:
{
"TableDescription": {
"AttributeDefinitions": [
{
"AttributeName": "id",
"AttributeType": "S"
}
],
"TableName": "test",
"KeySchema": [
{
"AttributeName": "id",
"KeyType": "HASH"
}
],
"TableStatus": "ACTIVE",
"CreationDateTime": "2023-11-15T11:29:05.597000+07:00",
"ProvisionedThroughput": {
"LastIncreaseDateTime": "1970-01-01T07:00:00+07:00",
"LastDecreaseDateTime": "1970-01-01T07:00:00+07:00",
"NumberOfDecreasesToday": 0,
"ReadCapacityUnits": 0,
"WriteCapacityUnits": 0
},
"TableSizeBytes": 0,
"ItemCount": 0,
"TableArn": "arn:aws:dynamodb:ap-northeast-1:000000000000:table/test",
"TableId": "fb25d41f-0563-4be9-8b21-75bc3b7006b9",
"BillingModeSummary": {
"BillingMode": "PAY_PER_REQUEST",
"LastUpdateToPayPerRequestDateTime": "2023-11-15T11:29:05.597000+07:00"
}
}
}Bạn muốn sử dụng dịch vụ nào của AWS thì thêm dịch vụ đấy vào SERVICES trong file docker-compose.yml.
Tài liệu tham khảo: https://docs.localstack.cloud/
5 comments
This site certainly has all thhe info I needed about
this subject and didn’t know who to ask.
Your point of view caught my eye and was very interesting. Thanks. I have a question for you.
The best pokies iin Australia sand out for entertaining visual designs.
Fans value lively gaming sessions. Different speciazl mechanics add extra
excitement. Clear layouts support quick understanding.
In general, these pokies create an enjoyable digitall experience for a wide audience.
Casinos with small startinng deposit levels create an inviting starting point.
With modest initial funding, users feel more relazed starting.
The balanced deposit model supports controlled spending.
Clear deposit guidelines enhance a sense of control. Overall,
this appeoach fosters an enjoyable introduction for various player profiles.
I don’t think the title of your article matches the content lol. Just kidding, mainly because I had some doubts after reading the article. https://www.binance.com/en-ZA/register?ref=B4EPR6J0