gpt4 book ai didi

amazon-s3 - 在 localstack 上自动创建 S3 存储桶

转载 作者:行者123 更新时间:2023-12-02 19:23:11 25 4
gpt4 key购买 nike

在我的 docker-compose 中使用 localstack 主要是为了模仿 S3。

我知道我可以创建存储桶,这不是问题。我想做的是在运行 docker-compose up 时自动创建存储桶。

是否已经为 localstack 内置了一些东西?

最佳答案

自版本 0.10.0 以来,commit 中出现的更改。

When a container is started for the first time, it will execute fileswith extensions .sh that are found in /docker-entrypoint-initaws.d.Files will be executed in alphabetical order. You can easily createaws resources on localstack using awslocal (or aws) cli tool in theinitialization scripts.

v1.1.0 之前

version: '3.7'
services:
localstack:
image: localstack/localstack
environment:
- SERVICES=s3
ports:
- "4566:4566"
# - "4572:4572" Old S3 port
volumes:
- ./aws:/docker-entrypoint-initaws.d

v1.1.0之后

The /docker-entrypoint-initaws.d directory usage has now been deprecated. The Pluggable initialization hooks in /etc/localstack/init/<stage>.d have replaced the legacy Init scripts, and the former will be removed entirely in the 2.0 release.

引用:localstack/localstack/issues/7257

初始化 Hook official documentation

version: '3.7'
services:
localstack:
image: localstack/localstack
environment:
- SERVICES=s3
ports:
- "4566:4566"
volumes:
- ./aws:/etc/localstack/init/ready.d

./aws/buckets.sh 目录中使用脚本:

#!/usr/bin/env bash
awslocal s3 mb s3://bucket

将产生以下输出:

v1.1.0 之前

...
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 | make_bucket: bucket
localstack_1 |

v1.1.0之后

localstack-1  | Ready.
localstack-1 | 2023-01-05T18:07:50.163 INFO --- [-functhread8] l.services.motoserver : starting moto server on http://0.0.0.0:40443
localstack-1 | 2023-01-05T18:07:50.165 INFO --- [ asgi_gw_0] localstack.services.infra : Starting mock S3 service on http port 4566 ...
localstack-1 | 2023-01-05T18:07:50.324 INFO --- [ asgi_gw_0] localstack.request.aws : AWS s3.CreateBucket => 200
localstack-1 | make_bucket: bucket

关于amazon-s3 - 在 localstack 上自动创建 S3 存储桶,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53619901/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com