Skip to content
Tutorials Center
My learning

Topics

Lesson 47 of 70 ยท Monitoring, operations and cost

Systems Manager and Day-Two Operations

Operate AWS after launch: Session Manager, Parameter Store, Secrets Manager, patching, runbooks and AWS Backup, with a runnable parameter hierarchy emulator.

Launching a system is the easy half. "Day two" is everything after: logging in to fix something, changing a database password, patching servers, restoring last night's data. AWS has a family of services for this work, and the center of it is AWS Systems Manager (SSM), a collection of tools for operating fleets of EC2 instances and on-premises servers without a bastion host or a pile of shell scripts.

This lesson covers five practical pieces: Session Manager for access, Parameter Store and Secrets Manager for configuration and secrets, Patch Manager and Automation runbooks for repetitive work, and AWS Backup for recovery. The code is read-only, except for runnable Python stand-ins that model the parameter hierarchy and backup retention logic.

Systems Manager and AWS Backup run inside AWS and cannot run on this site. CLI commands and JSON are read-only. The Python examples are stand-ins: they show how paths, versions and retention rules behave, not the real services.

The SSM Agent and managed instances

Most Systems Manager features need the SSM Agent, a small program that runs on the instance, calls out to Systems Manager and carries out the tasks it receives. It comes preinstalled on current Amazon Linux, Windows Server and many Ubuntu AMIs. For an instance to appear as a managed instance you need three things:

  1. The agent is running.
  2. The instance has an instance profile (an IAM role) that allows Systems Manager to talk to it. The AWS managed policy AmazonSSMManagedInstanceCore is the usual starting point (see AMIs, User Data and Instance Metadata for instance profiles).
  3. The instance can reach the Systems Manager endpoints over HTTPS, either through a NAT gateway or through VPC endpoints for ssm, ssmmessages and ec2messages.

Notice there is no inbound port in that list. The agent makes outbound connections only, which is why Systems Manager works for servers in private subnets with no public IP.

Session Manager: shell access without SSH

Session Manager gives you a shell on a managed instance through the console or the CLI. Compared with SSH and a bastion host:

  • No inbound ports. The security group needs no rule for port 22 or 3389.
  • No SSH keys to distribute. Access is controlled by IAM: who may start a session on which instances (you can limit by tag).
  • Auditing. Every session start is recorded in CloudTrail, and you can stream the full session output to S3 or CloudWatch Logs.
Terminal
# Start a shell on an instance (read-only here; needs the Session Manager plugin installed)
aws ssm start-session --target i-0abc123def456

# Forward a remote database port to your laptop through the instance
aws ssm start-session \
  --target i-0abc123def456 \
  --document-name AWS-StartPortForwardingSessionToRemoteHost \
  --parameters '{"host":["mydb.cluster-xyz.eu-west-1.rds.amazonaws.com"],"portNumber":["5432"],"localPortNumber":["15432"]}'

The second command is how teams reach private databases without opening them to the internet: your local port 15432 is tunneled to the database through the managed instance. Connecting to Instances and Security Groups compares all the ways to log in.

Parameter Store: configuration in a hierarchy

Applications need settings that differ per environment: a database host, a feature flag, a log level. Hard-coding them in an image or in code makes changes slow and risky. Parameter Store, a part of Systems Manager, keeps them centrally as named parameters.

