【问题标题】:refer the arn created from previous resource参考从先前资源创建的 arn
【发布时间】:2019-07-30 18:11:54
【问题描述】:

我正在尝试将第一步创建的策略的资源 arn 添加到第二步。但我无法将资源一中的 arn 引用到资源二。我尝试使用!ref 和 getattr,两者都不起作用。有什么解决办法吗?

在我尝试执行的 cloudformation 模板下方。

    Parameters: 
      AccountID: 
        Type: 'String'
        Default: "123465646"
        Description: "account id where the resources will be created"
    Resources:
      ssmPolicyEc2Manage: 
        Type: AWS::IAM::ManagedPolicy
        Properties: 
          Description: "This policy will be attached to EC2 running ssm agent"
          Path: "/"
          PolicyDocument: 
          Version: "2012-10-17"
          Statement: 
            - 
              Effect: "Allow"
              Action: "iam:PassRole"
              Resource: 
                  - !Join [ "", [ "arn:aws:iam::", !Ref AccountID, ":role/ssm_role_policy" ] ]

      snsPolicyRole:
        Type: AWS::IAM::Role
        Properties:    
          AssumeRolePolicyDocument: 
            Version: "2012-10-17"
            Statement:
              -
                Effect : "Allow"
                Principal:
                  Service :
                    - "ssm.amazonaws.com"
                    - "ec2.amazonaws.com"
                Action:
                    - "sts:AssumeRole"
          Path: "/"
          ManagedPolicyArns:
            - "HERE INCLUDE THE RESOURCE ARN CREATED FROM THE PREVIOUS RESOURCE I.E,ssmPolicyEc2Manage "
        DependsOn: ssmPolicyEc2Manage

感谢您的帮助。

【问题讨论】:

  • 您只是尝试Ref: ssmPolicyEc2Manage 吗?您有任何特定的错误消息吗?
  • 谢谢。你的评论很有帮助。我正在尝试使用 !Ref 而不是 Ref
  • @PruthviRaj !RefRef: 是等价的。

标签: amazon-cloudformation


【解决方案1】:

!Ref ssmPolicyEc2Manage 将返回资源的 ARN。您可以查看documentation 以获得更好的理解。

【讨论】:

    猜你喜欢
    • 2022-09-22
    • 2021-04-17
    • 2021-11-27
    • 1970-01-01
    • 1970-01-01
    • 2019-08-27
    • 2021-09-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多