Extraits CloudWatch de modèles Amazon - AWS CloudFormation

Les traductions sont fournies par des outils de traduction automatique. En cas de conflit entre le contenu d'une traduction et celui de la version originale en anglais, la version anglaise prévaudra.

Extraits CloudWatch de modèles Amazon

Utilisez ces exemples d'extraits de modèles pour décrire vos ressources Amazon CloudWatch dans AWS CloudFormation. Pour plus d'informations, consultez la référence CloudWatch des types de ressources Amazon.

Alarme de facturation

Dans l'exemple suivant, Amazon CloudWatch envoie une notification par e-mail lorsque des frais sont facturés à votre AWS le compte dépasse le seuil d'alarme. Pour recevoir des notifications d'utilisation, activez les alertes de facturation. Pour plus d'informations, voir Créer une alarme de facturation pour surveiller votre estimation AWS frais indiqués dans le guide de CloudWatch l'utilisateur Amazon. >

JSON

"SpendingAlarm": { "Type": "AWS::CloudWatch::Alarm", "Properties": { "AlarmDescription": { "Fn::Join": ["", [ "Alarm if AWS spending is over $", { "Ref": "AlarmThreshold" } ]]}, "Namespace": "AWS/Billing", "MetricName": "EstimatedCharges", "Dimensions": [{ "Name": "Currency", "Value" : "USD" }], "Statistic": "Maximum", "Period": "21600", "EvaluationPeriods": "1", "Threshold": { "Ref": "AlarmThreshold" }, "ComparisonOperator": "GreaterThanThreshold", "AlarmActions": [{ "Ref": "BillingAlarmNotification" }], "InsufficientDataActions": [{ "Ref": "BillingAlarmNotification" }] } }

YAML

SpendingAlarm: Type: AWS::CloudWatch::Alarm Properties: AlarmDescription: 'Fn::Join': - '' - - Alarm if AWS spending is over $ - !Ref: AlarmThreshold Namespace: AWS/Billing MetricName: EstimatedCharges Dimensions: - Name: Currency Value: USD Statistic: Maximum Period: '21600' EvaluationPeriods: '1' Threshold: !Ref: "AlarmThreshold" ComparisonOperator: GreaterThanThreshold AlarmActions: - !Ref: "BillingAlarmNotification" InsufficientDataActions: - !Ref: "BillingAlarmNotification"

CPUalarme d'utilisation

L'exemple d'extrait suivant crée une alarme qui envoie une notification lorsque l'CPUutilisation moyenne d'une EC2 instance Amazon dépasse 90 % pendant plus de 60 secondes sur trois périodes d'évaluation.

JSON

"CPUAlarm" : { "Type" : "AWS::CloudWatch::Alarm", "Properties" : { "AlarmDescription" : "CPU alarm for my instance", "AlarmActions" : [ { "Ref" : "logical name of an AWS::SNS::Topic resource" } ], "MetricName" : "CPUUtilization", "Namespace" : "AWS/EC2", "Statistic" : "Average", "Period" : "60", "EvaluationPeriods" : "3", "Threshold" : "90", "ComparisonOperator" : "GreaterThanThreshold", "Dimensions" : [ { "Name" : "InstanceId", "Value" : { "Ref" : "logical name of an AWS::EC2::Instance resource" } } ] } }

YAML

CPUAlarm: Type: AWS::CloudWatch::Alarm Properties: AlarmDescription: CPU alarm for my instance AlarmActions: - !Ref: "logical name of an AWS::SNS::Topic resource" MetricName: CPUUtilization Namespace: AWS/EC2 Statistic: Average Period: '60' EvaluationPeriods: '3' Threshold: '90' ComparisonOperator: GreaterThanThreshold Dimensions: - Name: InstanceId Value: !Ref: "logical name of an AWS::EC2::Instance resource"

Récupération d'une instance Amazon Elastic Compute Cloud

L' CloudWatch alarme suivante permet de récupérer une EC2 instance lorsque le contrôle de statut échoue pendant 15 minutes consécutives. Pour plus d'informations sur les actions d'alarme, consultez la section Créer des alarmes pour arrêter, résilier, redémarrer ou récupérer une EC2 instance dans le guide de CloudWatch l'utilisateur Amazon.

JSON

