Complete the code to specify the namespace when creating a CloudWatch metric.
metric = cloudwatch.Metric(namespace=[1], metric_name="PageViews")
The namespace groups metrics logically. Custom metrics often use a custom namespace like "MyApp/Metrics".
Complete the code to create a CloudWatch alarm that triggers when CPU utilization exceeds 80%.
alarm = cloudwatch.Alarm(threshold=[1], comparison_operator="GreaterThanThreshold")
The alarm triggers when CPU utilization is greater than 80%, so the threshold must be 80.
Fix the error in the code to correctly publish a custom metric value to CloudWatch.
cloudwatch.put_metric_data(Namespace="MyApp", MetricData=[[1]])
The MetricData list requires dictionaries with keys MetricName and Value. Option C is correct.
Fill both blanks to create a CloudWatch metric filter that matches error logs and extracts the error code.
filter = cloudwatch.MetricFilter(log_group_name=[1], filter_pattern=[2])
The log group name must be a valid string, and the filter pattern must match error logs and extract the errorCode field.
Fill all three blanks to define a CloudWatch dashboard widget showing average CPU utilization for an EC2 instance.
widget = cloudwatch.DashboardWidget(type=[1], properties={"metrics": [[[2], "CPUUtilization", "InstanceId", [3]]], "period": 300, "stat": "Average"})
The widget type for metrics is "metric". The namespace for EC2 is "AWS/EC2". The instance ID must be a string identifying the EC2 instance.