Skip to content
Menu
myCloud myCloud

Personal short notes about Cloud

  • XMPie
  • AWS
    • AWS Topics
    • AWS Architecture
    • AWS CLI
    • AWS Health
    • AWS Policies
    • AWS Cost
  • CHEAT SHEETS
myCloud myCloud

Personal short notes about Cloud

AWS CLI – KMS

By mikado on September 30, 2022September 30, 2022

Use the CLI for KMS encrypt, decrypt and key rotation.

Encrypt

aws kms encrypt --key-id YOURKEYIDHERE \
    --plaintext fileb://secret.txt \
    --output text \
    --query CiphertextBlob | base64 \
    --decode > encryptedsecret.txt

Decrypt

aws kms decrypt --ciphertext-blob fileb://encryptedsecret.txt \
    --output text \
    --query Plaintext | base64 \
    --decode > decryptedsecret.txt

Re-encrypt

aws kms re-encrypt --destination-key-id YOURKEYIDHERE \
    --ciphertext-blob fileb://encryptedsecret.txt | base64 > newencryption.txt

Key rotation

aws kms enable-key-rotation --key-id YOURKEYIDHERE
aws kms get-key-rotation-status --key-id YOURKEYIDHERE

Generate Key

aws kms generate-data-key --key-id YOURKEYIDHERE --key-spec AES_256

https://awscli.amazonaws.com/v2/documentation/api/latest/reference/kms/index.html#cli-aws-kms

Category: AWS CLI

Categories

  • AWS (4)
  • AWS Architecture (8)
  • AWS CLI (5)
  • AWS Cost (3)
  • AWS Health (4)
  • AWS Policies (2)
  • AWS Topics (24)
  • CHEAT SHEETS (16)
  • Container (21)
  • Datadog (4)
  • Jenkins (2)
  • Linux (9)
  • Microsoft (7)
  • Python (1)
  • SCRIPTS (9)
  • Terraform (5)
  • XMPie (6)
©2025 myCloud
Click to Copy