{ "AWSTemplateFormatVersion": "2010-09-09", "Parameters" : { "RecoveryInstance" : { "Description" : "The EC2 instance ID to associate this alarm with.", "Type" : "AWS::EC2::Instance::Id" } }, "Resources": { "RecoveryTestAlarm": { "Type": "AWS::CloudWatch::Alarm", "Properties": { "AlarmDescription": "Trigger a recovery when instance status check fails for 15 consecutive minutes.", "Namespace": "AWS/EC2" , "MetricName": "StatusCheckFailed_System", "Statistic": "Minimum", "Period": "60", "EvaluationPeriods": "15", "ComparisonOperator": "GreaterThanThreshold", "Threshold": "0", "AlarmActions": [ {"Fn::Join" : ["", ["arn:aws:automate:", { "Ref" : "AWS::Region" }, ":ec2:recover" ]]} ], "Dimensions": [{"Name": "InstanceId","Value": {"Ref": "RecoveryInstance"}}] } } } }

YAML

AWSTemplateFormatVersion: '2010-09-09' Parameters: RecoveryInstance: Description: The EC2 instance ID to associate this alarm with. Type: AWS::EC2::Instance::Id Resources: RecoveryTestAlarm: Type: AWS::CloudWatch::Alarm Properties: AlarmDescription: Trigger a recovery when instance status check fails for 15 consecutive minutes. Namespace: AWS/EC2 MetricName: StatusCheckFailed_System Statistic: Minimum Period: '60' EvaluationPeriods: '15' ComparisonOperator: GreaterThanThreshold Threshold: '0' AlarmActions: [ !Sub "arn:aws:automate:${AWS::Region}:ec2:recover" ] Dimensions: - Name: InstanceId Value: !Ref: RecoveryInstance

Création d'un tableau de bord de base

L'exemple suivant crée un CloudWatch tableau de bord simple avec un widget métrique affichant CPU l'utilisation et un widget texte affichant un message.

JSON

{ "BasicDashboard": { "Type": "AWS::CloudWatch::Dashboard", "Properties": { "DashboardName": "Dashboard1", "DashboardBody": "{\"widgets\":[{\"type\":\"metric\",\"x\":0,\"y\":0,\"width\":12,\"height\":6,\"properties\":{\"metrics\":[[\"AWS/EC2\",\"CPUUtilization\",\"InstanceId\",\"i-012345\"]],\"period\":300,\"stat\":\"Average\",\"region\":\"us-east-1\",\"title\":\"EC2 Instance CPU\"}},{\"type\":\"text\",\"x\":0,\"y\":7,\"width\":3,\"height\":3,\"properties\":{\"markdown\":\"Hello world\"}}]}" } } }

YAML

BasicDashboard: Type: AWS::CloudWatch::Dashboard Properties: DashboardName: Dashboard1 DashboardBody: '{"widgets":[{"type":"metric","x":0,"y":0,"width":12,"height":6,"properties":{"metrics":[["AWS/EC2","CPUUtilization","InstanceId","i-012345"]],"period":300,"stat":"Average","region":"us-east-1","title":"EC2 Instance CPU"}},{"type":"text","x":0,"y":7,"width":3,"height":3,"properties":{"markdown":"Hello world"}}]}'

Création d'un tableau de bord avec des side-by-side widgets

L'exemple suivant permet de créer un tableau de bord avec deux widgets de métrique s'affichant côte à côte.

JSON

{ "DashboardSideBySide": { "Type": "AWS::CloudWatch::Dashboard", "Properties": { "DashboardName": "Dashboard1", "DashboardBody": "{\"widgets\":[{\"type\":\"metric\",\"x\":0,\"y\":0,\"width\":12,\"height\":6,\"properties\":{\"metrics\":[[\"AWS/EC2\",\"CPUUtilization\",\"InstanceId\",\"i-012345\"]],\"period\":300,\"stat\":\"Average\",\"region\":\"us-east-1\",\"title\":\"EC2 Instance CPU\"}},{\"type\":\"metric\",\"x\":12,\"y\":0,\"width\":12,\"height\":6,\"properties\":{\"metrics\":[[\"AWS/S3\",\"BucketSizeBytes\",\"BucketName\",\"amzn-s3-demo-bucket\"]],\"period\":86400,\"stat\":\"Maximum\",\"region\":\"us-east-1\",\"title\":\"amzn-s3-demo-bucket bytes\"}}]}" } } }

YAML

DashboardSideBySide: Type: AWS::CloudWatch::Dashboard Properties: DashboardName: Dashboard1 DashboardBody: '{"widgets":[{"type":"metric","x":0,"y":0,"width":12,"height":6,"properties":{"metrics":[["AWS/EC2","CPUUtilization","InstanceId","i-012345"]],"period":300,"stat":"Average","region":"us-east-1","title":"EC2 Instance CPU"}},{"type":"metric","x":12,"y":0,"width":12,"height":6,"properties":{"metrics":[["AWS/S3","BucketSizeBytes","BucketName","amzn-s3-demo-bucket"]],"period":86400,"stat":"Maximum","region":"us-east-1","title":"amzn-s3-demo-bucket bytes"}}]}'