问题:我想在同一个aws账户上的两个不同的cloudformation堆栈中部署相同的服务。这非常有效,因为堆栈名称在
${self:provider.stage}
上有所不同
但是,我必须添加一个认知用户池并对其进行一些导出,如下所示:
Outputs:
UserPool:
Value:
Ref: UserPool
UserPoolId:
Value:
Ref: UserPool
Export:
Name: UserPoolId
但是这不起作用,因为导出在一个区域中必须是唯一的,因此当另一个堆栈已创建此导出时,第二个堆栈将在部署时出现错误。
不幸的是,我尝试将阶段(和服务名称)添加到密钥中,如下所示:
Outputs:
UserPool-${self:custom.serviceName}-${self:provider.stage}:
Value:
Ref: UserPool
UserPoolId-${self:custom.serviceName}-${self:provider.stage}:
Value:
Ref: UserPool
Export:
Name: UserPoolId
导致以下错误:
The CloudFormation template is invalid: Template format error: Outputs name 'UserPool-${self:custom.serviceName}-${self:provider.stage}' is non alphanumeric.
那么如何使用 Exports 在两个不同的堆栈中部署相同的服务?
您无法动态创建输出键。因此,在您的情况下,您的键是文字字符串
UserPool-${self:custom.serviceName}-${self:provider.stage}
,这会导致错误,因为键只能包含 a–z, A–Z, 0–9
字符,而不是 $
、}
或 -
ref。引用不会被解析,您必须明确定义它们。