Skip to content

SAP-C03 · Domain 5: Operational Excellence and Automation · 20% of the exam

Task 5.1: Design infrastructure as code.

Infrastructure as code with CloudFormation and the CDK, policy as code that validates before and remediates drift after deployment, secrets kept out of templates, and deployments across accounts and Regions with StackSets.

Study it

  • Infrastructure as code with CloudFormation and the CDK, and StackSets across accounts

    Lesson coming

  • Policy as code and secrets kept out of templates

    Partly covered by: ConfigMaps, Secrets & Env

Sample questions

Try each one before opening the answer. Every option is explained, with the AWS documentation page that proves it.

Question 1 · choose 1

Developers change IAM policies in CloudFormation templates through a pipeline. The security team wants the pipeline to fail automatically when a change would grant new access compared with the approved version of a policy. Which approach fits?

  1. ARun IAM Access Analyzer policy validation in CI and fail on its findings
  2. BRun IAM Access Analyzer unused access analysis once a month in each account
  3. CTurn on CloudTrail data events for IAM
  4. DRun IAM Access Analyzer custom policy checks for new access in CI
Show the answer and why
  • ARun IAM Access Analyzer policy validation in CI and fail on its findings

    Incorrect

    Policy validation checks a policy against IAM policy grammar and AWS best practices and reports errors and warnings. It does not compare the change with the approved version to find new access.

  • BRun IAM Access Analyzer unused access analysis once a month in each account

    Incorrect

    Unused access findings look at granted access after deployment, not at a policy change in the pipeline.

  • CTurn on CloudTrail data events for IAM

    Incorrect

    CloudTrail records API activity after the fact; it does not block a deployment.

  • DRun IAM Access Analyzer custom policy checks for new access in CI

    Correct

    Custom policy checks can check a policy for new access against your security standards.

Catching new access in a pipeline is done with Access Analyzer custom policy checks.

Question 2 · choose 1

A company uses AWS Organizations without AWS Control Tower. Every account in its workloads OU must receive the same baseline: three IAM roles, an AWS Config recorder and a set of Config rules. Accounts created in or moved into the OU later must receive the baseline automatically, and it must be removed from accounts that leave the OU. Which solution requires the LEAST ongoing effort?

  1. AShare a Service Catalog portfolio with the OU so that each account administrator can launch the baseline product
  2. BRun a pipeline that assumes a role in each account listed in the OU and deploys a CloudFormation stack there every night
  3. CCreate a service-managed CloudFormation StackSet that targets the OU with automatic deployment turned on
  4. DCreate an organization conformance pack that contains the Config rules, the configuration recorder and the IAM roles
Show the answer and why
  • AShare a Service Catalog portfolio with the OU so that each account administrator can launch the baseline product

    Incorrect

    Service Catalog lets users launch approved products themselves, so the baseline would depend on someone launching it in each new account, and it would not be removed automatically when an account leaves the OU.

  • BRun a pipeline that assumes a role in each account listed in the OU and deploys a CloudFormation stack there every night

    Incorrect

    This can work, but the company would build and run the pipeline, discover new accounts itself and write its own clean-up for accounts that leave.

  • CCreate a service-managed CloudFormation StackSet that targets the OU with automatic deployment turned on

    Correct

    With service-managed permissions and automatic deployment, StackSets deploys stack instances to accounts added to the target OU and can remove them from accounts that are removed from it.

  • DCreate an organization conformance pack that contains the Config rules, the configuration recorder and the IAM roles

    Incorrect

    A conformance pack is a collection of AWS Config rules and remediation actions. It is not a way to deploy IAM roles or other baseline resources.

"Same stack in every account of an OU, including future ones" is what StackSets with service-managed permissions and automatic deployment is for.

Question 3 · choose 1

A platform team of TypeScript developers is designing the infrastructure code for 40 new services. It wants to define infrastructure in TypeScript, with loops, conditions and inheritance, and to publish its own higher-level components, such as a load-balanced service with the company's logging and alarms built in, as versioned packages that every service team imports. Every deployment must still create or update CloudFormation stacks, because the release team reviews and audits changes at the stack level. Which approach meets these requirements?

  1. APackage the shared components as CloudFormation modules in the private registry and include them in each service's templates
  2. BWrite the components as AWS CDK constructs in TypeScript, publish them as packages, and deploy the apps through CloudFormation
  3. CWrite TypeScript scripts with the AWS SDK for JavaScript that create the resources, and share them as internal npm packages
  4. DDefine each service in an AWS SAM template, using its shorthand syntax, and deploy the templates with the SAM CLI
