Complete the code to define a CloudWatch alarm that monitors CPU utilization.
resource "aws_cloudwatch_metric_alarm" "cpu_alarm" { alarm_name = "HighCPU" comparison_operator = "[1]" evaluation_periods = 2 metric_name = "CPUUtilization" namespace = "AWS/EC2" period = 300 statistic = "Average" threshold = 80 alarm_description = "Alarm when CPU exceeds 80%" }
The alarm triggers when CPU utilization is greater than the threshold, so GreaterThanThreshold is correct.
Complete the code to enable detailed monitoring on an EC2 instance.
resource "aws_instance" "web" { ami = "ami-12345678" instance_type = "t2.micro" monitoring = [1] }
Setting monitoring = true enables detailed monitoring on the EC2 instance.
Fix the error in the CloudFormation snippet to correctly create an S3 bucket with versioning enabled.
Resources:
MyBucket:
Type: AWS::S3::Bucket
Properties:
BucketName: my-app-bucket
VersioningConfiguration:
Status: [1]The Status property must be Enabled with a capital E in CloudFormation.
Fill both blanks to create an IAM policy statement that allows reading objects from a specific S3 bucket.
Statement:
- Effect: Allow
Action: [1]
Resource: [2]The action to read objects is s3:GetObject, and the resource must include the bucket path with /* to specify objects inside the bucket.
Fill all three blanks to define a CloudWatch Logs subscription filter that sends error logs to a Lambda function.
resource "aws_cloudwatch_log_subscription_filter" "error_filter" { name = "ErrorFilter" log_group_name = [1] filter_pattern = [2] destination_arn = [3] }
The log_group_name must be the log group to monitor, filter_pattern is the keyword to filter logs (like 'ERROR'), and destination_arn is the Lambda function ARN receiving the logs.