我有一个 CloudFormation 模板,它创建一个
AWS::Events::Rule
和一个 AWS::SSM::Document
。我需要为 Targets
提供 SSM::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'
我认为我需要将
<-- This is the value that I need to fill in.
替换为 ARN
的 mySSMDocument
,但我没有看到任何方法可以从模板本身中检索此值。 文档未在 GetAtt
上指定任何允许获取 SSM::Document
的 ARN
功能。有谁知道如何解决这个问题吗?
这是文档的ARN模式
arn:${分区}:ssm:${区域}:${帐户}:文档/${文档名称}
示例:
arn:aws:ssm:us-east-2:12345678912:文档/demoooo
您可以使用
Ref
函数获取文档名称,然后 Sub
创建最终的 ARN
!Sub arn:${AWS::Partition}:ssm:${AWS::Region}:${AWS::AccountId}:document/${mySSMDocument}
的返回值、分区、区域和AccountId的伪参数以及
AWS::SSM::Document
内在函数生成Sub
的ARN格式