Task 2.2: Implement encryption and manage sensitive data by using AWS services.
Keeping data unreadable and secrets out of code: encryption at rest and in transit, certificates from ACM and AWS Private CA, client-side versus server-side encryption, KMS keys in code, certificates and SSH keys for development, finding, masking and limiting access to PII and PHI, and Secrets Manager and Parameter Store.
Study it
Encryption at rest and in transit; KMS keys and envelope encryption
Try each one before opening the answer. Every option is explained, with the AWS documentation page that proves it.
Question 1 · choose 1
An application must encrypt 50 MB export files under a customer managed AWS KMS key before it sends them to a partner's storage outside AWS. The developer's first attempt passes each file to the KMS Encrypt operation and fails. The solution must make as few calls to AWS KMS as possible. What should the developer do?
AAsk for a higher plaintext size limit for the Encrypt operation
BCall GenerateDataKey, encrypt locally, and keep the encrypted data key
CSplit each file into 4 KB chunks and call Encrypt once for every chunk
DCall GenerateDataKeyWithoutPlaintext and encrypt the file with the returned key
Show the answer and why
AAsk for a higher plaintext size limit for the Encrypt operation
Incorrect
Encrypt accepts at most 4,096 bytes of plaintext. It is meant for small data such as keys and passwords, not for files.
BCall GenerateDataKey, encrypt locally, and keep the encrypted data key
Correct
This is envelope encryption: one call returns a plaintext data key for local encryption and a copy encrypted under the KMS key. The plaintext key is erased after use, and Decrypt recovers it later.
CSplit each file into 4 KB chunks and call Encrypt once for every chunk
Incorrect
This needs thousands of KMS calls per file. Data keys exist so that large data is encrypted outside AWS KMS with a single key request.
DCall GenerateDataKeyWithoutPlaintext and encrypt the file with the returned key
Incorrect
That operation returns only the encrypted copy of the data key, which cannot encrypt anything until it is decrypted with another call.
KMS keys encrypt small payloads; data keys from GenerateDataKey encrypt large data locally, with only the encrypted data key stored next to it.
An Amazon S3 bucket stores customer contracts. Two new rules apply: any request that does not use HTTPS must be rejected, and every new object must be encrypted with a specific customer managed AWS KMS key, even when the uploading code sends no encryption headers. Which TWO actions meet these rules? (Choose TWO.)
ATurn on S3 Versioning for the bucket so that every object version is kept
BDeny all S3 actions in the bucket policy when aws:SecureTransport is false
CTurn on S3 Object Lock in compliance mode with a default retention period
DHave the uploading code send its own encryption keys with SSE-C on every request
ESet the bucket's default encryption to SSE-KMS with the customer managed key
Show the answer and why
ATurn on S3 Versioning for the bucket so that every object version is kept
Incorrect
Versioning keeps every version of an object so that it can be recovered. It does not control transport or encryption.
BDeny all S3 actions in the bucket policy when aws:SecureTransport is false
Correct
Denying requests where aws:SecureTransport is false allows only encrypted connections over HTTPS (TLS), as S3 security best practices recommend.
CTurn on S3 Object Lock in compliance mode with a default retention period
Incorrect
Object Lock stores objects as write-once-read-many to prevent deletion or overwrites. It does not encrypt them.
DHave the uploading code send its own encryption keys with SSE-C on every request
Incorrect
SSE-C uses keys that the caller supplies, not the company's KMS key, and S3 now turns SSE-C off by default for new general purpose buckets.
ESet the bucket's default encryption to SSE-KMS with the customer managed key
Correct
Default encryption applies to new objects whose requests specify no encryption, and SSE-KMS lets the bucket use the chosen customer managed key.
Encryption in transit is enforced with the aws:SecureTransport condition; encryption at rest with a chosen key is set by default bucket encryption.
An AWS Lambda function connects to an Amazon RDS for PostgreSQL database with a password stored in a plain environment variable. A security review requires the password to change automatically every 30 days without redeploying the function, and the function must not call a secrets API on every invocation. What should the developer do?
AStore the password as a SecureString parameter and change it with a scheduled script
BSecrets Manager with rotation, read through the Lambda extension's cache
CEncrypt the environment variable with a customer managed key that rotates every 30 days
DPut the password in the deployment package and redeploy the function every 30 days
Show the answer and why
AStore the password as a SecureString parameter and change it with a scheduled script
Incorrect
Parameter Store has no credential rotation. The script would also have to change the password in the database, which is the work rotation does for you.
BSecrets Manager with rotation, read through the Lambda extension's cache
Correct
Secrets Manager rotates the secret in both the secret and the database on a schedule, and the extension retrieves and caches the secret so the function does not call the API each time.
CEncrypt the environment variable with a customer managed key that rotates every 30 days
Incorrect
Rotating the KMS key changes the key that protects the variable. The database password itself stays the same.
DPut the password in the deployment package and redeploy the function every 30 days
Incorrect
Hard-coded credentials require redeploying for every change, which is what Secrets Manager's runtime retrieval and rotation avoid.
Rotation belongs to Secrets Manager; caching through the Lambda extension keeps per-invocation API calls down.
An AWS Lambda function reads a partner API token from an environment variable. A new rule says the console must show the token only as ciphertext, even to the administrators who manage the function and its KMS key settings, and only the function code may turn it into plaintext at runtime. The team accepts adding decryption code to the function. What should the developer do?
AEncryption helpers with a customer managed key, and decryption in code
BKeep Lambda's default encryption at rest with the AWS managed key
CUse a customer managed key for encryption at rest, with no other change
DMove the token from the variable into the function code as a constant
Show the answer and why
AEncryption helpers with a customer managed key, and decryption in code
Correct
The helpers encrypt the value client-side, so it is stored and shown as ciphertext. The function decrypts it with kms:Decrypt, which the execution role is granted.
BKeep Lambda's default encryption at rest with the AWS managed key
Incorrect
Default encryption at rest needs no KMS permissions from users, so anyone who can view the function's configuration sees the plaintext value.
CUse a customer managed key for encryption at rest, with no other change
Incorrect
With a customer managed key at rest, users who have access to the key can still view the variables in plaintext, and the administrators have that access.
DMove the token from the variable into the function code as a constant
Incorrect
Hard-coded credentials can be read by anyone who can inspect the code, the opposite of what the rule requires.
Encryption at rest protects stored variables but shows them to permitted users; client-side encryption with the helpers keeps them ciphertext until the code decrypts them.
An application writes request details to an Amazon CloudWatch Logs log group, and some log events contain customer email addresses. Compliance requires these addresses to be masked wherever the logs are read, including CloudWatch Logs Insights and subscription filters, and only a small security team may see them unmasked. The developer wants to avoid changing the application code. What should the developer do?
ATurn on Amazon Macie and point its discovery jobs at the log group
BAssociate a customer managed AWS KMS key with the log group
CA data protection policy, with logs:Unmask only for the security team
DAdd a metric filter that counts log events containing an email address
Show the answer and why
ATurn on Amazon Macie and point its discovery jobs at the log group
Incorrect
Macie discovers sensitive data in Amazon S3 general purpose buckets. It does not mask data in CloudWatch Logs.
BAssociate a customer managed AWS KMS key with the log group
Incorrect
A KMS key encrypts the log data at rest, but CloudWatch Logs decrypts it whenever it is requested, so readers still see the addresses.
CA data protection policy, with logs:Unmask only for the security team
Correct
A data protection policy masks matching sensitive data as it is ingested, at every egress point including Logs Insights and subscription filters. Only principals with logs:Unmask see the original.
DAdd a metric filter that counts log events containing an email address
Incorrect
A metric filter turns matching log data into a numeric metric. The email addresses stay visible in the log events.
Log group data protection policies mask sensitive data at ingestion; the logs:Unmask permission controls who may see it.
A multi-tenant SaaS application keeps every tenant's data in one Amazon DynamoDB table, and each item's partition key value is the tenant ID. An AWS Lambda function serves requests with its execution role, which can read the whole table, and it filters items by tenant in code. The security team wants IAM itself to stop a request from reading another tenant's items, even if the code has a bug. Which TWO changes meet this requirement? (Choose TWO.)
AKeep the current role, and add unit tests that check the tenant filter in the code
BCreate a global secondary index for each tenant and query only that index
CReplace each Query with a Scan that filters on the caller's tenant ID
DA tenant-access role whose policy sets dynamodb:LeadingKeys to ${aws:PrincipalTag/TenantId}
EPer request, assume that role with a TenantId session tag from the verified token
Show the answer and why
AKeep the current role, and add unit tests that check the tenant filter in the code
Incorrect
A test checks the code, but the role can still read every item. The requirement is for IAM to restrict which items a request can access.
BCreate a global secondary index for each tenant and query only that index
Incorrect
Indexes change how data is queried, not who may read it. A role that can read the table can still read every item.
CReplace each Query with a Scan that filters on the caller's tenant ID
Incorrect
A Scan reads every item before the filter is applied, and the role can still read all tenants' data.
DA tenant-access role whose policy sets dynamodb:LeadingKeys to ${aws:PrincipalTag/TenantId}
Correct
The dynamodb:LeadingKeys condition limits access to items whose partition key matches the given value, and aws:PrincipalTag reads the tenant from the session's tags.
EPer request, assume that role with a TenantId session tag from the verified token
Correct
Session tags passed with AssumeRole become principal tags of the session, so each request runs with credentials scoped to its own tenant.
Attribute-based access control: a session tag carries the tenant, and a dynamodb:LeadingKeys condition on aws:PrincipalTag enforces it per item.
A KMS key was created from a template whose key policy names only one administrator role and has no statement for the account itself. A developer attaches an IAM policy to an application role that allows kms:Decrypt on the key, but the role still gets AccessDenied. What is the cause?
AIAM policies take up to a day to apply to KMS keys
Bkms:Decrypt can only be granted through grants
CThe key policy does not let the account use IAM policies for the key
DThe role also needs kms:GenerateDataKey permission before any Decrypt call can succeed
Show the answer and why
AIAM policies take up to a day to apply to KMS keys
Incorrect
There is no such delay; the IAM policy has no effect because the key policy does not enable IAM policies.
Bkms:Decrypt can only be granted through grants
Incorrect
Key policies and IAM policies can allow kms:Decrypt; grants are one more option.
CThe key policy does not let the account use IAM policies for the key
Correct
Without the statement that gives the account access, IAM policies that allow access to the key are ineffective.
DThe role also needs kms:GenerateDataKey permission before any Decrypt call can succeed
Incorrect
Decrypt does not depend on GenerateDataKey; the missing piece is in the key policy.
KMS key policies do not automatically trust the account; IAM policies only work when the key policy enables them.
A high-throughput service encrypts many small records with the AWS Encryption SDK under a KMS key. Each encryption generates a new data key through AWS KMS, and the service now hits KMS request quotas. The security team accepts limited, bounded reuse of data keys. What should the developer do?
AEncrypt every record directly with the AWS KMS Encrypt operation instead
BTurn on data key caching in the AWS Encryption SDK with limits
CTurn on automatic rotation for the KMS key
DUse one hardcoded data key in the code for all records
Show the answer and why
AEncrypt every record directly with the AWS KMS Encrypt operation instead
Incorrect
This still makes a KMS request for every record, so the request volume does not fall.
BTurn on data key caching in the AWS Encryption SDK with limits
Correct
Data key caching reuses data keys from a cache instead of generating a new one each time; it is optional and should be used with care.
CTurn on automatic rotation for the KMS key
Incorrect
Rotation changes key material over time; it does not reduce the number of KMS requests.
DUse one hardcoded data key in the code for all records
Incorrect
A key in code is exposed to anyone who can read the code and never changes, which defeats envelope encryption.
Data key caching trades some key reuse for fewer KMS calls; set limits that match the team's security requirements.
A DynamoDB table stores customer records, and the taxId attribute is highly sensitive. Operators who can read the table for support must not be able to see taxId values, while the application must still read and write them. Encryption at rest is already on. What should the developer add?
ASwitch the table's encryption at rest to a customer managed key in AWS KMS
BTurn on DynamoDB Streams with the NEW_AND_OLD_IMAGES view type
CStore taxId in a second table that operators do not use
DEncrypt taxId on the client with the AWS Database Encryption SDK
Show the answer and why
ASwitch the table's encryption at rest to a customer managed key in AWS KMS
Incorrect
Encryption at rest is transparent to anyone allowed to read the table, so operators would still see plaintext values.
BTurn on DynamoDB Streams with the NEW_AND_OLD_IMAGES view type
Incorrect
Streams capture changes; they do not hide attribute values from readers.
CStore taxId in a second table that operators do not use
Incorrect
Moving the value does not encrypt it, and anyone with read access to the second table could still see it.
DEncrypt taxId on the client with the AWS Database Encryption SDK
Correct
The SDK provides client-side, attribute-level encryption, so the stored value is ciphertext unless a caller can use the key.
Client-side, attribute-level encryption protects specific fields from people who can read the table but cannot use the key.
A SecureString parameter in Parameter Store is encrypted with a customer managed KMS key. An application role has ssm:GetParameter on the parameter, and calls with WithDecryption set to true fail with an access error. Calls without decryption succeed. What should the developer add to the role's permissions?
Akms:Decrypt on the customer managed key
Bssm:PutParameter on the parameter
Ckms:Encrypt on the customer managed key
Dssm:GetParametersByPath on the parent path
Show the answer and why
Akms:Decrypt on the customer managed key
Correct
To decrypt a SecureString parameter value, the caller needs kms:Decrypt permission on the key that encrypted it.
Bssm:PutParameter on the parameter
Incorrect
PutParameter writes values; reading a value needs no write permission.
Ckms:Encrypt on the customer managed key
Incorrect
Encrypt is needed to write standard SecureString values, not to read them.
Dssm:GetParametersByPath on the parent path
Incorrect
The role can already read the parameter; the missing permission is on the KMS key.
Reading SecureString values needs both Parameter Store access and kms:Decrypt on the key.