SaveMyCert
Log in
5 of 5 free questions left today·for 30 a day
DVA-C02 · Domain 2

Security practice questions

Security is worth 26% of the DVA-C02 exam — the 2nd-heaviest of the 4 domains. Authentication and authorization for applications, encryption with AWS services, and handling sensitive data in code. 6 fully worked examples are further down this page, answers included.

Exam weight
26%
the 2nd-heaviest of the 4 domains
Questions
60
across 3 topics
Free, no account
5/day
sign up free to remove the cap
Explanations
Every option
right and wrong

Build a practice session

5 free questions left today.

Domains

How many?

Mode

Ready when you are

10 fresh questions drawn across 1 of 4 domains, in Learn mode.

Focused review

Every question you answer incorrectly, and every question you flag while practising, is saved here automatically. Finish a session and you can come back to re-drill just those.

6 sample Security questions, fully explained

Questions from the DVA-C02 bank mapped to domain 2, with the answer key and the reasoning behind every option. None of them repeat the examples on the main DVA-C02 practice page.

Question 1Security

After a user signs in through an Amazon Cognito user pool, a developer needs to display the user's name and email address on the application's profile screen. Which token should the application read these claims from?

Choose one.

  • a
    The access token

    The access token carries OAuth scopes and group membership for authorizing API calls, not profile attributes like name and email.

  • b
    The refresh token

    The refresh token is a long-lived credential used only to obtain new tokens from Cognito; it carries no readable identity claims.

  • c
    The SAML assertion from the identity provider

    Even with federation, the user pool normalizes the provider's response and issues its own JWTs — the application consumes those, not the raw assertion.

  • d
    The ID token Correct

    The ID token exists to carry identity claims — name, email, and other profile attributes — for use inside the application.

The concept

Cognito's three tokens have distinct jobs: the ID token answers "who is the user" with profile claims, the access token answers "what may this caller do", and the refresh token silently renews the other two.

Why that’s the answer

Profile data like name and email lives in the ID token's claims, which is exactly what a profile screen needs. The access token is the classic confusion: it authorizes API requests via scopes and groups but does not carry profile attributes. The refresh token is opaque to the application and only ever exchanged with Cognito. A SAML assertion, when federation is involved, is consumed by the user pool during brokering — the app still receives standard Cognito JWTs.

How to reason it out
  1. Identify the need: identity information for display, not API authorization.
  2. Map identity claims to the ID token and authorization to the access token.
  3. Read name and email from the validated ID token's payload.
  4. Continue sending the access token, not the ID token, when calling scoped APIs.

Exam tip: ID token = identity claims for the app; access token = authorization for APIs.

Authentication and Authorization on AWS: Cognito, IAM, and STS — the lesson that teaches this.

Question 2Security

Users of a single-page application must sign in again every hour when their Amazon Cognito access and ID tokens expire. The developer wants users to stay signed in for longer periods without re-entering credentials. What should the application do?

Choose one.

  • a
    Configure the app client so access tokens are valid for 30 days.

    Access and ID token validity is capped at 24 hours per app client, and long-lived bearer tokens widen the window an intercepted token can be abused.

  • b
    Send the refresh token to the API in place of the expired access token.

    The refresh token is only ever exchanged with Cognito itself; an API cannot and must not accept it in place of an access token.

  • c
    Use the refresh token to silently obtain new ID and access tokens from Cognito before the current ones expire. Correct

    That is the refresh token's purpose: it is exchanged with Cognito for fresh ID and access tokens without re-authentication, and it lives 30 days by default.

  • d
    Store the user's password in local storage and re-authenticate automatically each hour.

    Persisting passwords client-side is a serious security defect; token renewal exists precisely so credentials never need to be stored.

The concept

Cognito issues short-lived ID and access tokens (one hour by default) alongside a long-lived refresh token (30 days by default) whose only job is renewing the other two against Cognito without re-login.

Why that’s the answer

Silent renewal with the refresh token keeps sessions alive while access tokens stay short-lived — the intended design. Stretching access token validity to 30 days is impossible (24-hour maximum) and would be poor practice even if allowed, because bearer tokens grant access to whoever holds them. Sending the refresh token to the API misroutes it — it is only valid against Cognito. Storing passwords locally to re-authenticate is a textbook credential-handling failure.

How to reason it out
  1. Keep ID and access token lifetimes short — that is a security feature, not a bug.
  2. Hold the refresh token securely on the client.
  3. Before or upon expiry, exchange the refresh token with Cognito for new ID and access tokens.
  4. Force full re-authentication only when the refresh token itself expires or is revoked.

Exam tip: Session longevity comes from the refresh token exchanged with Cognito — never from long-lived access tokens or stored passwords.

Authentication and Authorization on AWS: Cognito, IAM, and STS — the lesson that teaches this.

Question 3Security

A backend service receives JWTs that were issued by an Amazon Cognito user pool. What must the service do before trusting the claims in a token?

