在本地堆栈上自动创建S3存储桶 [英] Auto create S3 Buckets on localstack
问题描述
在我的docker-compose中使用localstack主要是模仿S3.
Using localstack in my docker-compose mainly to mimic S3.
我知道我可以创建存储桶,这不是问题.我想做的是在运行docker-compose时自动创建存储桶.
I know I can create buckets, thats not the issue. What I would like to do is automatically create the buckets when I run a docker-compose up.
已经为localstack内置了一些东西吗?
Is there something build in already for localstack?
推荐答案
A change that came in with this commit since version 0.10.0
.
首次启动容器时,它将执行文件 在
/docker-entrypoint-initaws.d
中具有扩展名.sh的扩展名. 文件将按字母顺序执行.您可以轻松创建 使用以下命令中的awslocal(或aws)cli工具在本地堆栈上的aws资源 初始化脚本.
When a container is started for the first time, it will execute files with extensions .sh that are found in
/docker-entrypoint-initaws.d
. Files will be executed in alphabetical order. You can easily create aws resources on localstack using awslocal (or aws) cli tool in the initialization scripts.
version: '3.7'
services:
localstack:
image: localstack/localstack
environment:
- SERVICES=s3
ports:
- "4572:4572"
volumes:
- ./aws:/docker-entrypoint-initaws.d
在目录./aws/buckets.sh
中具有脚本:
#!/bin/bash
set -x
awslocal s3 mb s3://bucket
set +x
注意:set [-/+] x
纯粹是用于打开和关闭正在执行的命令的输出.
Note: the set [-/+] x
is purely there to turn on and off outputting of the commands being executed.
将产生以下输出:
...
localstack_1 | Starting mock S3 (http port 4572)...
localstack_1 | Waiting for all LocalStack services to be ready
localstack_1 | Ready.
localstack_1 | /usr/local/bin/docker-entrypoint.sh: running /docker-entrypoint-initaws.d/buckets.sh
localstack_1 | ++ awslocal s3 mb s3://bucket
localstack_1 | make_bucket: bucket
localstack_1 | ++ set +x
localstack_1 |
这篇关于在本地堆栈上自动创建S3存储桶的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!