【问题标题】:How to get S3 bucket name from S3 ARN using cloudformation如何使用 cloudformation 从 S3 ARN 获取 S3 存储桶名称
【发布时间】:2020-11-10 02:39:30
【问题描述】:

我正在使用表达式!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
:
:

【问题讨论】:

  • 代码看起来不错, !Select 表达式也是如此。当我将存储桶添加到主堆栈模板时,我可以使用正确命名的存储桶部署堆栈。您确定在部署堆栈时将资源 ARN 作为参数传递吗?
  • 欣赏评论@berenbums ...确实没问题,问题出在其他地方。

标签: amazon-web-services amazon-s3 expression amazon-cloudformation


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-05-06
    • 2022-01-23
    • 2021-07-18
    • 1970-01-01
    • 2021-08-02
    • 2022-06-21
    • 1970-01-01
    相关资源
    最近更新 更多