Wanted to get some feed back on some code I wrote ...
# general
r
Wanted to get some feed back on some code I wrote to loop through different conditions on creating an alarm for route53. Could I have done this in a better way?
Copy code
environments = {
    'HealthChecks': [health_check_1.id, health_check_2.id],
    'Names': ['Primary', 'Secondary']
}

# Metric alarm for both primary and secondary sites
for index in range(0, (len(environments))):
    cloudwatch.MetricAlarm(
        f"{environments['Names'][index]}_site_alarm",
        __opts__=ResourceOptions(
            depends_on=[sns_topic, sns_email]),
        alarm_actions=[sns_topic.arn],
        alarm_description=f"{environments['Names'][index]} alarm for website",
        name=f"{environments['Names'][index]}_site",
        comparison_operator="LessThanThreshold",
        statistic="Minimum", evaluation_periods=3,
        metric_name="HealthCheckStatus",
        namespace="AWS/Route53",
        period=60, threshold=1,
        dimensions={
            'HealthCheckId': environments['HealthChecks'][index]
        }
    )
w
Looks reasonable to me! You could probably simplify a little by “transposing” your environments variable - make it an array of objects instead of an object of arrays - then doing
for env in environments
.
m
You shouldnt use
__opts__
but instead just
opts