Reputation: 2993
As I knew, I can use ImportValue to reference value from another cloudformation stack in part of Resources
.
NetworkInterfaces:
- GroupSet:
- Fn::ImportValue:
Fn::Sub: "${NetworkStackNameParameter}-SecurityGroupID"
AssociatePublicIpAddress: 'true'
DeviceIndex: '0'
DeleteOnTermination: 'true'
SubnetId:
Fn::ImportValue:
Fn::Sub: "${NetworkStackNameParameter}-SubnetID"
But seems this feature can't be used in Parameters
Parameters:
VPC:
Description: VPC ID
Type: String
Default:
Fn::ImportValue:
!Sub "${NetworkStackNameParameter}-VPC"
If I use above way, will get the error:
An error occurred (ValidationError) when calling the CreateChangeSet operation: Template format error: Every Default member must be a string.
Anyway to work around? because the same vpc id, subnet id, security group Id, will be used not only one place.
So I have to give up:
- In your AWS CloudFormation template, confirm that the Parameters section doesn't contain any intrinsic functions.
https://aws.amazon.com/premiumsupport/knowledge-center/cloudformation-template-validation/
Upvotes: 15
Views: 9345
Reputation: 488
One way of doing this is to use a condition:
Parameters:
MyValue:
Type: String
Value: ''
Conditions:
MyValueExists: !Not [ !Equals [!Ref MyValue, '']]
Resources:
Resource:
Type: AWS::Something
Properties:
Key: !If [MyValueExists, !Ref MyValue, !ImportValue 'Imported']
Upvotes: 3