0%
AWS Developer Associate (DVA-C03) Exam Prep: Development, Security, Testing, Deployment and Troubleshooting
How the Exam Works
Domain 1: Development with AWS Services
Domain 3: Testing and Deployment
Domain 4: Troubleshooting and Optimization
New in DVA-C03: Containers and AI
Final Review and Mock Exams
Encryption, KMS and Secrets for Developers
The Developer Associate exam spends a good part of its security domain on encryption, and nearly all of it comes down to AWS Key Management Service (KMS): what a KMS key is, which API to call for what, who can use a key and why a call fails. The IAM lesson covered how requests are authorized. This lesson adds keys, server-side encryption in S3 and other services, encryption in transit with ACM, and how applications store and fetch secrets and configuration.
What a KMS key is
A KMS key is a logical key that lives inside KMS. Its key material is generated and used within hardware security modules and is never exported in plaintext. You do not download a KMS key and encrypt with it on your own machine; you send data or a data key to KMS, and KMS performs the operation and returns the result. Every use of a key is an API call that IAM authorizes and CloudTrail records, which is why KMS is the standard answer to "we need an audit trail of who used the key".
Keys come in three ownership types. Customer managed keys are keys you create: you control the key policy, enable or disable them, schedule deletion, choose rotation, add grants and tags, and pay a monthly fee per key plus per request. AWS managed keys are created by a service on your behalf, with aliases such as aws/s3, aws/lambda or aws/secretsmanager; you can see them and audit their use in CloudTrail, but you cannot change their policies or share them across accounts. AWS owned keys belong to a service and are used across many accounts; you never see them, and they are free. Several services encrypt at rest with AWS owned keys by default, for example DynamoDB tables unless you choose otherwise.
Most keys are symmetric: one 256-bit AES key used for both encryption and decryption, and only usable through KMS. KMS also supports asymmetric keys, RSA and elliptic curve key pairs, used for encryption or for signing and verifying, where the public key can be downloaded and used outside AWS, and HMAC keys for generating and verifying message authentication codes. If a question has a client outside AWS that must encrypt data or verify a signature without calling AWS, an asymmetric key with a downloadable public key is the answer.
The cryptographic APIs
The core calls are few, and the exam expects you to pick the right one.
Encrypt takes up to 4 KB of plaintext and returns ciphertext encrypted under a KMS key. Decrypt takes that ciphertext and returns the plaintext. For symmetric keys, the ciphertext blob already contains the key ID, so Decrypt does not need to be told which key to use, though naming it is good practice. ReEncrypt decrypts and re-encrypts under a different key inside KMS, without exposing plaintext to the caller, which is useful when moving data to a new key.
GenerateDataKey returns a fresh data key in two forms: plaintext and encrypted under the KMS key. GenerateDataKeyWithoutPlaintext returns only the encrypted form, for a component that will store the key now and have something else decrypt it later. GenerateRandom returns random bytes. Sign and Verify work with asymmetric signing keys, and GenerateMac and VerifyMac with HMAC keys.
Encryption context
The encryption context is a set of non-secret key and value pairs passed with Encrypt or GenerateDataKey. KMS binds it to the ciphertext cryptographically: Decrypt succeeds only if the caller supplies exactly the same context. It does not need to be secret, it appears in plaintext in CloudTrail, which makes logs much more useful, and it can be used in key policy and IAM conditions with kms:EncryptionContext keys, for example allowing a role to decrypt only ciphertexts whose context says tenant equals its own tenant. A Decrypt call that fails with InvalidCiphertextException while the key and permissions are right often has a missing or different encryption context. AWS services set their own context, such as the S3 object ARN for SSE-KMS.
Aliases, rotation and deletion
An alias is a friendly name, such as alias/orders-prod, that points to a key. Code that refers to the alias can be pointed at a new key by updating the alias, without code changes. Aliases work in Encrypt and GenerateDataKey calls; in key policies and in many IAM conditions you refer to keys by ARN, though aliases can be used in conditions with kms:RequestAlias or kms:ResourceAliases.
Rotation for a customer managed key is optional. When enabled, KMS creates new key material on a schedule, by default every year and configurable within a range of roughly three months to several years, and you can also rotate on demand. The key ID, ARN and aliases stay the same; old key material is kept so existing ciphertext still decrypts, and new encryptions use the new material. No data is re-encrypted and no code changes. AWS managed keys rotate automatically every year. Keys with imported key material and asymmetric keys do not support automatic rotation; for those, you rotate manually by creating a new key and moving the alias.
You cannot delete a key immediately. ScheduleKeyDeletion sets a waiting period of 7 to 30 days, 30 by default, during which the key is disabled for use and the deletion can be cancelled. Once the key is deleted, data encrypted under it is unrecoverable. Disabling a key is the reversible way to stop its use. A CloudWatch alarm on attempted use of a key pending deletion, found through CloudTrail, tells you whether something still needs it.
Multi-Region keys
A multi-Region key is a set of related keys in different Regions that share key material and key ID, so ciphertext encrypted in one Region can be decrypted in another without calling across Regions. They suit client-side encryption of data replicated across Regions, such as items in DynamoDB global tables encrypted by the application. They are not needed for most server-side encryption, where each Region's service uses its own key and replication re-encrypts.
What the exam is checking here
Recognise the calls: up to 4 KB, use Encrypt; anything larger, use GenerateDataKey; store a key for later without seeing it, GenerateDataKeyWithoutPlaintext; move ciphertext to another key without exposing it, ReEncrypt. Recognise the key types: control over the policy and cross account sharing need a customer managed key. And remember that the encryption context must match on decrypt.
Choosing a key per application
A common question is how many keys to create. One customer managed key per application and environment is a good default: orders-prod, orders-test, billing-prod. Separate keys give separate key policies, so the billing team cannot decrypt order data, separate CloudTrail trails of use, and the ability to disable one application's key in an incident without touching the others. A single shared key for everything is simpler but means one key policy has to describe every team's access, and one mistake exposes everything. Per-tenant keys are possible for strict isolation, but each key has a monthly cost, so many SaaS applications use one key per environment and an encryption context naming the tenant instead, with key policy conditions on that context.
Permissions for each call
Each KMS operation has its own action name, and least privilege means granting only the ones the code uses. A producer that encrypts with data keys needs kms:GenerateDataKey. A consumer that decrypts needs kms:Decrypt. Code that inspects a key needs kms:DescribeKey. Key administrators need kms:Create*, kms:Put*, kms:Enable*, kms:Disable*, kms:ScheduleKeyDeletion and similar actions, but should not be key users. Granting kms:* to an application role is the KMS equivalent of s3:* on every bucket, and on the exam it is almost always a distractor.
Worked example: encrypting a field
An application stores customer tax IDs in a database column. The values are short, well under 4 KB, so calling Encrypt directly with a customer managed key is reasonable, with an encryption context naming the customer ID. The ciphertext blob, base64 encoded, goes in the column. Reading requires Decrypt with the same context, which means a stolen ciphertext copied to another customer's row will not decrypt, and every decryption shows in CloudTrail with the customer ID. For high volumes of reads, the Database Encryption SDK with a cached data key does the same with fewer KMS calls.
KMS Encrypt and Decrypt handle at most 4 KB of plaintext. A question about encrypting files, images or large payloads with KMS wants GenerateDataKey and local encryption, not a bigger Encrypt call.