Skip to Content

AWS KMS

AWS Key Management Service, symmetric and asymmetric KMS keys, AWS owned, AWS managed and customer managed keys, pricing, key rotation, key policies, and copying encrypted snapshots across Regions and accounts.

What it is

AWS KMS (Key Management Service) creates and controls encryption keys.

  • Whenever "encryption" comes up for an AWS service, it's most likely KMS.
  • AWS manages the encryption keys: they're kept in hardware security modules (validated to FIPS 140-3 Level 3).
  • Fully integrated with IAM for authorization.
  • A straightforward way to control access to data.
  • Audit every use of a key with CloudTrail.
  • Seamlessly integrated into most AWS services (EBS, S3, RDS, SSM…).
  • Never ever store secrets in plaintext, especially in code!
    • KMS encryption is also available through API calls (SDK, CLI);
    • encrypted secrets can be stored in the code or environment variables.

Key types

KMS keys is the new name for KMS customer master keys (CMK).

  • Symmetric (AES-256):
    • a single encryption key used to encrypt and decrypt;
    • AWS services integrated with KMS use symmetric keys;
    • the key is never accessible unencrypted (using it requires a call to the KMS API).
  • Asymmetric (RSA and ECC key pairs):
    • a public key (encrypt) and private key (decrypt) pair;
    • used for encrypt/decrypt, or sign/verify;
    • the public key is downloadable, but the private key is never accessible unencrypted;
    • use case: encryption outside AWS by users who can't call the KMS API.

Who owns the key, and what it costs

  • AWS owned keys (free): used by SSE-S3, SSE-SQS, DynamoDB's default encryption. They are not visible in the account.
  • AWS managed keys (free to keep): named aws/service-name, such as aws/rds or aws/ebs. Their use by the service is billed.
  • Customer managed keys created in KMS: $1 per month.
  • Customer managed keys imported (customer-supplied key material): $1 per month.
  • Plus API calls to KMS: about $0.03 per 10,000 calls (20,000 calls a month are free).

Updated since the slides

AWS managed keys are now a legacy key type: AWS stopped creating them for new services in 2021 (existing ones like aws/ebs remain). Resources encrypted with an AWS managed key can't be shared with other accounts, so use a customer managed key when sharing is needed. Each automatic or on-demand rotation of a customer managed key also adds $1 a month, for the first two rotations only.

Automatic key rotation

  • AWS managed keys: rotated automatically every year; this can't be changed.
  • Customer managed keys: automatic rotation must be enabled; every year by default (or a custom period), and on demand at any time.
  • Imported key material: rotate on demand, or manually by creating a new key and moving an alias to it.

Updated since the slides

The slides say imported keys can only be rotated manually with an alias. KMS now supports on-demand rotation for symmetric keys with imported key material. Manual rotation with an alias is still the way for asymmetric and HMAC keys, and keys in custom key stores.

Key policies

  • Control access to KMS keys, "similar" to S3 bucket policies.
  • Difference: access cannot be controlled without them. Every KMS key has a key policy.
  • Default key policy:
    • created if no specific one is provided;
    • gives the AWS account (root) complete access to the key, so IAM policies in the account can grant access.
  • Custom key policy:
    • define the users and roles that can use the key;
    • define who can administer the key;
    • useful for cross-account access to a KMS key.

Copying snapshots across Regions

Copying an encrypted EBS snapshot across Regions: in eu-west-2 the volume and its snapshot are encrypted with KMS key A; the copy to ap-southeast-2 is re-encrypted with KMS key B, which exists in that Region, and a new volume encrypted with key B is created from it Copying an encrypted EBS snapshot across Regions: in eu-west-2 the volume and its snapshot are encrypted with KMS key A; the copy to ap-southeast-2 is re-encrypted with KMS key B, which exists in that Region, and a new volume encrypted with key B is created from it

KMS keys are Regional, so the copy is re-encrypted.

KMS keys are Regional (except multi-Region keys). To move an encrypted snapshot to another Region, copy it and choose a key in the destination Region: KMS re-encrypts it with key B.

Copying snapshots across accounts

Sharing an encrypted snapshot with another account: account A encrypts the snapshot with a customer managed key, adds a key policy that lets account B use the key, and shares the snapshot; account B copies it, re-encrypting with its own key, and creates a volume from the copy Sharing an encrypted snapshot with another account: account A encrypts the snapshot with a customer managed key, adds a key policy that lets account B use the key, and shares the snapshot; account B copies it, re-encrypting with its own key, and creates a volume from the copy

Share the snapshot and the key.
  1. Create a snapshot encrypted with a customer-owned KMS key (a customer managed key).
  2. Attach a KMS key policy to authorize cross-account access.
  3. Share the encrypted snapshot.
  4. In the target account, create a copy of the snapshot, encrypted with a key in that account.
  5. Create a volume from the snapshot.

The key policy statement looks like this:

{
  "Sid": "Allow use of the key with destination account",
  "Effect": "Allow",
  "Principal": { "AWS": "arn:aws:iam::TARGET-ACCOUNT-ID:role/ROLENAME" },
  "Action": ["kms:Decrypt", "kms:CreateGrant"],
  "Resource": "*",
  "Condition": {
    "StringEquals": {
      "kms:ViaService": "ec2.REGION.amazonaws.com",
      "kms:CallerAccount": "TARGET-ACCOUNT-ID"
    }
  }
}

Real-world examples

  • A bank encrypts its RDS databases with customer managed keys, turns on yearly rotation, and reviews every Decrypt call in CloudTrail.
  • A company shares nightly encrypted EBS snapshots with its backup account: the snapshot's customer managed key has a key policy allowing that account.

Exam tips

  • "Encrypt data at rest and audit key usage" → KMS (+ CloudTrail).
  • "Users outside AWS must encrypt data they send" → asymmetric KMS key (download the public key).
  • "Share an encrypted snapshot or AMI with another account" → customer managed key + key policy + share.
  • "Copy an encrypted snapshot to another Region" → copy and re-encrypt with a key in that Region.
  • "Automatic yearly key rotation" → enable rotation on a customer managed key.

Common traps

  • "Share a snapshot encrypted with the default aws/ebs key." AWS managed keys can't be shared; re-encrypt with a customer managed key first.
  • "IAM policies alone control KMS access." The key policy must allow it (the default policy enables IAM).
  • "KMS keys are global." They're Regional, except multi-Region keys.

Hands-on lab: encrypt and decrypt with a KMS key

Goal: create a customer managed key and use it from the CLI.

Costs money

A customer managed key costs $1 a month, prorated by the hour, and stops billing once scheduled for deletion (the minimum waiting period is 7 days). A few API calls are within the free tier. Expect a few cents. Any Region works.

Create the key

KMS → Customer managed keys → Create key: symmetric, encrypt and decrypt, alias saa-demo. Add yourself as key administrator and key user.

Encrypt

In CloudShell:

echo -n "my secret" > secret.txt
aws kms encrypt --key-id alias/saa-demo --plaintext fileb://secret.txt \
  --query CiphertextBlob --output text | base64 --decode > secret.enc

Decrypt

aws kms decrypt --ciphertext-blob fileb://secret.enc \
  --query Plaintext --output text | base64 --decode

No key ID is needed: the ciphertext says which key encrypted it.

Expected result: my secret printed back, and both calls visible in CloudTrail event history a few minutes later.

Clean up: Key actions → Schedule key deletion with a 7-day waiting period.

AWS documentation

On this page

Open notes

Spotted a mistake?

These notes are open source. Suggest a fix, or star the repo if they helped you.

Suggest an edit

For AI agents: llms.txt · llms-full.txt