【发布时间】:2018-08-17 09:43:39
【问题描述】:
我制作了一个嵌套的 cloudformation 父模板,然后引用 4 个子模板。当我尝试通过 CLI 命令aws cloudformation create-stack... 启动堆栈时,出现错误:
An error occurred (ValidationError) when calling the CreateStack
operation: Template error: instance of Fn::GetAtt references undefined
resource BatchScatterGatherSubmissionActivity
这是因为我有一个名为 StepFunctionResourcesStack 的子模板,其中包含 BatchScatterGatherSubmissionActivity,然后是另一个引用它的子模板 EC2InstanceResourcesStack。我确保为后一个子模板添加了 DependsOn 子句,但我仍然收到错误消息。
这里是 StepFunctionResourcesStack:
AWSTemplateFormatVersion: '2010-09-09'
Description: step functions resources stack.
Parameters:
StackUID:
Type: String
Resources:
StatesExecutionRole:
Type: "AWS::IAM::Role"
Properties:
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: "Allow"
Principal:
Service:
- !Sub states.${AWS::Region}.amazonaws.com
Action: "sts:AssumeRole"
Path: "/"
Policies:
- PolicyName: StatesExecutionPolicy
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Action:
- "lambda:InvokeFunction"
Resource: "*"
MyStateMachine:
Type: "AWS::StepFunctions::StateMachine"
Properties:
#
# The StateMachine definition is substituted in with Jinja2
#
DefinitionString: !Sub
- |
{{ machine_json | indent(10) }}
- {% for item in machine_args -%}
{{ item }}
{% endfor %}
RoleArn: !GetAtt [ StatesExecutionRole, Arn ]
# several of these:
BatchScatterGatherSubmissionActivity:
Type: "AWS::StepFunctions::Activity"
Properties:
Name:
Fn::Join: [ "-", [ "BatchScatterGatherSubmissionActivity", Ref: StackUID] ]
BatchScatterGatherPollingActivity:
Type: "AWS::StepFunctions::Activity"
Properties:
Name:
Fn::Join: [ "-", [ "BatchScatterGatherPollingActivity", Ref: StackUID] ]
BatchGatherActivity:
Type: "AWS::StepFunctions::Activity"
Properties:
Name:
Fn::Join: [ "-", [ "BatchGatherActivity", Ref: StackUID] ]
BatchTriodenovoActivity:
Type: "AWS::StepFunctions::Activity"
Properties:
Name:
Fn::Join: [ "-", [ "BatchTriodenovoActivity", Ref: StackUID] ]
BatchHandoffActivity:
Type: "AWS::StepFunctions::Activity"
Properties:
Name:
Fn::Join: [ "-", [ "BatchHandoffActivity", Ref: StackUID] ]
Outputs:
# These get used in the instance_resources child stack.
BatchScatterGatherSubmissionActivity:
Value: !Ref BatchScatterGatherSubmissionActivity
BatchScatterGatherPollingActivity:
Value: !Ref BatchScatterGatherPollingActivity
BatchGatherActivity:
Value: !Ref BatchGatherActivity
BatchTriodenovoActivity:
Value: !Ref BatchTriodenovoActivity
BatchHandoffActivity:
Value: !Ref BatchHandoffActivity
这里是父(嵌套)模板的相关部分,上面的输出被传递到 EC2InstanceResourcesStack:
StepFunctionResourcesStack:
Type: AWS::CloudFormation::Stack
Properties:
Parameters:
StackUID:
Ref: StackUID
TemplateURL: https://s3.amazonaws.com/CFNTemplate/step_functions_resources.stack.yaml
Timeout: "100"
EC2InstanceResourcesStack:
Type: AWS::CloudFormation::Stack
Properties:
Parameters:
BatchScatterGatherSubmissionActivity:
Fn::GetAtt: [ "BatchScatterGatherSubmissionActivity", "Outputs.StepFunctionResourcesStack" ]
BatchScatterGatherPollingActivity:
Fn::GetAtt: [ "BatchScatterGatherPollingActivity", "Outputs.StepFunctionResourcesStack" ]
BatchGatherActivity:
Fn::GetAtt: [ "BatchGatherActivity", "Outputs.StepFunctionResourcesStack" ]
BatchTriodenovoActivity:
Fn::GetAtt: [ "BatchTriodenovoActivity", "Outputs.StepFunctionResourcesStack" ]
BatchHandoffActivity:
Fn::GetAtt: [ "BatchHandoffActivity", "Outputs.StepFunctionResourcesStack" ]
Subnet: !Ref Subnet
GPCESSHKeyPair: !Ref GPCESSHKeyPair
GPCESubnetAZ1: !Ref GPCESubnetAZ1
ActivityAndHandoffAnsibleBucketName: !Ref ActivityAndHandoffAnsibleBucketName
ActivityAndHandoffAnsibleKeyName: !Ref ActivityAndHandoffAnsibleKeyName
ActivityAndHandoffDaemonBucketName: !Ref ActivityAndHandoffDaemonBucketName
ActivityAndHandoffDaemonKeyName: !Ref ActivityAndHandoffDaemonKeyName
ActivityAndHandoffDaemonRequirementsBucketName: !Ref ActivityAndHandoffDaemonRequirementsBucketName
ActivityAndHandoffDaemonRequirementsKeyName: !Ref ActivityAndHandoffDaemonRequirementsKeyName
Rkstr8PkgBucketName: !Ref Rkstr8PkgBucketName
Rkstr8PkgKeyName: !Ref Rkstr8PkgKeyName
TemplateURL: https://s3.amazonaws.com/CFNTemplate/instance_resources.stack.yaml
Timeout: "100"
DependsOn: StepFunctionResourcesStack
对于我从子级导出参数并通过父模板将它们传递给另一个的方法,我遵循此处答案中提供的方法:AWS CloudFormation: Passing Values between Nested Stacks
【问题讨论】:
标签: amazon-web-services nested stack amazon-cloudformation