Choose one.

  • a
    Base64-decode the token payload and read the claims directly.

    Decoding is not verification — anyone can construct a token with arbitrary claims, so unverified claims must never be trusted.

  • b
    Compare the token against a copy stored in the database at sign-in time.

    JWTs are self-contained bearer tokens designed to be verified cryptographically; storing and comparing copies defeats the design and still does not verify the signature.

  • c
    Forward the token to AWS STS for validation.

    STS issues temporary AWS credentials; it does not validate Cognito user pool JWTs.

  • d
    Verify the token's signature against the user pool's published public keys (JWKS) and validate the expiry and issuer claims. Correct

    Signature verification against the JWKS proves Cognito issued the token unaltered, and checking exp and iss rejects expired tokens and tokens from the wrong pool.

The concept

A JWT has three parts — header, payload, signature — and its trustworthiness rests entirely on verifying the signature against the issuer's public keys, plus validating standard claims such as expiry and issuer.

Why that’s the answer

The backend must verify the signature using the user pool's JWKS endpoint and check that exp has not passed, iss matches the expected user pool, and the audience/token_use fit the context. Merely decoding the payload accepts forged tokens. Storing tokens in a database for comparison misunderstands bearer tokens — they are stateless and verified with cryptography, not lookups. STS is a credential-minting service and plays no role in JWT validation.

How to reason it out
  1. Fetch and cache the user pool's public keys from its JWKS endpoint.
  2. Verify the token signature with the key identified by the token header's key ID.
  3. Validate exp (not expired), iss (correct user pool), and the audience or token_use claim.
  4. Only then read claims such as sub and cognito:groups to make authorization decisions.

Exam tip: Trust a JWT only after verifying its signature against the issuer's JWKS and validating expiry and issuer — decoding alone proves nothing.

Authentication and Authorization on AWS: Cognito, IAM, and STS — the lesson that teaches this.

Question 4Security

A company's employees sign in through a corporate SAML 2.0 identity provider. A new internal application's API must validate one consistent token format for all users, and the company may add social sign-in later. What should the developer implement?

Choose one.

  • a
    Configure the SAML IdP as a federated identity provider in a Cognito user pool, so the user pool issues its own JWTs after sign-in. Correct

    The user pool acts as an identity broker: whichever provider signs the user in, it normalizes the result and issues standard Cognito JWTs — one token format for the API, and social providers can be added later.

  • b
    Migrate all employee accounts into a new Cognito user pool directory with new passwords.

    When users already authenticate with a corporate IdP, the answer is federation — never migrating or duplicating accounts into a second directory.

  • c
    Configure the SAML IdP directly in a Cognito identity pool.

    An identity pool exchanges the SAML result for temporary AWS credentials — it does not produce a normalized application token for the API to validate.

  • d
    Create an IAM user for each employee and map SAML attributes to it.

    IAM users are for AWS access, not application authentication, and federation exists precisely to avoid creating per-user IAM identities.

The concept

A Cognito user pool can broker federation: external SAML 2.0, OIDC, and social providers are registered with the pool, and after any of them authenticates the user, the pool issues its own standard JWTs.

Why that’s the answer

The requirement is a single, consistent token format regardless of provider — exactly what user pool brokering delivers, and adding a social provider later is just another IdP registration. Migrating accounts duplicates identities and passwords the company already manages, the classic anti-pattern when a scenario says employees "already authenticate" somewhere. An identity pool federates too, but its output is temporary AWS credentials, not an application JWT. Per-employee IAM users confuse AWS access management with application authentication.

How to reason it out
  1. Register the corporate SAML IdP with the Cognito user pool.
  2. Have employees sign in through the provider via the user pool's sign-in flow.
  3. Let the user pool normalize the response and issue ID, access, and refresh JWTs.
  4. Validate those Cognito JWTs in the API — the same code path for any future social provider.

Exam tip: An existing corporate IdP means federate through a user pool as broker — one JWT format out, no duplicated accounts.

Authentication and Authorization on AWS: Cognito, IAM, and STS — the lesson that teaches this.

Question 5Security

A developer with an IAM identity in account A receives an AccessDenied error when calling sts:AssumeRole for a role in account B. The role's trust policy correctly specifies account A as a trusted principal. What is the MOST likely cause?

Choose one.

  • a
    The role in account B is missing an instance profile.

    Instance profiles are containers that attach roles to EC2 instances; they are irrelevant to an explicit cross-account AssumeRole call.

  • b
    Account B must also create an IAM user for the developer.

    Cross-account role assumption exists precisely so the target account never needs to create identities for external callers.

  • c
    The role's permissions policy does not include sts:AssumeRole.

    A role's permissions policy governs what the role can do after it is assumed — it plays no part in who may assume the role.

  • d
    The developer's identity-based policy in account A does not allow sts:AssumeRole on the role's ARN. Correct

    Assuming a role is a two-sided handshake: the trust policy must name the caller AND the caller's own identity-based policy must allow sts:AssumeRole on that role — the second side is missing here.

