How to convert CommaDelimitedList Parameter to String for passing it as environment variable to Lamda Function ?
Below is sample CommaDelimitedList Parameter containing list of AWS regions which I need to pass it as Environment variable to AWS Lambda function in cloud formation template. The reason is when I try to pass it as it is !Ref ExternalRegions
it gives error when create/update of the stack:
Properties validation failed for resource LambdaFunction with message: #/Environment/Variables/EXTERNAL_REGIONS: expected type: String, found: JSONArray
Parameters:
ExternalRegions:
Description: CSV delimited account regions
Type: CommaDelimitedList
Resources:
LambdaFunction:
Type: AWS::Lambda::Function
Properties:
Environment:
Variables:
EXTERNAL_REGIONS: !Ref ExternalRegions
Parameter Template:
[{
"ParameterKey": "ExternalRegions",
"ParameterValue": "us-east-1,us-west-2,ap-southeast-1"
}]
Could you please help, I am looking for a way to cast csv list into string so that I don't have to create another String variable with same values and always bother to keep them in sync during future changes.
Thanks in advace.
Scrub
Can't use comma in environment variable value in Lambda?
My recommendation would be to just changes the Parameter to Type: String since it looks like your lambda function will have to handle the ;
delimiter anyway.
Additionally, I'd be wary of using a semicolon as a delimiter in environment variables since it can have unexpected/unintended side effects... (particularly in a shell)