50.1 LocalStack for S3 (#50 Work with LocalStack)

This commit is contained in:
Art
2023-01-12 15:45:31 +02:00
parent 9e9779e05e
commit af1e9114b1
4 changed files with 76 additions and 0 deletions

View File

@ -19,6 +19,28 @@ services:
ports: ports:
- 8081:8080 - 8081:8080
#https://medium.com/dandelion-tutorials/using-s3-localstack-with-spring-boot-and-r2dbc-5ea201a18aea
localstack:
container_name: localstack
image: localstack/localstack:latest
environment:
- DEBUG=1
- USE_SSL=0
- AWS_CBOR_DISABLE=1
# - DOCKER_HOST=unix:///var/run/docker.sock
- HOSTNAME=localstack
- SERVICES=s3
- AWS_DEFAULT_REGION=eu-north-1
ports:
- '4566-4583:4566-4583'
volumes:
# - ./tmp/lib/localstack:/tmp/lib/localstack
- ./init-s3-bucket.sh:/etc/localstack/init/ready.d/init-s3-bucket.sh
# - ${TEMPDIR:-/tmp/localstack}:/tmp/localstack - LEGACY (or use LEGACY_INIT_DIR=1)
# - ./init-s3-bucket.sh:/docker-entrypoint-initaws.d/init-s3-bucket.sh - LEGACY (or use LEGACY_INIT_DIR=1)
# - /var/run/docker.sock:/var/run/docker.sock
volumes: volumes:
mysql-data: mysql-data:

View File

@ -0,0 +1,6 @@
#!/bin/bash
# -- > Create S3 Bucket
echo 'Starting.....................'
echo $(awslocal s3api create-bucket --bucket portal-user-profile-images)
# --> List S3 Buckets
echo $(awslocal s3api list-buckets)

View File

@ -0,0 +1,5 @@
#!/bin/bash
# -- > Create S3 Bucket
echo $(awslocal s3 mb s3://portal-user-profile-images)
# --> List S3 Buckets
echo $(awslocal s3 ls)

View File

@ -0,0 +1,43 @@
## Working with LocalStack
1. Start docker-compose
2. Working with AWS CLI
- create bucket
- `aws s3 mb s3://portal-user-profile-images --endpoint-url http://localhost:4566`
- **or**
- `aws s3api create-bucket --bucket portal-user-profile-images --endpoint-url http://localhost:4566 --create-bucket-configuration '{\"LocationConstraint\":\"eu-north-1\"}'`
- will respond
- ```
{
"Location": "http://portal-user-profile-images.s3.localhost.localstack.cloud:4566/"
}
```
- list buckets
- `aws s3 ls --endpoint-url http://localhost:4566`
- `aws s3api list-buckets --endpoint-url http://localhost:4566`
- list objects in a bucket
- `aws s3 ls s3://portal-user-profile-images --endpoint-url http://localhost:4566` - only one level (like dir)
- `aws s3api list-objects --bucket portal-user-profile-images --endpoint-url http://localhost:4566` - view all object info
3. Working with `awslocal` cli inside running docker container
- run `bash` inside container
- `docker ps` - view container id `c60d2c36c5f9`
- `docker exec -it c60 bash`
- create bucket
- `awslocal s3 mb s3://portal-user-profile-images`
- `awslocal s3api create-bucket --bucket portal-user-profile-images --create-bucket-configuration '{"LocationConstraint":"eu-north-1"}'`
- list buckets
- `awslocal s3 ls`
- `awslocal s3api list-buckets`
- list objects in a bucket
- `awslocal s3 ls s3://portal-user-profile-images` - only one level (like dir)
- `awslocal s3api list-objects --bucket portal-user-profile-images` - view all object info
5. Working with `awslocal` cli installed locally
- install localstack cli
- `pip install localstack`
- `localstack --version`