The concept

sts:AssumeRole requires two allows: the role's trust policy (a resource-based policy) must name the caller as a principal, and the caller's identity-based policy must permit sts:AssumeRole on the role's ARN.

Why that’s the answer

The stem establishes the trust-policy side is already correct, so the remaining failure point is the caller's side: the developer's identity in account A needs an explicit allow for sts:AssumeRole on the role's ARN. An instance profile only matters for EC2-attached roles. Creating an IAM user in account B contradicts the whole point of cross-account roles. The role's own permissions policy determines what the assumed session can do, never who can assume it.

How to reason it out
  1. Confirm the trust policy in account B names the account A principal and allows sts:AssumeRole.
  2. Check the caller's identity-based policy in account A for an allow on sts:AssumeRole with the role's ARN.
  3. Add the missing allow scoped to that specific role ARN.
  4. Retry AssumeRole and use the returned temporary credentials in account B.

Exam tip: AssumeRole failures are two-sided: verify the role's trust policy AND the caller's sts:AssumeRole permission — a correct trust policy alone is not enough.

Authentication and Authorization on AWS: Cognito, IAM, and STS — the lesson that teaches this.

Question 6Security

An application on an Amazon EC2 instance has an instance profile role that allows all the DynamoDB actions it needs, yet its API calls fail with an AccessDenied error that references an old, deactivated IAM user. The instance's environment still exports AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY values left over from earlier testing. Why is the instance role not being used?

Choose one.

  • a
    Environment variables are checked before the instance metadata service in the SDK credential provider chain, so the stale keys win. Correct

    The provider chain stops at the first credentials it finds, and environment variables sit earlier in the chain than the instance role — the deactivated user's keys are silently used.

  • b
    Instance profile credentials must be explicitly loaded in application code before the SDK can use them.

    The chain reaches the instance metadata service automatically — role-based designs need zero credential code.

  • c
    The role's temporary credentials have expired and must be refreshed manually.

    The platform refreshes instance-role credentials continuously; manual refresh is never required.

  • d
    IAM roles cannot be used on instances where AWS environment variables are defined.

    Roles work regardless; the issue is precedence order in the chain, not any incompatibility.

The concept

AWS SDKs resolve credentials through the credential provider chain, checking sources in a fixed order — explicit configuration, environment variables, the shared credentials file, web identity, container credentials, then the EC2 instance metadata service — and stopping at the first hit.

Why that’s the answer

Because environment variables precede the instance metadata service in the chain, the leftover AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY silently outrank the attached role — and since that user is deactivated, calls fail with an error naming it. Nothing needs to be loaded in code for a role to work, the platform refreshes role credentials automatically, and there is no rule preventing roles from coexisting with environment variables — precedence, not compatibility, is the problem.

How to reason it out
  1. Read the error: it names a deactivated IAM user, not the instance role — some other credential source is winning.
  2. Recall the chain order: environment variables come before the instance metadata service.
  3. Unset AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY on the instance.
  4. Confirm the SDK now falls through to the instance role's temporary credentials.

Exam tip: The credential provider chain stops at the first match — stale environment-variable keys silently override an attached instance role.

Authentication and Authorization on AWS: Cognito, IAM, and STS — the lesson that teaches this.

What DVA-C02 domain 2 tests, topic by topic

The official exam guide breaks Security into 3 topics. The question bank follows the same split, so a weak topic shows up as a cluster of misses you can go back and read.

Published DVA-C02 practice questions per topic in Security
TopicWhat it coversQuestions
Implement authentication and/or authorization for applications and AWS servicesExam guide task 2.1. Federated access via identity providers (Amazon Cognito, IAM); bearer tokens; programmatic AWS access and authenticated service-to-service calls; assuming IAM roles and defining permissions for IAM principals; application-level authorization for fine-grained access control; cross-service authentication in microservice architectures.20
Implement encryption by using AWS servicesExam guide task 2.2. Encryption at rest vs in transit; client-side vs server-side encryption; certificate management (e.g. AWS Private CA) and generating certificates/SSH keys for development; encrypting and decrypting with AWS KMS keys; cross-account encryption; enabling and disabling key rotation.20
Manage sensitive data in application codeExam guide task 2.3. Data classification (PII, PHI); encrypting sensitive environment variables; secret management services (Secrets Manager, Systems Manager Parameter Store); sanitizing sensitive data; application-level data masking; data access patterns for multi-tenant applications.20
Total60

Revise Security before you drill it

Other DVA-C02 domains

Security: your questions

Security is domain 2 of the DVA-C02 exam guide and carries 26% of the scored content — the 2nd-heaviest of the 4 domains. On a 65-question paper that works out to roughly 17 questions, though AWS does not publish an exact per-domain count and individual exam forms vary.

Source

The domain weight and topic list on this page come from the official DVA-C02 exam guide.