Show the answer and why
  • APackage the shared components as CloudFormation modules in the private registry and include them in each service's templates

    Incorrect

    Modules are reusable, versioned resource configurations that templates include through the CloudFormation registry, so they meet the reuse and stack requirements. They are declared in templates, though, not written as TypeScript code with loops and inheritance.

  • BWrite the components as AWS CDK constructs in TypeScript, publish them as packages, and deploy the apps through CloudFormation

    Correct

    The AWS CDK lets you define reusable cloud components, called constructs, in TypeScript and other languages, using parameters, conditionals, loops, composition and inheritance. You can create and distribute your own constructs, and CDK apps deploy through CloudFormation.

  • CWrite TypeScript scripts with the AWS SDK for JavaScript that create the resources, and share them as internal npm packages

    Incorrect

    The SDK gives TypeScript code a JavaScript API for AWS services, so the language and packaging fit. But scripts that call service APIs directly create resources outside any CloudFormation stack, which the release team needs.

  • DDefine each service in an AWS SAM template, using its shorthand syntax, and deploy the templates with the SAM CLI

    Incorrect

    An AWS SAM template is an extension of CloudFormation, so deployments still go through stacks. But it is a simplified template syntax for serverless resources, not TypeScript code with loops and inheritance.

Three constraints decide it: TypeScript with real programming constructs, shared versioned components, and deployment through CloudFormation stacks. Modules and SAM meet the stack requirement but are template syntax. SDK scripts are TypeScript but bypass CloudFormation. CDK constructs written in TypeScript, published as packages and synthesized into CloudFormation stacks meet all three.

Question 4 · choose 1

A security review found that 200 application servers keep the password of an Amazon RDS for SQL Server database in a configuration file. The password has not changed in two years. The company wants the password out of the files, rotated every 30 days automatically, and applications that keep working during rotation. Which solution meets these requirements?

  1. AStore the password as a SecureString parameter in Parameter Store and have each server read it at startup
  2. BKeep the credentials in AWS Secrets Manager with 30-day automatic rotation and fetch the secret at runtime
  3. CEncrypt the configuration files with an AWS KMS key and replace the files on every server each month
  4. DPut the password in an environment variable of each server through the instance user data
Show the answer and why
  • AStore the password as a SecureString parameter in Parameter Store and have each server read it at startup

    Incorrect

    SecureString parameters are encrypted, but Parameter Store has no built-in rotation, so the 30-day rotation would need custom code.

  • BKeep the credentials in AWS Secrets Manager with 30-day automatic rotation and fetch the secret at runtime

    Correct

    Secrets Manager can rotate Amazon RDS credentials automatically on a schedule, updating both the secret and the database, and applications that fetch the secret when they connect pick up the new value.

  • CEncrypt the configuration files with an AWS KMS key and replace the files on every server each month

    Incorrect

    The password stays in files on 200 servers, and changing it every month depends on a manual or custom process.

  • DPut the password in an environment variable of each server through the instance user data

    Incorrect

    AWS advises against keeping passwords in user data, because anyone with access to the instance can read it, and nothing would rotate the password.

"Out of the code, rotated on a schedule" is Secrets Manager rotation with applications that read the secret at runtime.

Question 5 · choose 1

A shared services account keeps about 300 configuration values for each of dev, test and prod, many of them long connection strings, as a flat list of standard Parameter Store parameters with names such as prod-app-db-url. Engineers and services often read another environment's value by mistake. The platform team wants each environment's application role to be able to read only that environment's values, each application to load all values for its environment with one query instead of naming every parameter, and no move to a paid parameter tier. Which change meets these requirements?

  1. AAttach labels such as dev, test and prod to the parameter versions and have applications request values by label
  2. BRename the parameters into hierarchies such as /prod/app/db-url, grant each role its path, and read with GetParametersByPath
  3. CMove the parameters to the advanced tier and add parameter policies that notify owners when a value is not changed for a long time
  4. DStore each environment's values as one JSON document in a single parameter per environment and parse it in the applications
Show the answer and why
  • AAttach labels such as dev, test and prod to the parameter versions and have applications request values by label

    Incorrect

    A parameter label is a user-defined alias for a version of one parameter, which helps track which version is in use. It does not group different parameters by environment for IAM or for bulk retrieval.

  • BRename the parameters into hierarchies such as /prod/app/db-url, grant each role its path, and read with GetParametersByPath

    Correct

    Hierarchies organize parameters by a path and let GetParametersByPath return everything under one level. IAM policies grant access by parameter ARN, which carries the path, so each role can be limited to its own environment, all on the standard tier.

  • CMove the parameters to the advanced tier and add parameter policies that notify owners when a value is not changed for a long time

    Incorrect

    Parameter policies such as NoChangeNotification need the advanced tier, which is charged. They help keep values current; they do not separate environments or allow bulk retrieval.

  • DStore each environment's values as one JSON document in a single parameter per environment and parse it in the applications

    Incorrect

    One parameter per environment would allow one read and one IAM grant, but a standard parameter holds at most 4 KB and an advanced one 8 KB, which is charged, so 300 long values do not fit in the free tier.

