Home > front end >  Use Gett Function inside Sub in cloudformation
Use Gett Function inside Sub in cloudformation

Time:07-29

I am trying to get the value of my RDS endpoint and use it as a value in a secret-manager I am creating.

I know how to get the endpoint in the outputs:

  DB1ConnectionString:
    Condition: Launch1Engine
    Description: The First db Connection String
    Value: {"Fn::GetAtt": ["RDSDBInstance1","Endpoint.Address"]} 

But I can not use output inside my current stack, so I want to use the same way I got the Endpoint and use it in the secret manager. This is what I tried:

  DBStringSecret1:
    Condition: Launch1Engine
    Type: 'AWS::SecretsManager::Secret'
    Properties:
      Name: !Ref DBStringSecret1Name
      SecretString: !Sub '{"repository":!GetAtt RDSDBInstance1.Endpoint.Address,"username":"MasterUsername","password":"${SafeMineDBPassword1}"}'

But I get a literal string as the "repository value and not the RDS endpoint, Is there a way to use the "!GetAtt" inside the "!Sub"?

Or am I doing it all wrong and I can define a new parameter that will build the value I want using Join?

!Sub 'jdbc://{!GetAtt RDSDBInstance1.Endpoint.Address}:3306/<SCHEMA>?'

Expected result:

jdbc://endpoint:3306/?

enter image description here

CodePudding user response:

You have to use join function in this case:

SecretString: !Join
  - ''
  - - '{"repository": "'
    - !GetAtt RDSDBInstance1.Endpoint.Address
    - '","username":"MasterUsername","password":"'
    - !Ref SafeMineDBPassword1
    - '"}'
  • Related