Introduction to Amazon CloudWatch (CW)

Amazon CloudWatch – Components and Architecture

Main Components of CloudWatch

  1. CloudWatch Metrics
    • Provides the core metrics service.
    • Examples: CPU utilization of an EC2 instance, disk usage of an on-premises server.
    • Can collect metrics from AWS services, custom applications, or on-premises systems.
    • Some metrics are gathered natively by AWS.
    • A CloudWatch Agent is required to collect:
      • Non-native AWS metrics (e.g., internal processes in EC2 instances)
      • Metrics from outside AWS
    • Metrics should be organized and separated to avoid confusion.
  2. CloudWatch Logs
    • Collects logs from AWS services, applications, or on-premises infrastructure.
    • Some logs are generated natively; others require the CloudWatch Agent.
  3. CloudWatch Alarms
    • Trigger notifications (via Amazon SNS) or events based on monitored metrics.
    • Example: Send an SMS when an EC2 instance’s CPU usage exceeds 90%.
    • Billing alarms are also created in CloudWatch, sending notifications when costs exceed a threshold.
  4. CloudWatch Events (now Amazon EventBridge)
    • Integrates with AWS services and scheduled events.
    • Generates events that can trigger actions, such as sending notifications.
    • Events are generated based on:
      1. Conditions (e.g., EC2 instance creation or termination)
      2. Schedules (e.g., specific times or recurring schedules)
Amazon CloudWatch – Key Concepts

Introduction to AWS CloudFormation (CFN)

IaC Basics and AWS CloudFormation
CFN Templates – Components and Examples

CFN Stacks

Syncing Logical and Physical Resources

Introduction to AWS Lambda

AWS Lambda – Key Concepts
AWS Lambda – Architecture
AWS Lambda – Common Use Cases
Demo: Create and Execute a Lambda Function
  1. Deploy CloudFormation Stack to spin up two EC2 instances:
  2. Create Execution Role in IAM or during Lambda creation.
    • Example JSON for EC2 start/stop permissions:

{
“Version”: “2012-10-17”,
“Statement”: [
{
“Effect”: “Allow”,
“Action”: [
“logs:CreateLogGroup”,
“logs:CreateLogStream”,
“logs:PutLogEvents”
],
“Resource”: “arn:aws:logs:::” }, { “Effect”: “Allow”, “Action”: [ “ec2:Start“,
“ec2:Stop” ], “Resource”: “
}
]
}

  1. Create Lambda Function:
    • Provide a name and select runtime (e.g., Python 3.9).
    • Assign the execution role created in step 2.
  2. Add Code to the function:
Stop EC2 Instances Example:

import boto3
import os

region = ‘us-east-1’
ec2 = boto3.client(‘ec2’, region_name=region)

def lambda_handler(event, context):
instances = os.environ[‘EC2_INSTANCES’].split(“,”)
ec2.stop_instances(InstanceIds=instances)
print(‘Stopped instances: ‘ + str(instances))

  1. Set Environment Variables:
    • Include EC2_INSTANCES with instance IDs (comma-separated).
  2. Test the Function:
    • Click “Test” in the console; verify EC2 instances stop.
  3. After the function executes successfully, output will be displayed in the console and the EC2 instances will be stopped. Confirm this by checking the EC2 console.
  4. Create another function using the same approach to start the EC2 instances. Run or test the function and verify in the EC2 console that the instances have started.
Start EC2 Instances Example:

import boto3
import os

region = ‘us-east-1’
ec2 = boto3.client(‘ec2’, region_name=region)

def lambda_handler(event, context):
instances = os.environ[‘EC2_INSTANCES’].split(“,”)
ec2.start_instances(InstanceIds=instances)
print(‘Started instances: ‘ + str(instances))

9. Clean-up: delete the created functions, then delete the CloudFormation stack

Introduction to Amazon Route 53 (R53)

Amazon Route 53 (R53) – Core Concepts
R53 Registered Domains
R53 Hosted Zones

Identity, Access, and Organizational Management

AWS IAM Basics

Identity and Access Management (IAM) Service
Root User of the Account (Account Root User)
IAM Identities and IAM Policies
Demo: Creating an IAM Admin User in an AWS Account

IAM Access Keys

Long-term and Short-term Credentials
IAM Access Keys
Demo: Creating Access Keys and Configuring AWS CLI v2

IAM Permission Policies

IAM Policy
Policy Statements
Permission Evaluation Logic
Applying Permission Logic (Example)
IAM Policy Types
Attachment Types: Identity Policies vs Resource Policies
Management Types for Identity Policies: Inline vs Managed Policies
Amazon Resource Name (ARN)
arn:partition:service:region:account-id:resource-id
arn:partition:service:region:account-id:resource-type/resource-id
arn:partition:service:region:account-id:resource-type:resource-id

IAM Users and Groups

Principals and IAM Identities
IAM User
IAM Group

IAM Roles

IAM Roles – Key Concepts
IAM Roles – Architecture
Process: Accessing AWS Resources with a Role
  1. Principal attempts to authenticate as the role via IAM
  2. IAM checks the trust policy to ensure the Principal is allowed to assume the role
    • Request is denied if the Principal is not trusted
  3. Principal calls AWS Security Token Service (STS) using sts:AssumeRole
  4. STS generates temporary credentials if allowed
    • The Principal assumes the role and becomes an authenticated identity for a limited time
  5. When credentials expire, the Principal must reassume the role to get new temporary credentials
    • Some AWS services auto-renew STS credentials; external applications (e.g., mobile apps) may need custom auto-renewal logic

Use Cases for IAM Roles

1. Grant AWS Services Permissions
2. Grant Additional Permissions in Extraordinary Situations
3. Grant AWS Access to Existing Corporate Environments
4. Designing Applications with Many Users
5. Cross-Account Access

Service-Linked Roles and PassRole

Service-Linked Role

Example: IAM policy referencing iam:CreateServiceLinkedRole

PassRole