2016-04-14 4 views
3

私は、自動スケーリンググループを監視するクラウドウォッチアラームを作成するために、ec2_metric_alarmタスクを使用して、ASGのCPU使用率が上になる場合は自動スケーリングポリシーを有効にしますまたはある点以下になることがあります。私はちょうど(「cpuDown_test3_policy」と「cpuUP_test3_policy」されるであろう)私の自動スケーリング政策のリテラル名を使用することはできませんし、私は私のエラーメッセージので「ARN構文」と呼ばれるものを使用する必要が何らかの理由でac2_metric_alarmが自動スケーリングポリシーにアタッチされない

- ec2_metric_alarm: 
     aws_access_key: '{{ ami_access }}' 
     aws_secret_key: '{{ ami_secret }}' 
     state: present 
     region: "{{regi}}" 
     name: "{{item.names}}" 
     metric: "CPUUtilization" 
     namespace: "AWS/EC2" 
     statistic: Average 
     comparison: "{{item.compare}}" 
     threshold: "{{item.limits}}" 
     period: 60 
     evaluation_periods: 1 
     unit: "Percent" 
     description: "{{item.desc}}" 
     dimensions: {'AutoScalingGroupName':'{{auto_sc}}'} 
     alarm_actions: "{{item.pol}}" 
    with_items: 
     - names: "cpuUP_{{auto_sc}}" 
     compare: ">=" 
     limits: "20.0" 
     desc: "This will alarm when the average cpu usage of the ASG is   greater than 20% for 1 minute" 
     pol: "cpuUP_{{auto_sc}}_policy" 
     - names: "cpuDown_{{auto_sc}}" 
     compare: "<=" 
     limits: "10.0" 
     desc: "This will alarm when the average cpu usage of the ASG is less than 10% for 1 minute" 
     pol: "cpuDown_{{auto_sc}}_policy" 

無効なArn構文について不平を言い続けてください。

arn構文を見つける方法、または自動スケーリングポリシー名をarn構文に変換するにはどうすればよいですか?参考のため

ここで私のように私の脚本を実行しようとすると、私はエラーメッセージがあるさ:

TASK [ec2_metric_alarm]  ******************************************************** 
failed: [localhost] => (item={u'pol': u'cpuUP_test3_policy', u'desc': u'This wil 
l alarm when the average cpu usage of the ASG is greater than 20% for 1  minute', 
u'compare': u'>=', u'limits': u'20.0', u'names': u'cpuUP_test3'}) =>  {"failed": 
true, "item": {"compare": ">=", "desc": "This will alarm when the average  cpu u 
sage of the ASG is greater than 20% for 1 minute", "limits": "20.0",  "names": "c 
puUP_test3", "pol": "cpuUP_test3_policy"}, "msg": "BotoServerError: 400 Bad  Requ 
est\n<ErrorResponse xmlns=\"http://monitoring.amazonaws.com/doc/2010-08- 01/\">\n 
    <Error>\n <Type>Sender</Type>\n <Code>ValidationError</Code>\n  <Messa 
ge>Invalid arn syntax: cpuUP_test3_policy</Message>\n </Error>\n  <RequestId>d8 
97c79a-01db-11e6-92d5-5fa534a149e9</RequestId>\n</ErrorResponse>\n"} 
failed: [localhost] => (item={u'pol': u'cpuDown_test3_policy', u'desc':  u'This w 
ill alarm when the average cpu usage of the ASG is less than 10% for 1  minute', 
u'compare': u'<=', u'limits': u'10.0', u'names': u'cpuDown_test3'}) =>  {"failed" 
: true, "item": {"compare": "<=", "desc": "This will alarm when the average  cpu 
usage of the ASG is less than 10% for 1 minute", "limits": "10.0", "names":  "cpu 
Down_test3", "pol": "cpuDown_test3_policy"}, "msg": "BotoServerError: 400  Bad Re 
quest\n<ErrorResponse xmlns=\"http://monitoring.amazonaws.com/doc/2010-08- 01/\"> 
\n <Error>\n <Type>Sender</Type>\n <Code>ValidationError</Code>\n  <Mes 
sage>Invalid arn syntax: cpuDown_test3_policy</Message>\n </Error>\n  <RequestI 
d>d8b33ea6-01db-11e6-82db-8bfc9e3af9a2</RequestId>\n</ErrorResponse>\n"} 

答えて

4

ここAmazon Resource Name. を説明して提供されたリンクからの抜粋です。このリンクをお読みください。

Amazonリソース名(ARN)は、AWSリソースを一意に識別します。 IAMポリシー、Amazon Relational Database Service(Amazon RDS)タグ、APIコールなど、すべてのAWSでリソースを明白に指定する必要がある場合は、ARNが必要です。ここで

何alarm_actionsの例です:あなたはスケーリングポリシー第一を作成し、使用するスケーリングポリシーのARNをつかむために登録された出力を使用する必要があります。..

alarm_actions: ["arn:aws:autoscaling:region:account-id:scalingPolicy:policyid:autoScalingGroupName/groupfriendlyname:policyname/policyfriendlyname"] 

のようになります。 。ここで

は例..です

- name: Scale Out policy 
    local_action: 
    module: ec2_scaling_policy 
    state: present 
    region: "{{ aws_region }}" 
    name: "Name-ScaleOutPolicy" 
    adjustment_type: "ChangeInCapacity" 
    asg_name: "name_of_autoscale_group" 
    scaling_adjustment: "-1" 
    min_adjustment_step: "1" 
    cooldown: "30" 
    register: so_result 

今、あなたはそうのように、スケーリングポリシーARNを使用するようにメトリックのアラームを設定することができます。

alarm_actions: ['{{ so_result["arn"] }}'] 
+0

ありがとうございました! –

関連する問題