Problem: I want to deploy the same service in two different cloudformation stacks on the same aws account. This works great since the stacknames differ on the ${self:provider.stage}
However, I had to add a cognito userpool with some exports to it like this:
Outputs:
UserPool:
Value:
Ref: UserPool
UserPoolId:
Value:
Ref: UserPool
Export:
Name: UserPoolId
However this does not work since Exports have to be unique across one region so when this export is already created by the other stack, the second stack will get an error while deploying.
Unfortunatly my attept to add the stage (and servicename) to the key like this:
Outputs:
UserPool-${self:custom.serviceName}-${self:provider.stage}:
Value:
Ref: UserPool
UserPoolId-${self:custom.serviceName}-${self:provider.stage}:
Value:
Ref: UserPool
Export:
Name: UserPoolId
results in the following error:
The CloudFormation template is invalid: Template format error: Outputs name 'UserPool-${self:custom.serviceName}-${self:provider.stage}' is non alphanumeric.
So how can I deploy the same service in two different stack with Exports?
You can't dynamically create output keys. Thus in your case your keys are literal strings
UserPool-${self:custom.serviceName}-${self:provider.stage}which leads to errors, because keys can only containa–z, A–Z, 0–9characters, not$,}or-ref. The references are not going to be resolved and you must explicity define them.