getUniqueResourceName()

in source/networkFirewallAutomation/lib/common/stringUtils.ts [36:54]


  getUniqueResourceName(resourceName: string) {
    Logger.log(LOG_LEVEL.DEBUG, `Resource name input: ${resourceName}`)
    if (this.stackId) {
      const splitStackId = this.stackId.split("-").pop()
      let customName = resourceName + Name.delimiter + splitStackId
      if (splitStackId && customName.length > Name.maxCharacters) {
        const sliceString = Name.maxCharacters - (splitStackId.length + Name.delimiter.length)
        Logger.log(LOG_LEVEL.INFO, `Modified name is larger than 128 characters, trimming the resource name and using only first ${sliceString.toString()} characters from the name.`)
        const trimmedResourceName = resourceName.substring(0, sliceString)
        customName = trimmedResourceName + Name.delimiter + splitStackId
      }
      Logger.log(LOG_LEVEL.DEBUG, `Returning Custom name : ${resourceName}`)
      return customName
    }
    else {
      throw Error("The stack id environment variable is undefined in the" +
        " CodeBuild stage environment variables.")
    }
  }