July Release Confetti
150+ New Courses, Hands‑On Labs, And
Interactive Learning Activities
Learn More

CloudWatch Events

Length: 00:20:40

Lesson Summary:

CloudWatch Events allow us to create rules that we can trigger by services and API calls or through scheduling. These rules can then interact with many different services in our environment. CloudWatch Events are the central block in many automation workflows we can build as well. This lesson dives into the specifics and shows some examples of how we can use this service.

https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/ScheduledEvents.html

https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/iam-access-control-identity-based-cwe.html

Lambda Function


import boto3

def lambda_handler(event, context):

    # set the region to the region the event occured in
    region=event['region'] 
    instances=[event['detail']['instance-id']]

    print 'detected stopped instance : ' + str(instances)
    ec2 = boto3.client('ec2', region_name=region)
    ec2.start_instances(InstanceIds=instances)
    print 'started your instances: ' + str(instances)


This lesson is only available to Linux Academy members.

Sign Up To View This Lesson
Or Log In

Looking For Team Training?

Learn More