[英]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.