英文:
How to pass variables in TemplateBody section of Cloudformation
问题
我尝试在TemplateBody部分传递RegionName,但出现错误:“模板格式错误:在模板的资源块中存在未解析的资源依赖项[RegionName]”。
这是我使用的YAML文件:
TemplateBody: |
Resources:
CWEvent:
Type: AWS::Events::Rule
Properties:
State: ENABLED
Name: Rule
Targets:
- Arn: !Sub "arn:aws:events:${RegionName}:1234:event-bus/My-Bus"
Id: 'Event'
RoleArn:
!Join
- ""
- - "arn:aws:iam::"
- !Ref "AWS::AccountId"
- ":role/"
- "Role"
EventPattern:
source:
- "aws.ec2"
detail-type:
- "AWS API Call via CloudTrail"
detail:
eventSource:
- "ec2.amazonaws.com"
eventName:
- "RestoreSnapshotFromRecycleBin"
由于限制,我也无法使用S3,因此TemplateURL不适用。
英文:
Im trying to pass RegionName in the TemplateBody section but getting the error as "Template format error: Unresolved resource dependencies [RegionName] in the Resources block of the template".
Here is the yaml file which I'm using:
TemplateBody: |
Resources:
CWEvent:
Type: AWS::Events::Rule
Properties:
State: ENABLED
Name: Rule
Targets:
- Arn: !Sub "arn:aws:events:${RegionName}:1234:event-bus/My-Bus"
Id: 'Event'
RoleArn:
!Join
- ""
- - "arn:aws:iam::"
- !Ref "AWS::AccountId"
- ":role/"
- "Role"
EventPattern:
source:
- "aws.ec2"
detail-type:
- "AWS API Call via CloudTrail"
detail:
eventSource:
- "ec2.amazonaws.com"
eventName:
- "RestoreSnapshotFromRecycleBin"
Also I cannot use S3 due to restriction so TemplateURL is out of picture.
答案1
得分: 1
如果您使用了!Sub函数,它应该会自动填充所有变量,因此您的TemplateBody行应该如下所示:
TemplateBody: !Sub |
这将在堆栈部署之前填充您的变量,您可能需要删除模板中其他!Sub函数以使其正常工作。
英文:
If you used the !Sub function it should fill in all your variables for you, so your TemplateBody line should look like
TemplateBody: !Sub |
This would then fill in your variables before the stack is deployed, you might need to remove the other !Sub's you have inside the template for this to work.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论