The constraints are per-environment access control, a single query per environment, and no paid tier. Labels track versions of one parameter, parameter policies need the paid tier, and one JSON parameter per environment exceeds the size limits. Path-based hierarchies give IAM scoping by path and GetParametersByPath on standard parameters.

Question 6 · choose 2

Forty Lambda functions call a payment vendor's API with an API key kept in a plain-text environment variable that every developer with console access can see. The vendor requires the key to be replaced every 30 days through its own API. The security team wants the key stored once, encrypted, rotated automatically on that schedule and no longer visible in any function's configuration. The functions handle 2,000 requests per second, so getting the key must add almost no latency and must not call the storage service on every invocation, and the developers will not write caching code. Which changes meet these requirements? (Choose TWO.)

  1. AHave each function call GetSecretValue through the AWS SDK at the start of every invocation to read the current key
  2. BStore the key as a SecureString parameter in Parameter Store, encrypted with a customer managed KMS key
  3. CRead the key through the AWS Parameters and Secrets Lambda Extension layer added to each function
  4. DKeep the environment variable but encrypt it with a customer managed KMS key that developers cannot use
  5. EStore the key as a secret in Secrets Manager with a rotation Lambda function that calls the vendor's API every 30 days
Show the answer and why
  • AHave each function call GetSecretValue through the AWS SDK at the start of every invocation to read the current key

    Incorrect

    Reading through the SDK always returns the current value, but it calls the service on every invocation. AWS notes that the caching approaches perform better and cost less than retrieving secrets directly with the SDK.

  • BStore the key as a SecureString parameter in Parameter Store, encrypted with a customer managed KMS key

    Incorrect

    A SecureString parameter is stored once and encrypted, but AWS recommends Secrets Manager for API keys because it provides automatic rotation, which Parameter Store does not.

  • CRead the key through the AWS Parameters and Secrets Lambda Extension layer added to each function

    Correct

    The extension retrieves and caches secrets without an SDK, and its local cache means a function does not call Secrets Manager on every invocation, which gives better performance and lower cost.

  • DKeep the environment variable but encrypt it with a customer managed KMS key that developers cannot use

    Incorrect

    With a customer managed key, only users with access to the key can view the variable, but the key still lives in every function's configuration, in 40 copies, with no rotation.

  • EStore the key as a secret in Secrets Manager with a rotation Lambda function that calls the vendor's API every 30 days

    Correct

    Secrets Manager stores secrets centrally and encrypted, and for secrets that are not managed by an AWS service, rotation uses a Lambda function that updates the secret and the external service on a schedule.

The constraints are one encrypted copy, automatic 30-day rotation, nothing in function configuration, and cached low-latency reads without new code. Secrets Manager with a rotation function covers storage and rotation, and the Lambda extension supplies cached reads. SDK calls on every invocation add latency and cost, SecureString parameters do not rotate, and an encrypted environment variable stays in each function.

Question 7 · choose 1

A platform team deploys a logging baseline with one service-managed StackSet that targets the Workloads OU in three Regions. The template has a RetentionDays parameter. The eight accounts that hold regulated data need a value of 3,653 days, while every other account keeps the StackSet's value of 90 days. The team wants to keep one StackSet and one template, and later template updates rolled out through the StackSet must not reset the regulated accounts to 90 days. Which approach meets these requirements?

  1. AOverride the RetentionDays parameter value on the stack instances of the eight regulated accounts
  2. BCreate a second StackSet from the same template for the regulated accounts, with RetentionDays set to 3,653
  3. CChange the StackSet's RetentionDays value to 3,653 in each update and deploy that update only to the regulated accounts
  4. DTag the regulated accounts in AWS Organizations so that the StackSet reads the retention value from the account tag
Show the answer and why
  • AOverride the RetentionDays parameter value on the stack instances of the eight regulated accounts

    Correct

    StackSets let you override parameter values for stack instances by account and Region, and overridden values keep their value during later StackSet updates.

  • BCreate a second StackSet from the same template for the regulated accounts, with RetentionDays set to 3,653

    Incorrect

    This sets the right value, but it means two StackSets to keep in step, and the team wants to keep one.

  • CChange the StackSet's RetentionDays value to 3,653 in each update and deploy that update only to the regulated accounts

    Incorrect

    The StackSet holds one parameter value for every stack instance that is not overridden, so the next update that reaches the other accounts would give them 3,653 days as well.

  • DTag the regulated accounts in AWS Organizations so that the StackSet reads the retention value from the account tag

    Incorrect

    Stack instances take their parameter values from the StackSet or from per-instance overrides. StackSets do not read parameter values from account tags.

Each stack in a StackSet comes from the same template, and parameters customize individual stacks. Parameter overrides set a different value for chosen accounts and Regions and survive later StackSet updates. With service-managed OU targets, an override applies to the accounts in the OU when it is set; accounts added later get the StackSet's value.

Practice domain 5 →Practice all domains →