By using AWS re:Post, you agree to the Terms of Use
/Cloudformation - adding string in middle/

Cloudformation - adding string in middle

1

I am trying to concatenate sting in AWS Cloudformation, I am getting error, tried various things . No luck. Enviroment is a Parameter. I am trying to make EndpointIdentifier with join but it doesn't work. Please let me know the correct format. Error message - Template error: every Fn::Join object requires two parameters, (1) a string delimiter and (2) a list of strings to be joined or a function that returns a list of strings (such as Fn::GetAZs) to be joined.

End result should be for e.g if dev is choosen from dropdown - fp-epk-dev-dms-source or fp-epk-dev-dms-target Removed some code which is not required for this question

AWSTemplateFormatVersion: 2010-09-09
Parameters:
 Enviroment:
      Type: String
      Default: "dev"
      AllowedValues:
        - "dev"
        - "uat"
        - "prod"
Resources:
  DMSSourceEndpoint:
    Type: "AWS::DMS::Endpoint"
    Properties:
      EndpointIdentifier: !Join
        - ''
        - 'fp-epk-'
        - !Ref Enviroment
        - '-dms-source'
      EngineName: "ORACLE"
      EndpointType: "source"
      Username: !Ref Username
      Password: !Ref Password
      ServerName: !Ref SourceServer
      Port: !Ref SourcePort
      DatabaseName: !Ref SourceDatabase      
      ExtraConnectionAttributes: "addSupplementalLogging=Y"

  DMSTargetEndpoint:
    Type: "AWS::DMS::Endpoint"
    Properties:
      EndpointIdentifier: !Join
        - ''
        - '-epk-'
        - !Ref Enviroment
        - '-dms-target'
      EngineName: "S3"
      EndpointType: "target"
1 Answers
2
Accepted Answer

Hi, I hope you're keeping well today.

The intrinsic function Fn::Sub would be best for this scenario [1]. So you have your parameter defined like:

Enviroment:
  Type: String
  Default: "dev"
  AllowedValues:
    - "dev"
    - "uat"
    - "prod"

Then in your AWS::DMS::Endpoint resource, for the 'EndpointIdentifier' option define it something like:

Description: "Endpoint test"
Resources: 
  BasicEndpoint: 
    Type: "AWS::DMS::Endpoint"
    Properties: 
      ....
      EndpointIdentifier: !Sub 'fp-epk-${Environment}-dms-target'
    ....
    ....

This will populate the psuedo parameter ${Environment} with the value you selected for the parameter Environment.

I hope you find this useful. If you have any additional queries, please let me know!

REFERENCES:

[1] https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-sub.html

answered 25 days ago
  • Thank you this worked, Thanks for the reply, thanks sir.

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions