amazon-s3 - 以编程方式创建 s3cmd 配置文件

标签 amazon-s3 s3cmd

我正在使用 s3cmd 将一些内容上传到 S3 存储桶。问题是,我如何以编程方式向它提供一些配置变量?

我没有使用 1.5 版,所以我没有 --access_key--secret_key 标志可用。我只有 --configure ,它以交互方式创建一个配置文件,以及 -c ,它必须提供一个配置文件。但是我如何实际构建该配置文件? --configure 构建的配置文件在那里添加了许多选项;我只需要将访问 key 和 secret key 传递给我的 s3cmd 命令。

最佳答案

我一直在为同样的问题苦苦挣扎,但幸运的是,因为我使用的是 docker,所以我可以在镜像构建期间生成配置文件。

Dockerfile:

FROM ubuntu:xenial

ARG ACCESS_KEY
ARG SECRET_KEY

COPY template.s3cfg /tmp/template.s3cfg

RUN apt-get -y update; \
    apt-get -y install python-setuptools wget gettext-base; \
    wget http://netix.dl.sourceforge.net/project/s3tools/s3cmd/1.6.0/s3cmd-1.6.0.tar.gz; \
    tar xvfz s3cmd-1.6.0.tar.gz; \
    cd s3cmd-1.6.0; \
    python setup.py install

RUN ACCESS_KEY=$ACCESS_KEY \
    SECRET_KEY=$SECRET_KEY \
    bash -c '/usr/bin/envsubst < "/tmp/template.s3cfg" > "/root/.s3cfg";'

CMD [<whatever you wanna run>]

模板.s3cfg:
[default]
access_key = ${ACCESS_KEY}
access_token = 
add_encoding_exts = 
add_headers = 
bucket_location = US
ca_certs_file = 
cache_file = 
check_ssl_certificate = True
check_ssl_hostname = True
cloudfront_host = cloudfront.amazonaws.com
default_mime_type = binary/octet-stream
delay_updates = False
delete_after = False
delete_after_fetch = False
delete_removed = False
dry_run = False
enable_multipart = True
encrypt = False
expiry_date = 
expiry_days = 
expiry_prefix = 
follow_symlinks = False
force = False
get_continue = False
gpg_command = None
gpg_decrypt = %(gpg_command)s -d --verbose --no-use-agent --batch --yes --passphrase-fd %(passphrase_fd)s -o %(output_file)s %(input_file)s
gpg_encrypt = %(gpg_command)s -c --verbose --no-use-agent --batch --yes --passphrase-fd %(passphrase_fd)s -o %(output_file)s %(input_file)s
gpg_passphrase = 
guess_mime_type = True
host_base = nyc3.digitaloceanspaces.com
host_bucket = %(bucket)s.nyc3.digitaloceanspaces.com
human_readable_sizes = False
invalidate_default_index_on_cf = False
invalidate_default_index_root_on_cf = True
invalidate_on_cf = False
kms_key = 
limit = -1
limitrate = 0
list_md5 = False
log_target_prefix = 
long_listing = False
max_delete = -1
mime_type = 
multipart_chunk_size_mb = 15
multipart_max_chunks = 10000
preserve_attrs = True
progress_meter = True
proxy_host = 
proxy_port = 0
put_continue = False
recursive = False
recv_chunk = 65536
reduced_redundancy = False
requester_pays = False
restore_days = 1
restore_priority = Standard
secret_key = ${SECRET_KEY}
send_chunk = 65536
server_side_encryption = False
signature_v2 = False
signurl_use_https = False
simpledb_host = sdb.amazonaws.com
skip_existing = False
socket_timeout = 300
stats = False
stop_on_error = False
storage_class = 
urlencoding_mode = normal
use_http_expect = False
use_https = True
use_mime_magic = True
verbosity = WARNING
website_endpoint = http://%(bucket)s.s3-website-%(location)s.amazonaws.com/
website_error = 
website_index = index.html

现在。构建图像时,您只需指定 ACCESS_KEYSECRET_KEY 参数,就可以了。

当然,您可以通过这种方式指定更多的值。您可以创建一个 bash 脚本,您可以将配置回显到文件中,这样您就不会丢失当前现有的配置文件。您根本没有使用 docker,这只是我的用例。

长话短说:使用 envsubst

关于amazon-s3 - 以编程方式创建 s3cmd 配置文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23650381/

相关文章:

amazon-web-services - 从 aws s3 存储桶下载 yfcc100m

s3cmd - 排除 s3cmd 同步的点文件

amazon-s3 - 来自 s3cmd 的 POST 或 PUSH 操作在某个 Internet 连接上失败

amazon-web-services - S3 : Make uploaded files public by default

使用远程数据扩展 Bash glob 模式

amazon-web-services - webpack 拆分是否有利于节省 AWS 成本?

amazon-web-services - 何时使用 Amazon Cloudfront 或 S3

ruby - 如何在 Ruby 中执行相当于 's3cmd setacl --acl-grant=read:82b82d.. s3://somebucket/..' 的操作?

ios - AWS/iOS 开发工具包 : when should I use AWSS3TransferManager and AWSS3TransferUtility?

amazon-s3 - 通过 url 访问 Amazon S3 图像