gpt4 book ai didi

amazon-web-services - 为什么在 CloudFormation 中使用嵌套堆栈时会收到 "No Export Named"错误?

转载 作者:行者123 更新时间:2023-12-03 07:18:40 26 4
gpt4 key购买 nike

我正在 CloudFormation 模板中定义导出,以便在另一个模板中使用。

我可以看到正在 AWS 控制台中创建导出,但是,第二个堆栈无法找到它。

错误:

UPDATE_ROLLBACK_IN_PROGRESS with reason: No export named sandbox06-ODM-KinesisStreamArn found

template.yml

Resources:
KinesisStream:
Type: AWS::Kinesis::Stream
Properties:
ShardCount: 1
RetentionPeriodHours: 24
Name: !Sub ${Environment}-${Application}
Outputs:
Topic:
Value: !Ref Topic
KinesisStreamArn:
Value: !GetAtt KinesisStream.Arn
Export:
Name: !Sub ${Environment}-${Domain}-KinesisStreamArn

firehose.yml

KinesisFirehoseRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Principal:
Service: firehose.amazonaws.com
Action: sts:AssumeRole
Path: /
Policies:
- PolicyName: KinesisFirehosePolicy
PolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Action:
- kinesis:*
- s3:*
- s3-object-lambda:*
Resource:
- !Sub "${Bucket.Arn}/*"
- Fn::ImportValue: !Sub "${Environment}-${Domain}-KinesisStreamArn"

nested_template.yml

  OperationalData:
Type: AWS::Serverless::Application
Properties:
Parameters:
Environment: !Ref Environment
Domain: OperationalData
Application: odm
BucketPrefix: pie
WhiteListCidr: !Ref WhiteListCidr
VpcId:
Fn::ImportValue: !Sub vpc-${Environment}-VPCID
VpcCidr:
Fn::ImportValue: !Sub vpc-${Environment}-VPCCIDR
Subnets:
Fn::ImportValue: !Sub vpc-${Environment}-PrivateSubnets
Location: ./data/odm/template.yml
Tags:
Environment: !Ref Environment
Domain: odm
Application: !Ref Application
Developer: !Ref Developer
DevOpsAdmin: !Ref DevOpsAdmin
Repository: !Ref Repository
Team: !Ref Team

DataEngineeringData:
Type: AWS::Serverless::Application
Properties:
Parameters:
Environment: !Ref Environment
Domain: DataEngineeringData
Application: data-engineering
Location: ./data/data-engineering/template.yml
Tags:
Environment: !Ref Environment
Domain: DataEngineeringData
Application: data-engineering
Developer: !Ref Developer
DevOpsAdmin: !Ref DevOpsAdmin
Repository: !Ref Repository
Team: !Ref Team

问题是什么?

最佳答案

the second stack fails to find it

这是因为默认情况下,嵌套的 CloudFormation 堆栈是并行创建的。

这意味着如果您的一个 child 堆叠 - 例如包含 KinesisFirehoseRole 的堆栈 - 正在从另一个子堆栈导入输出 - 例如包含 KinesisStream 的堆栈 - 那么堆栈创建将失败。

这是因为它们是并行创建的,CloudFormation 如何确保在创建的另一个子堆栈导入导出值时已将其导出?

要解决此问题,请使用 DependsOn堆栈上包含 KinesisFirehoseRole 的属性。

这应该指向包含 KinesisStream 的堆栈,因为 KinesisFirehoseRole 对其具有依赖关系。

DependsOn 使此依赖关系明确,并将确保正确的堆栈创建顺序。

这样的事情应该有效:

Stack-Containing-Kinesis-Firehose-Role:
Type: AWS::CloudFormation::Stack
DependsOn: Stack-Containing-Kinesis-Stream-Resource-Which-Outputs-KinesisStreamArn
...

关于amazon-web-services - 为什么在 CloudFormation 中使用嵌套堆栈时会收到 "No Export Named"错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69573472/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com