I am trying to get an env variable in Kotlin using another environment variable. For example, if I have a unique variable per AWS Region, I'd like something like this: System.getenv("Key"-$aws_region"). However, I can't seem to get it working right now (it is always null). Is the following syntax correct or am I missing something?
val awsRegionProvider: String =
when {
System.getenv("aws_region") != null -> System.getenv("aws_region")
else -> ""
}
}
val uniqueKey: String =
System.getenv("UniqueKey-$awsRegionProvider")
I've already added aws_region & UniqueKey-us-west-2 to my env variables but uniqueKey complains about being null. Let me know if there are further details I can add.
Provider? (Also, you can replace the wholewhenblock withSystem.getenv("aws_region") ?: "".)