如何在 CloudFormation 中获取 SSM 文档的 ARN?

Tit*_*lum 4 amazon-web-services aws-cloudformation ssm

我有一个 CloudFormation 模板,它创建一个AWS::Events::Rule和一个AWS::SSM::Document. 我需要提供的名单TargetsSSM::Rule,但每个目标要求的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'
Run Code Online (Sandbox Code Playgroud)

我认为我需要<-- This is the value that I need to fill in.ARNof替换mySSMDocument,但我没有看到任何方法可以从模板本身中检索此值。文档不指定任何GetAtt有关的功能SSM::Document,允许获得ARN。有谁知道如何解决这个问题?

Pat*_*ron 7

!Sub arn:${AWS::Partition}:ssm:${AWS::Region}:${AWS::AccountId}:document/${mySSMDocument}
Run Code Online (Sandbox Code Playgroud)

您可以生成ARN 格式以AWS::SSM::Document使用 的返回值AWS::SSM::Document分区、区域和 AccountId 的伪参数以及Sub内部函数


Ton*_*yVo 5

这是文档的 ARN 模式

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

例子:

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

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

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