[英]How to get S3 bucket name from S3 ARN using cloudformation
I'm using the expression ,Select [5: ,Split [':', !Ref ResourceARN]]
to convert ResourceARN
, which is a STRING input parameter to a stack, to the corresponding S3 bucket name
, to pass it to a child stack.我正在使用表达式,Select [5: ,Split [':', !Ref ResourceARN]]
将ResourceARN
(这是一个堆栈的 STRING 输入参数)转换为相应的S3 bucket name
,以将其传递给孩子堆。
Example: from arn:aws:s3:::tests3bucket-1a3o2v3wr375g
expecting to create tests3bucket-1a3o2v3wr375g
示例:来自arn:aws:s3:::tests3bucket-1a3o2v3wr375g
期望创建tests3bucket-1a3o2v3wr375g
Instead it evaluates to empty string, as I'm getting Parameters: [S3BucketName] must have values
.相反,它评估为空字符串,因为我得到了Parameters: [S3BucketName] must have values
。
How can I make this work?我怎样才能使这项工作?
Here is the main stack template:这是主要的堆栈模板:
AWSTemplateFormatVersion: 2010-09-09
Parameters:
ResourceARN:
Description: 'The AWS ARN associated with S3 resource, example arn:aws:s3:::tests3bucket-1a3o2v3wr375g'
ConstraintDescription: The ARN of the resource
Type: String
:
:
Resources:
ChildStack:
Type: 'AWS::CloudFormation::Stack'
Properties:
TemplateURL: !Sub >-
https://${QSS3BucketName}.s3.amazonaws.com/${QSS3KeyPrefix}/templates/child.template
Parameters:
S3BucketName: !Select [5, !Split [':', !Ref ResourceARN]] # Expecting to evaluate to tests3bucket-1a3o2v3wr375g
:
:
and here is the child template:这是子模板:
AWSTemplateFormatVersion: 2010-09-09
Parameters:
S3BucketName:
Description: 'The name of the S3 bucket'
Type: String
:
:
Thank you @berenbums for taking a look - just realized myself too that this works.谢谢@berenbums 看一看——我自己也意识到这很有效。 There was another issue which masked the problem.还有一个问题掩盖了这个问题。
So after all, the expression ,Select [5: ,Split [':', !Ref ResourceARN]]
can be used to convert ResourceARN to the corresponding S3 bucket name.所以毕竟,表达式,Select [5: ,Split [':', !Ref ResourceARN]]
可以用来将 ResourceARN 转换为对应的 S3 存储桶名称。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.