Home > Enterprise >  YAML Syntax for ImportValue into CFN Parameter Default
YAML Syntax for ImportValue into CFN Parameter Default

Time:11-27

I'm struggling with the YAML syntax to import a value that was exported by another CFN stack into the default value of a parameter in a new stack.

What I have at the moment is:

Parameters:
  DBEndpoint:
    Description: Hostname endpoint for RDS Database
    Type: String
    Default: Fn::ImportValue: 'db-endpoint'

Where db-endpoint is the value exported by the following YAML template snippet:

Outputs:
  dbhost:
    Description: "RDS Endpoint Address"
    Value: !GetAtt DB.Endpoint.Address
    Export:
      Name: db-endpoint

The export works fine, but I get a parse error (Template format error: YAML not well-formed. ) when trying to load the template with the ImportValue line.


Update:

I have the YAML parsing correctly now, I think, but now get a new error.

With

Parameters:
  DBEndpoint:
    Description: Hostname endpoint for RDS Database
    Type: String
    Default: !ImportValue 'db-endpoint'

I get an error Template format error: Every Default member must be a string..

So, it seems closer, but still not working.

This answer implies this might not even be possible... is that the case?

CodePudding user response:

!ImportValue 'db-endpoint' can't be used in Parameters. It can only be used in Resources and Outputs of your template. You have to "manually" (aka, outside of CloudFormation, e.g. by a wrapper script) set the default value of DBEndpoint to the actual value of your db-endpoint.

  • Related