1

I am using environment variables in Lambda to collect list of alarm names, then pass it to the AlarmNames field in Cloudwatch API cloudwatch.describe_alarms(AlarmNames=[])

Keep having error in type, the type that is accepted by the API is list and tuple.

env = os.environ['ALARM_NAMES']
response = cloudwatch.describe_alarms(
    AlarmNames= env
)

this are the environment variables field for ALARM_NAMES: 'instance1-freediskspace C','instance2-freediskspace C','instance3-freediskspace C'

2
  • How is ALARM_NAMES being set? Can you print the env here and update the question with an example value? Commented Aug 21, 2019 at 7:55
  • updated with sample values in environment variables. Commented Aug 21, 2019 at 9:36

2 Answers 2

4

Environment variables are strings. To get a tuple or a list you can split the string by some separator:

"mystring1;mystring2".split(";")  # -> ['mystring1', 'mystring2']
Sign up to request clarification or add additional context in comments.

1 Comment

the function able to run without errors, but the describe_alarms failed to return any results, this means that none of the env variables were passed into the argument list
1

If this is the value of env:

"'instance1-freediskspace C','instance2-freediskspace C','instance3-freediskspace C'"

you need to remove the single quotes and split by the comma to get the list. Like this for example:

AlarmNames= env.replace("'", "").split(',')

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.