AWS Developer Associate · Domain 2 of 4 · 26% of the exam

AWS Developer Associate Domain 2: Security

52 free practice questions for Security in the AWS Certified Developer – Associate (DVA-C02) exam. Try each question first, then open "Show answer" for the correct option and explanation.

Security practice questions

  1. Question 1. What gives a Lambda function permission to write to a DynamoDB table?

    1. Its resource-based policy
    2. Its environment variables
    3. Its execution role
    4. The table's stream settings
    Show answer

    Answer: C. Its execution role

    The execution role is assumed by Lambda when the function runs, and its policies decide which AWS APIs the code can call.

  2. Question 2. What allows an S3 bucket in the same account to invoke a Lambda function?

    1. A permission added to the function's execution role
    2. A statement in the function's resource-based policy
    3. An IAM user created for the S3 service
    4. A VPC endpoint for Lambda in the bucket's Region
    Show answer

    Answer: B. A statement in the function's resource-based policy

    Resource-based policies control who can invoke the function. The console or add-permission creates the statement.

  3. Question 3. A web app must let users sign up, sign in, and receive JWTs. Which service provides this?

    1. Amazon Cognito user pools
    2. Amazon Cognito identity pools
    3. AWS IAM users with passwords
    4. AWS Directory Service
    Show answer

    Answer: A. Amazon Cognito user pools

    User pools are user directories that issue ID, access, and refresh tokens.

  4. Question 4. Signed-in mobile users need temporary AWS credentials to upload directly to S3. Which service exchanges their token for credentials?

    1. Amazon Cognito user pools only
    2. AWS Secrets Manager
    3. Amazon Cognito identity pools
    4. AWS Certificate Manager
    Show answer

    Answer: C. Amazon Cognito identity pools

    Identity pools federate identities from user pools or social providers and return temporary credentials for an IAM role.

  5. Question 5. An API Gateway REST API should accept only requests with valid tokens from a Cognito user pool, with no custom code. What should be used?

    1. A Lambda authorizer that validates the token
    2. IAM authorization with SigV4 signing
    3. A Cognito user pool authorizer
    4. An API key required on every method
    Show answer

    Answer: C. A Cognito user pool authorizer

    The Cognito authorizer validates the token itself. A Lambda authorizer is needed only for custom logic.

  6. Question 6. An API must validate tokens from a third-party identity provider and check custom claims. Which REST API feature fits?

    1. A Cognito user pool authorizer
    2. A usage plan with an API key
    3. A resource policy with source IP conditions
    4. A Lambda authorizer
    Show answer

    Answer: D. A Lambda authorizer

    Lambda authorizers run custom code that returns an IAM policy, and results can be cached.

  7. Question 7. Internal services call an API Gateway API with their IAM roles. Which authorization type should the API use?

    1. A Cognito user pool authorizer
    2. AWS_IAM, with requests signed using SigV4
    3. API keys in a usage plan
    4. No authorization, restricted by CORS
    Show answer

    Answer: B. AWS_IAM, with requests signed using SigV4

    IAM authorization checks the caller's signed request against its IAM permissions for execute-api:Invoke.

  8. Question 8. A developer must encrypt a 50 MB file with AWS KMS. Why can't the file be passed directly to the Encrypt API?

    1. Encrypt accepts at most 4 KB of data
    2. KMS can only encrypt objects already in S3
    3. Encrypt only works with asymmetric keys
    4. Files over 1 MB need a CloudHSM cluster
    Show answer

    Answer: A. Encrypt accepts at most 4 KB of data

    Larger data uses envelope encryption with a data key from GenerateDataKey.

  9. Question 9. Which KMS API returns a plaintext data key and the same key encrypted under a KMS key?

    1. GenerateDataKey
    2. Encrypt
    3. CreateKey
    4. ReEncrypt
    Show answer

    Answer: A. GenerateDataKey

    The app encrypts data with the plaintext key, discards it, and stores the encrypted key with the data.

  10. Question 10. In envelope encryption, what is stored alongside the encrypted data?

    1. The plaintext data key
    2. The KMS key material
    3. The encrypted data key
    4. The IAM role's access key
    Show answer

    Answer: C. The encrypted data key

    To decrypt, the app calls KMS Decrypt on the encrypted data key, then uses the plaintext key locally.

  11. Question 11. An app calls KMS Decrypt thousands of times per second and hits throttling. What reduces the number of calls?

    1. Create a new KMS key for every request
    2. Switch to a customer-managed key with rotation
    3. Call Decrypt with a larger payload
    4. Cache data keys with the AWS Encryption SDK
    Show answer

    Answer: D. Cache data keys with the AWS Encryption SDK

    Data key caching reuses keys within limits you set, reducing KMS requests and cost.

  12. Question 12. What does a KMS encryption context provide?

    1. Extra authenticated data that must match on decrypt
    2. A second encryption key stored with the data
    3. A way to encrypt data larger than 4 KB
    4. Automatic rotation of the data key
    Show answer

    Answer: A. Extra authenticated data that must match on decrypt

    The context is logged in CloudTrail and can be used in policy conditions, but it isn't secret.

  13. Question 13. A database password must rotate automatically every 30 days. Which service fits BEST?

    1. Systems Manager Parameter Store standard parameters
    2. Lambda environment variables
    3. An S3 object encrypted with SSE-S3
    4. AWS Secrets Manager
    Show answer

    Answer: D. AWS Secrets Manager

    Secrets Manager has built-in rotation for RDS and other databases using a rotation function.

  14. Question 14. An app needs dozens of configuration values, some encrypted, at low cost without rotation. What fits BEST?

    1. Parameter Store with SecureString for sensitive values
    2. Secrets Manager for every value
    3. DynamoDB with encryption disabled
    4. Hard-coded constants in the source code
    Show answer

    Answer: A. Parameter Store with SecureString for sensitive values

    Standard parameters are free, and SecureString parameters are encrypted with KMS.

  15. Question 15. Which Parameter Store API retrieves all parameters under /myapp/prod/ in one call?

    1. GetParameter
    2. DescribeParameters
    3. GetParametersByPath
    4. GetParameterHistory
    Show answer

    Answer: C. GetParametersByPath

    Hierarchical names let an app load its configuration by path. Add WithDecryption for SecureString values.

  16. Question 16. Objects must be encrypted before they leave the application, so AWS never sees plaintext. Which approach is required?

    1. SSE-S3
    2. Client-side encryption
    3. SSE-KMS
    4. A bucket policy that requires HTTPS
    Show answer

    Answer: B. Client-side encryption

    Server-side options encrypt at rest in S3. Client-side encryption encrypts before upload.

  17. Question 17. A bucket policy must deny uploads that aren't encrypted with SSE-KMS. Which condition key is checked?

    1. aws:SecureTransport on the request
    2. s3:x-amz-server-side-encryption
    3. s3:x-amz-acl on the object
    4. aws:SourceIp of the caller
    Show answer

    Answer: B. s3:x-amz-server-side-encryption

    Deny PutObject when the header isn't aws:kms. Buckets now encrypt by default, but policies can require a specific type.

  18. Question 18. A bucket policy must reject requests over plain HTTP. Which condition should be used?

    1. s3:x-amz-server-side-encryption set to AES256
    2. aws:MultiFactorAuthPresent set to true
    3. aws:SecureTransport set to false in a Deny statement
    4. s3:prefix set to https
    Show answer

    Answer: C. aws:SecureTransport set to false in a Deny statement

    Denying when aws:SecureTransport is false forces TLS for all requests.

  19. Question 19. A service in account A must access a DynamoDB table in account B. What is the usual approach?

    1. Assume a role in account B that trusts account A
    2. Share account B's root access keys with account A
    3. Create IAM users in account B for each service
    4. Make the table public with a resource policy
    Show answer

    Answer: A. Assume a role in account B that trusts account A

    The role's trust policy allows account A, and the caller uses sts:AssumeRole to get temporary credentials.

  20. Question 20. Which STS API returns temporary credentials for assuming an IAM role?

    1. GetSessionToken only
    2. AssumeRole
    3. GetCallerIdentity
    4. DecodeAuthorizationMessage
    Show answer

    Answer: B. AssumeRole

    AssumeRole returns an access key, secret key, and session token with an expiration.

  21. Question 21. An API call fails with an encoded authorization failure message. Which API decodes it?

    1. sts:GetCallerIdentity
    2. sts:DecodeAuthorizationMessage
    3. iam:SimulatePrincipalPolicy
    4. kms:Decrypt
    Show answer

    Answer: B. sts:DecodeAuthorizationMessage

    The decoded message shows which action and resource were denied and why.

  22. Question 22. How can a developer test whether a role's policies allow s3:GetObject on a bucket without making the call?

    1. The IAM policy simulator
    2. CloudTrail Lake queries
    3. AWS Config conformance packs
    4. Amazon Inspector findings
    Show answer

    Answer: A. The IAM policy simulator

    The policy simulator evaluates identity policies and can include resource policies and conditions.

  23. Question 23. An explicit Deny and an Allow both match the same request. What happens?

    1. The request is allowed
    2. The most recently attached policy wins
    3. The request is denied
    4. The policy with more statements wins
    Show answer

    Answer: C. The request is denied

    An explicit deny always overrides any allow in IAM policy evaluation.

  24. Question 24. A GitHub Actions workflow must deploy to AWS without storing access keys as secrets. What should be used?

    1. An IAM user whose keys are stored in the repository
    2. The root account's access keys stored as a secret
    3. A Cognito user pool with a shared password
    4. An IAM OIDC identity provider and a role the workflow assumes
    Show answer

    Answer: D. An IAM OIDC identity provider and a role the workflow assumes

    The workflow exchanges its OIDC token for short-lived role credentials with AssumeRoleWithWebIdentity.

  25. Question 25. A Cognito user pool should require a second factor at sign-in. What should be enabled?

    1. An identity pool with guest access
    2. Multi-factor authentication (MFA) in the user pool
    3. A Lambda authorizer on the user pool
    4. Unauthenticated identities in the identity pool
    Show answer

    Answer: B. Multi-factor authentication (MFA) in the user pool

    User pools support TOTP and SMS MFA, optional or required.

  26. Question 26. A company wants users to sign in to its app with Google or Facebook through Cognito. What should be configured?

    1. A SAML identity provider in IAM created for each user
    2. An IAM user created for each Google or Facebook account
    3. Cross-account IAM roles trusted by Google and Facebook
    4. Social identity providers in the user pool, with the hosted UI
    Show answer

    Answer: D. Social identity providers in the user pool, with the hosted UI

    User pools federate social and SAML/OIDC providers and issue their own tokens to the app.

  27. Question 27. Which token from a Cognito user pool should an app send to its API to authorize access to resources?

    1. The refresh token
    2. The access token
    3. The client secret
    4. The user's password
    Show answer

    Answer: B. The access token

    Access tokens carry scopes and groups for authorization. ID tokens carry identity claims about the user.

  28. Question 28. What is the refresh token used for in Cognito?

    1. Authorizing API calls directly at API Gateway
    2. Encrypting the user's attributes in the user pool
    3. Verifying the user's email address after sign-up
    4. Getting new ID and access tokens without signing in again
    Show answer

    Answer: D. Getting new ID and access tokens without signing in again

    Access and ID tokens are short-lived. The refresh token obtains new ones until it expires.

  29. Question 29. Users in the "admins" group of a Cognito user pool must get more AWS permissions through an identity pool. What should be configured?

    1. A role mapped to the group through role-based access control
    2. An IAM user created for each admin in the group
    3. A second user pool that contains only the admins
    4. A Lambda authorizer configured in the identity pool
    Show answer

    Answer: A. A role mapped to the group through role-based access control

    Identity pools can choose the IAM role from the user's groups or token claims.

  30. Question 30. An IAM policy lets each user read only their own folder in a bucket. Which feature makes one policy work for all users?

    1. A separate S3 bucket created for every user
    2. One inline policy written by hand for each user
    3. S3 Object Lock in governance mode on each folder
    4. Policy variables such as ${aws:username} in the resource ARN
    Show answer

    Answer: D. Policy variables such as ${aws:username} in the resource ARN

    Policy variables are replaced at evaluation time, so one policy can scope access per principal.

  31. Question 31. With Cognito identity pools, how can users be restricted to their own prefix in S3?

    1. Create a separate IAM role for every single user
    2. Add each user's identity ID to the bucket ACL
    3. Use a separate Cognito user pool for every user
    4. Use ${cognito-identity.amazonaws.com:sub} in the role policy
    Show answer

    Answer: D. Use ${cognito-identity.amazonaws.com:sub} in the role policy

    The identity ID variable scopes a shared role's permissions to each identity.

  32. Question 32. Where should an application's TLS certificate for a custom API Gateway domain come from at no extra cost?

    1. AWS Certificate Manager (ACM)
    2. AWS Secrets Manager
    3. A self-signed certificate in S3
    4. AWS KMS asymmetric keys
    Show answer

    Answer: A. AWS Certificate Manager (ACM)

    ACM issues public certificates for free and renews them automatically. Edge-optimized APIs need the certificate in us-east-1.

  33. Question 33. A developer logs full request objects in Lambda, including credit card numbers. What is the BEST fix?

    1. Increase the log retention period
    2. Turn off CloudWatch Logs encryption
    3. Log to /tmp instead of CloudWatch
    4. Remove or mask sensitive fields before logging
    Show answer

    Answer: D. Remove or mask sensitive fields before logging

    Logs are widely readable. Mask sensitive data in code, and consider CloudWatch Logs data protection policies.

  34. Question 34. Which CloudWatch Logs feature can detect and mask sensitive data such as credit card numbers in log events?

    1. Metric filters on the log group
    2. Data protection policies on the log group
    3. Subscription filters to Lambda
    4. Log group retention settings
    Show answer

    Answer: B. Data protection policies on the log group

    Data protection policies use managed identifiers to find and mask sensitive data.

  35. Question 35. A developer's application reads a secret from Secrets Manager on every request, adding latency and cost. What helps?

    1. Store the secret in a Lambda environment variable
    2. Cache the secret in memory with a client-side caching library
    3. Create a new secret for every request
    4. Call GetSecretValue with a larger timeout
    Show answer

    Answer: B. Cache the secret in memory with a client-side caching library

    Caching reduces API calls. Refresh the cache periodically to pick up rotated values.

  36. Question 36. Which KMS key type should be used when an app needs full control over the key policy and rotation?

    1. A customer managed key
    2. An AWS managed key
    3. An AWS owned key
    4. A key stored in an environment variable
    Show answer

    Answer: A. A customer managed key

    Customer managed keys let you edit key policies, enable rotation, and disable or schedule deletion.

  37. Question 37. A Lambda function calls kms:Decrypt on a customer managed key and gets AccessDenied, though its role allows kms:Decrypt. What else must allow it?

    1. The function's resource-based policy
    2. The KMS key policy
    3. The S3 bucket policy
    4. The VPC's network ACL
    Show answer

    Answer: B. The KMS key policy

    KMS key policies are the primary access control. They must allow the role directly or delegate to IAM.

  38. Question 38. Which S3 encryption option records each use of the key in CloudTrail and lets the customer control the key policy?

    1. SSE-S3
    2. SSE-KMS with a customer managed key
    3. SSE-C
    4. No encryption with bucket versioning
    Show answer

    Answer: B. SSE-KMS with a customer managed key

    SSE-KMS uses KMS keys, and every encrypt and decrypt call is logged.

  39. Question 39. With SSE-C, what must the client do on every GET of an encrypted object?

    1. Provide the same encryption key in the request headers
    2. Nothing; S3 stores the key with the object
    3. Call KMS Decrypt before the GET
    4. Use a presigned URL with the key in the path
    Show answer

    Answer: A. Provide the same encryption key in the request headers

    S3 doesn't store SSE-C keys. HTTPS is required, and losing the key means losing the data.

  40. Question 40. Many requests to SSE-KMS encrypted objects cause KMS throttling. What reduces KMS requests?

    1. Switch to SSE-C for all objects
    2. Disable versioning on the bucket
    3. Enable S3 Bucket Keys
    4. Use a larger KMS key size
    Show answer

    Answer: C. Enable S3 Bucket Keys

    Bucket Keys generate a bucket-level key from KMS, so S3 calls KMS far less often.

  41. Question 41. An app on ECS Fargate must access S3. How should it get permissions?

    1. The ECS task execution role
    2. An ECS task role
    3. Access keys in the container image
    4. The EC2 instance profile of the cluster
    Show answer

    Answer: B. An ECS task role

    The task role is for application calls. The execution role lets ECS pull images and write logs.

  42. Question 42. An EC2 instance runs an app that calls DynamoDB. How should credentials be provided?

    1. Access keys in the application's config file
    2. The root user's keys in environment variables
    3. An instance profile with an IAM role
    4. A shared IAM user for all instances
    Show answer

    Answer: C. An instance profile with an IAM role

    The SDK gets temporary credentials from the instance metadata service automatically.

  43. Question 43. Which instance metadata option helps protect role credentials from SSRF attacks on EC2?

    1. Disabling the instance profile
    2. Using IMDSv1 only
    3. Requiring IMDSv2 session tokens
    4. Storing credentials in user data
    Show answer

    Answer: C. Requiring IMDSv2 session tokens

    IMDSv2 requires a PUT request to get a session token, which blocks many SSRF attempts.

  44. Question 44. A developer needs a Lambda function to use a secret, but only the function should be able to read it. What should be done?

    1. Allow GetSecretValue on that secret only in the function's role
    2. Put the secret value directly in the function's source code
    3. Allow every role in the account to read the secret
    4. Store the secret in a public S3 bucket read at startup
    Show answer

    Answer: A. Allow GetSecretValue on that secret only in the function's role

    Least privilege grants access to the specific secret ARN to the specific role that needs it.

  45. Question 45. An API Gateway REST API should only be reachable from a specific VPC. What should be used?

    1. An edge-optimized API protected with a usage plan
    2. A regional API with CORS disabled on every method
    3. An HTTP API with a JWT authorizer on each route
    4. A private API with a resource policy for the VPC endpoint
    Show answer

    Answer: D. A private API with a resource policy for the VPC endpoint

    Private APIs are reached through an interface VPC endpoint, and the resource policy restricts access.

  46. Question 46. What does API Gateway's authorizer caching do for a Lambda authorizer?

    1. Reuses the returned policy for a token for a set TTL
    2. Caches backend responses for all users
    3. Stores user passwords in memory
    4. Removes the need for an IAM policy
    Show answer

    Answer: A. Reuses the returned policy for a token for a set TTL

    Caching reduces authorizer invocations and latency. Keep the TTL short if permissions change often.

  47. Question 47. What is the purpose of an IAM permissions boundary on roles that developers create?

    1. It grants the role additional permissions
    2. It forces MFA for every API call
    3. It caps the maximum permissions the role can ever have
    4. It replaces the role's trust policy
    Show answer

    Answer: C. It caps the maximum permissions the role can ever have

    Effective permissions are the intersection of the identity policy and the boundary.

  48. Question 48. A developer wants to know which identity their CLI is using. Which command shows it?

    1. aws iam list-users
    2. aws sts get-caller-identity
    3. aws configure list-profiles
    4. aws sts assume-role
    Show answer

    Answer: B. aws sts get-caller-identity

    It returns the account, ARN, and user ID of the current credentials and needs no permissions.

  49. Question 49. An app stores user-uploaded files. Which practice follows least privilege for the app's role?

    1. Allow s3:* on every bucket in the account
    2. Attach the AdministratorAccess managed policy
    3. Grant the role iam:PassRole on all roles in the account
    4. Allow only s3:PutObject and s3:GetObject on the app's prefix
    Show answer

    Answer: D. Allow only s3:PutObject and s3:GetObject on the app's prefix

    Scope actions and resources to what the application actually needs.

  50. Question 50. What does the iam:PassRole permission control?

    1. Whether a user can change their own console password
    2. Whether a user can hand a role to a service, such as Lambda
    3. Whether a role can be assumed from another account
    4. Whether a role's session duration can be extended
    Show answer

    Answer: B. Whether a user can hand a role to a service, such as Lambda

    Without PassRole restrictions, a user could attach a powerful role to a service they control.

  51. Question 51. Which Lambda feature verifies that only trusted, signed code packages can be deployed?

    1. Reserved concurrency
    2. Code signing with AWS Signer
    3. Lambda layers
    4. Function URLs with IAM auth
    Show answer

    Answer: B. Code signing with AWS Signer

    A code signing configuration rejects or warns on packages not signed by an allowed signing profile.

  52. Question 52. A Lambda function URL must only be callable by IAM principals with permission. Which auth type should be set?

    1. NONE
    2. COGNITO_USER_POOLS
    3. API_KEY
    4. AWS_IAM
    Show answer

    Answer: D. AWS_IAM

    With AWS_IAM, callers sign requests with SigV4 and need lambda:InvokeFunctionUrl permission.

AWS, Amazon Web Services, and AWS Certified are trademarks of Amazon.com, Inc. or its affiliates. These questions are original study material, not questions from the real exam.