【问题标题】:How to get the ARN of an SSM Document in CloudFormation?如何在 CloudFormation 中获取 SSM 文档的 ARN?
【发布时间】:2019-12-17 02:38:04
【问题描述】:

我有一个 CloudFormation 模板,可以创建一个 AWS::Events::Rule 和一个 AWS::SSM::Document。我需要为SSM::Rule 提供Targets 的列表,但每个目标都需要一个ARN

mySSMDocument:
  Type: AWS::SSM::Document
  Properties:
    DocumentType: 'Command'
    Content:
      schemaVersion: '2.2'
      description: "Code that will be run on EC2"
      mainSteps:
        - action: "aws:runShellScript"
          name: runShellScript
          inputs:
            runCommand:
              - 'Some command to execute'
myEventRule:
  Type: AWS::Events::Rule
  Properties:
    Description: "A description for the Rule."
    EventPattern: 
      source:
        - "aws.autoscaling"
      detail-type:
        - "EC2 Instance-terminate Lifecycle Action"
      detail:
        AutoScalingGroupName:
          - !Ref 'someAutoScalingGroupInThisTemplate'
    RoleArn: 'some role ARN'
    State: "ENABLED"
    Targets:
      - Id: "some-unique-id"
        Arn: <-- This is the value that I need to fill in.
        RunCommandParameters:
          RunCommandTargets:
            - Key: "tag: Name"
              Values:
                - 'The name of the EC2 machine'

我认为我需要将&lt;-- This is the value that I need to fill in. 替换为mySSMDocumentARN,但我看不到任何从模板本身中检索此值的方法。 The documentation 没有在SSM::Document 上指定任何允许获取ARNGetAtt 功能。有谁知道如何解决这个问题?

【问题讨论】:

    标签: amazon-web-services amazon-cloudformation ssm


    【解决方案1】:

    这是文档的 ARN 模式

    arn:${Partition}:ssm:${Region}:${Account}:document/${DocumentName}

    示例:

    arn:aws:ssm:us-east-2:12345678912:document/demoooo

    您可以使用Ref 函数获取文档名称,然后使用Sub 创建最终的 ARN

    参考:https://docs.aws.amazon.com/IAM/latest/UserGuide/list_awssystemsmanager.html#awssystemsmanager-resources-for-iam-policies

    【讨论】:

    • 有什么理由使用Join 而不是Sub?我看到它被到处使用,而Sub 更具可读性。
    • @TuanVA 我可以为包提供 ARN 模式(使用系统管理器中的分发器创建)吗?我试过但它不接受
    【解决方案2】:
    !Sub arn:${AWS::Partition}:ssm:${AWS::Region}:${AWS::AccountId}:document/${mySSMDocument}
    

    您可以使用return Value for AWS::SSM::DocumentPseudo Parameters for Partition, Region, and AccountIdSub intrinsic function 生成ARN format for AWS::SSM::Document

    【讨论】:

      猜你喜欢
      • 2020-03-13
      • 2020-03-24
      • 1970-01-01
      • 1970-01-01
      • 2022-08-11
      • 2020-01-27
      • 2020-10-03
      • 2020-10-27
      • 1970-01-01
      相关资源
      最近更新 更多