Names are organized as paths: /shop/prod/db/host, /shop/prod/db/port, /shop/staging/db/host. This hierarchy is the main feature. IAM can allow an application access to arn:aws:ssm:*:*:parameter/shop/prod/* only, and the application can fetch the whole branch in one call.

There are three parameter types: String, StringList (comma-separated values) and SecureString, whose value is encrypted with a KMS key (see Encryption and KMS). Parameters are versioned: each update creates a new version, and you can attach a label such as stable to a version and ask for it by name. The standard tier is free for up to 10,000 parameters with values up to 4 KB; the advanced tier costs money, allows values up to 8 KB and adds parameter policies (for example an expiration date).

Terminal
aws ssm put-parameter --name /shop/prod/db/host --type String --value mydb.example.internal
aws ssm put-parameter --name /shop/prod/db/password --type SecureString --value 'change-me'
aws ssm get-parameters-by-path --path /shop/prod --recursive --with-decryption

The stand-in below implements the core behaviors: path hierarchy, version history, labels and the "get a whole branch" call. A SecureString is only marked here (there is no real KMS): the emulator hides the value unless you ask for decryption, mimicking --with-decryption.

Python A Parameter Store emulator with paths, versions and labels

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Notice what the two get_by_path calls return. Non-recursive reads return only parameters directly under /shop/prod, skipping /shop/prod/db/.... The recursive call reaches all of them. A good habit is to give each application a path of its own and write IAM policies against that path, so one service cannot read another service's settings.

Secrets Manager: secrets that rotate

A SecureString parameter can store a password, but AWS Secrets Manager is built for secrets. Its main extra is automatic rotation: on a schedule, a Lambda function creates a new password, sets it on the database, tests it and switches the secret to the new value. Applications that fetch the secret at start-up (or at connection time) never see a hard-coded password. Secrets Manager also supports replication to other Regions, resource policies and larger values.

The trade-off is cost: Secrets Manager charges per secret per month plus API calls, while standard parameters are free. A common rule of thumb: plain configuration goes in Parameter Store, and credentials that benefit from rotation go in Secrets Manager. The Secrets, WAF, Shield and GuardDuty lesson covers rotation in more detail.

Python
import boto3, json

client = boto3.client("secretsmanager")
secret = json.loads(client.get_secret_value(SecretId="shop/prod/db")["SecretString"])
# secret == {"username": "app", "password": "...", "host": "...", "port": 5432}

Patch Manager, Run Command and runbooks

Servers need operating system updates. Patch Manager applies them on a schedule. You define a patch baseline (which patches are approved, for example "critical and security, three days after release"), put instances into patch groups by tag, and run patching inside a maintenance window that fits your business hours. A scan-only mode reports what is missing without installing anything.

Other tools in the same family:

  • Run Command runs a script or document on many instances at once, targeted by tag, with output collected centrally and no SSH.
  • State Manager keeps instances in a desired state, for example "this agent is always installed".
  • Automation runs runbooks: ordered, parameterized steps that can call AWS APIs, wait for conditions and approve before continuing. AWS supplies many (for example restarting instances or creating an AMI), and you can write your own in YAML. Config remediation and CloudWatch alarm actions can trigger runbooks, so recurring fixes become hands-off. See CloudTrail, Config and X-Ray for the detection side.
  • Inventory lists installed software and settings across the fleet.

Targeting by tag is the trick that makes all of this scale: tag instances with Patch Group=web or Env=prod, and your commands, patch runs and IAM permissions follow the tags.

Terminal
aws ssm send-command \
  --document-name AWS-RunShellScript \
  --targets Key=tag:Role,Values=web \
  --parameters 'commands=["systemctl is-active nginx"]'

AWS Backup

Backups only count if they are automatic, protected and tested. AWS Backup is a central service that handles backups for EBS, RDS, DynamoDB, EFS, S3 and more, with one policy model:

  • A backup plan has one or more rules: a schedule, a lifecycle (when to move to cold storage, when to delete) and a destination vault.
  • A backup vault is the container for recovery points. A vault lock can make backups immutable, so even an administrator or attacker cannot delete them early.
  • Resource assignments pick what to protect, usually by tag (for example backup=daily), so new resources are covered automatically.
  • Rules can copy recovery points to another Region or account for disaster recovery.

The stand-in below simulates a plan with daily backups kept for seven days, plus a monthly one kept for a year, and prints what exists after a period of time. It teaches how retention overlaps.

Python Backup plan retention: daily and monthly rules

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The result shows the typical shape: only the last week of daily backups survives, but monthly points reach back to January. For February 5 only the monthly point from January 31 is left, so you would restore data that is five days old (with monthly points, the gap can be up to 30 days). That gap is your recovery point objective (RPO), a topic in High Availability and Disaster Recovery. Finally, run a restore test now and then: an untested backup is only a hope.

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. Which inbound security group rules does Session Manager need to reach an instance?

    The SSM Agent initiates outbound HTTPS connections, so no inbound rule is needed. The instance still needs an instance profile and a route to the Systems Manager endpoints.
  2. 2. Which Parameter Store type should hold a database password?

    SecureString encrypts the value with KMS, and readers need permission to use the key as well. String values are stored in plain form.
  3. 3. Why use a hierarchy such as /shop/prod/db/host for parameter names?

    Paths let you grant access per application and environment and fetch a whole branch with GetParametersByPath.
  4. 4. What is the main advantage of Secrets Manager over a plain SecureString parameter?

    Secrets Manager can run a rotation function that creates and sets a new password. It costs per secret, whereas standard parameters are free.
  5. 5. How does AWS Backup decide which resources a plan protects?

    A resource assignment selects resources, usually by tag, so new tagged resources are protected without changing the plan.

Summary

  • Systems Manager manages instances through the SSM Agent, an instance profile and outbound HTTPS only.
  • Session Manager replaces SSH and bastions: no inbound ports, IAM-controlled, audited, and able to tunnel ports to private databases.
  • Parameter Store keeps configuration in versioned path hierarchies; use SecureString for sensitive values and Secrets Manager when you want automatic rotation.
  • Patch Manager, Run Command, State Manager and Automation runbooks apply changes to fleets, targeted by tag and run in maintenance windows.
  • AWS Backup uses plans, vaults, lifecycle rules and tag-based assignments, can lock backups against deletion and copy them across Regions. Test restores regularly.

Next: Cost Management and Optimization