18 Ekim 2023 Çarşamba

Localstack awslocal komutu

Giriş
Açıklaması şöyle
When interacting with LocalStack to emulate AWS services it’s important to configure your AWS CLI or SDK to point to the LocalStack endpoint URL. This allows you to interact with LocalStack easily without having to specify the --endpoint-url option every time you run a command.

Another option is installing a tool called “awslocal” which is a wrapper around the AWS CLI for LocalStack. It automatically configures the CLI to use the LocalStack endpoint URL, saving you from the manual step of specifying the --endpoint-url option.
Açıklaması şöyle
awslocal is a thin wrapper and a drop-in replacement for the aws command that runs commands directly against LocalStack
1. awslocal Olmadan
Örnek
Şöyle yaparız
# create s3 bucket
aws --endpoint-url=http://localhost:4566 s3api create-bucket --bucket testbucket

# list s3 buckets
aws --endpoint-url=http://localhost:4566 s3api list-buckets

# copy test file to the created bucket.
aws --endpoint-url=http://localhost:4566 s3 cp test.txt s3://testbucket

# check files
aws --endpoint-url=http://localhost:4566 s3api list-objects --bucket testbucket
Örnek
bucket_policy.json içinde şöyle yaparız
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "PublicReadGetObject",
      "Effect": "Allow",
      "Principal": "*",
      "Action": "s3:GetObject",
      "Resource": "arn:aws:s3:::testbucket/*"
    }
  ]
}
Şöyle yaparız
# sync the website folder that contains our files to the S3 bucket 
aws --endpoint-url=http://localhost:4566 s3 sync .\website\ s3://testbucket

# enable static website hosting on the bucket and configure the index and error documents:
aws --endpoint-url=http://localhost:4566 s3 website s3://testbucket/ \
  --index-document index.html 
  --error-document error.html
2. Bash Başlatmak
Localstack içinden awslocal çıkıyor. Container'a bash açmak yeterli. Şöyle yaparız
docker exec -it <container_id> /bin/bash
sqs seçeneği
Örnek
Şöyle yaparız
$awslocal sqs create-queue --queue-name test-queue

$awslocal sqs list-queues

{
  "QueueUrls" : [
    http:/localhost:4566:/000000/test-queue"
  ]
}
s3 seçeneği
Örnek - High Level Command
Şöyle yaparız. Yeni bir bucket yaratır
awslocal s3 mb s3://my-test-bucket
Örnek -  - Low Level Command
Şöyle yaparız. Yeni bir bucket yaratır
awslocal s3api create-bucket \
--bucket mybucket \
--create-bucket-configuration LocationConstraint=eu-central-1

Hiç yorum yok:

Yorum Gönder