繁体   English   中英

如何使用 cloudformation 从 S3 ARN 获取 S3 存储桶名称

[英]How to get S3 bucket name from S3 ARN using cloudformation

我正在使用表达式,Select [5: ,Split [':', !Ref ResourceARN]]ResourceARN (这是一个堆栈的 STRING 输入参数)转换为相应的S3 bucket name ,以将其传递给孩子堆。

示例:来自arn:aws:s3:::tests3bucket-1a3o2v3wr375g期望创建tests3bucket-1a3o2v3wr375g

相反,它评估为空字符串,因为我得到了Parameters: [S3BucketName] must have values

我怎样才能使这项工作?


这是主要的堆栈模板:

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
:
:

这是子模板:

AWSTemplateFormatVersion: 2010-09-09
Parameters:
  S3BucketName:
    Description: 'The name of the S3 bucket'
    Type: String
:
:

谢谢@berenbums 看一看——我自己也意识到这很有效。 还有一个问题掩盖了这个问题。

所以毕竟,表达式,Select [5: ,Split [':', !Ref ResourceARN]]可以用来将 ResourceARN 转换为对应的 S3 存储桶名称。

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM