简体   繁体   English

如何将 S3 存储桶的原始名称分配给变量,然后使用该变量

[英]How can I assign the raw Name of an S3 bucket to a variable and then use that variable

I'm trying to create a an S3 bucket and then use that bucket in another AWS service:我正在尝试创建一个 S3 存储桶,然后在另一个 AWS 服务中使用该存储桶:

I'm doing this way:我这样做:

I have a variable named $AccountAlias which I'll use that to make my buckets unique, so I'm running this:我有一个名为 $AccountAlias 的变量,我将使用它来使我的存储桶独一无二,所以我正在运行它:

bucketName=$(aws s3 mb s3://mytestbkt-${AccountAlias})

The bucket is created successfully, but I'm expecting that $bucketName will store the Name of the bucket, then use that variable to another service that expects the Bucket Name:存储桶已成功创建,但我希望 $bucketName 将存储存储桶的名称,然后将该变量用于另一个需要存储桶名称的服务:

aws shield associate-drt-log-bucket --log-bucket $bucketName

After running this command I get the error:运行此命令后,出现错误:

make_bucket:: command not found    
aws: error: argument --log-bucket: expected one argument

And It makes sense, because if I run echo $bucketName I get: make_bucket: mytestbkt-testacc123这是有道理的,因为如果我运行echo $bucketName我得到: make_bucket: mytestbkt-testacc123

So, How can I assign just the value of the bucket name to my variable to use that in another CLI command?那么,我如何才能将存储桶名称的值分配给我的变量,以便在另一个 CLI 命令中使用它?

Create a variable for the bucket name initially and then use it in both places:最初为存储桶名称创建一个变量,然后在两个地方使用它:

#!/bin/bash
bucketName="mytestbkt-$AccountAlias"
aws s3 mb "s3://$bucketName"
aws shield associate-drt-log-bucket --log-bucket "$bucketName"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何备份或同步 Amazon S3 存储桶? - How can I backup or sync an Amazon S3 bucket? 将存储桶名称作为变量引用到 serverless.yml 中的 s3 事件中的资源 - Referencing bucket name as variable to a resource in s3 event in serverless.yml 如何从 inte.net 访问 S3 存储桶? - How can I access the S3 bucket from internet? 如何将所有对象从一个 Amazon S3 存储桶复制到另一个存储桶? - How can I copy all objects from one Amazon S3 bucket to another bucket? 如何为 s3 存储桶设置允许经过身份验证的用户列出存储桶或从存储桶中获取任何文件的策略 - How can I set a policy for an s3 bucket that allows authenticated users to list the bucket or get any file from the bucket 如何正确配置我的 S3 存储桶以供 Transloadit 使用? - How do I correctly configure my S3 bucket for use by Transloadit? 如何将 AWS S3 url 转换为 boto 的存储桶名称? - How do I translate an AWS S3 url into a bucket name for boto? 将 ELB 帐户分配给 S3 存储桶策略 - Assign ELB Account to S3 Bucket Policy 如何在可观察的 Firebase 变量中分配 SnapshotChanges? - How Can I assign the SnapshotChanges in a Observable Firebase Variable? 如何确保 S3 存储桶名称不与 Terraform 一起使用? - How to ensure an S3 bucket name is not used with Terraform?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM