Добрый день.
Пытаюсь создать Alarm, для оповещений на email(когда упал сервер и тд)
Сейчас пробую запустить вот такой тестовый код:
import boto.ec2.cloudwatch
import sys
import os
AWS_KEY = os.environ.get("XXXX")
AWS_SECRET = os.environ.get("XXXX")
AWS_REGION = os.environ.get("AWS_EC2_REGION", "us-west-2")
TOPIC = 'EXAMPLE'
def create_status_alarm(instance_id):
ec2_conn = boto.ec2.connect_to_region(AWS_REGION,
aws_access_key_id=AWS_KEY,
aws_secret_access_key=AWS_SECRET)
cloudwatch_conn = boto.ec2.cloudwatch.connect_to_region(
AWS_REGION,
aws_access_key_id=AWS_KEY,
aws_secret_access_key=AWS_SECRET)
reservations = ec2_conn.get_all_instances(filters = {'instance-id': instance_id})
if reservations and reservations[0].instances:
instance = reservations[0].instances[0]
instance_name = instance.tags['Name']
else:
print "Invalid instance-id!"
sys.exit(1)
alarm = boto.ec2.cloudwatch.alarm.MetricAlarm(
connection = cloudwatch_conn,
name = instance_name + "-status-alarm",
metric = 'StatusCheckFailed',
namespace = 'AWS/EC2',
statistic = 'Maximum',
comparison = '>=',
description = 'status check for %s %s' % (instance_id, instance_name),
threshold = 1.0,
period = 60,
evaluation_periods = 2,
dimensions = {'InstanceId':instance_id},
alarm_actions = [TOPIC],
ok_actions = [TOPIC],
insufficient_data_actions = [TOPIC])
cloudwatch_conn.put_metric_alarm(alarm)
if __name__ == '__main__':
if len(sys.argv) < 2:
print "Usage: create_status_alarm.py <instanceid>"
sys.exit(2)
create_status_alarm(sys.argv[1])
Получаю вот такое:
Traceback (most recent call last):
File "ins.py", line 50, in <module>
create_status_alarm(sys.argv[1])
File "ins.py", line 15, in create_status_alarm
aws_secret_access_key=AWS_SECRET)
File "/usr/local/lib/python2.7/dist-packages/boto/ec2/__init__.py", line 66, in connect_to_region
return region.connect(**kw_params)
File "/usr/local/lib/python2.7/dist-packages/boto/regioninfo.py", line 187, in connect
return self.connection_cls(region=self, **kw_params)
File "/usr/local/lib/python2.7/dist-packages/boto/ec2/connection.py", line 103, in __init__
profile_name=profile_name)
File "/usr/local/lib/python2.7/dist-packages/boto/connection.py", line 1100, in __init__
provider=provider)
File "/usr/local/lib/python2.7/dist-packages/boto/connection.py", line 569, in __init__
host, config, self.provider, self._required_auth_capability())
File "/usr/local/lib/python2.7/dist-packages/boto/auth.py", line 987, in get_auth_handler
'Check your credentials' % (len(names), str(names)))
boto.exception.NoAuthHandlerFound: No handler was ready to authenticate. 1 handlers were checked. ['HmacAuthV4Handler'] Check your credentials
Думаю, что скрипт не видит переменных окружения. Погуглив как их правильно задать, везде натыкаюсь на одно и тоже решение, которое не помогло, собственно Вы его и видите в коде.
Как можно заставить его видить переменные окружения?