![](/img/trans.png)
[英]How to get an AWS SSM Key Arn from an Alias using CloudFormation?
[英]How to get the ARN of an SSM Document in CloudFormation?
我有一個 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'
我認為我需要用mySSMDocument
的ARN
替換<-- This is the value that I need to fill in.
,但我沒有看到任何方法可以從模板本身中檢索此值。 該文檔沒有在SSM::Document
上指定任何允許獲取ARN
GetAtt
功能。 有誰知道如何解決這個問題?
這是文檔的 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
!Sub arn:${AWS::Partition}:ssm:${AWS::Region}:${AWS::AccountId}:document/${mySSMDocument}
您可以產生的ARN格式AWS::SSM::Document
使用的返回值的AWS::SSM::Document
,該偽參數分區,區域和ACCOUNTID和Sub
內在功能
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.