AWS DevOps DevOps Automation Tools & Scripting Techniques 2 — Questions and Answers
Question 1: A DevOps engineer needs to run a shell script as a post-deploy hook in AWS CodeDeploy. Which AppSpec file section should contain this script reference?
- BeforeInstall
- AfterInstall
- ApplicationStart (Correct answer)
- ValidateService
Correct answer: ApplicationStart
The ApplicationStart lifecycle hook runs scripts after the application files have been installed, making it the correct place for post-deploy startup logic.
Question 2: Which AWS CLI command lists all available parameter names stored in AWS Systems Manager Parameter Store under a specific path prefix?
- aws ssm get-parameters --path /myapp/
- aws ssm describe-parameters --filters Key=Path,Values=/myapp/
- aws ssm get-parameters-by-path --path /myapp/ (Correct answer)
- aws ssm list-parameters --prefix /myapp/
Correct answer: aws ssm get-parameters-by-path --path /myapp/
aws ssm get-parameters-by-path retrieves all parameters within a specified path hierarchy, making it ideal for prefix-based lookups.
Question 3: In a Jenkins pipeline, a developer wants to skip a stage if a specific environment variable is not set. Which Jenkinsfile construct achieves this?
- post { always {} }
- when { environment name: 'VAR', value: 'true' } (Correct answer)
- options { skipStagesAfterUnstable() }
- triggers { cron('H/15 * * * *') }
Correct answer: when { environment name: 'VAR', value: 'true' }
The 'when' directive with 'environment' condition evaluates the stage conditionally based on whether the named environment variable matches the given value.
Question 4: A team uses AWS Systems Manager Run Command to execute scripts across 50 EC2 instances simultaneously. What is the recommended way to avoid overwhelming all instances at once?
- Use --max-concurrency and --max-errors parameters (Correct answer)
- Schedule separate Run Command jobs for each instance
- Use AWS Lambda to stagger execution
- Enable SSM Inventory before running commands
Correct answer: Use --max-concurrency and --max-errors parameters
--max-concurrency limits how many instances execute simultaneously while --max-errors defines the failure threshold before the command halts.
Question 5: Which Python boto3 pattern is considered best practice for handling AWS API throttling in automation scripts?
- Catch ClientError and immediately retry without delay
- Use exponential backoff with jitter on ThrottlingException (Correct answer)
- Switch to a different AWS region on throttling
- Increase the API rate limit via AWS Support before running scripts
Correct answer: Use exponential backoff with jitter on ThrottlingException
Exponential backoff with jitter spreads retry attempts over time, reducing contention and preventing thundering herd problems when AWS throttles API calls.
Question 6: A CloudFormation custom resource needs to signal success or failure back to the stack. What mechanism does the Lambda function use to communicate this?
- Return an HTTP status code directly to CloudFormation
- Write the result to an S3 bucket that CloudFormation polls
- Send a PUT request to the pre-signed S3 URL in the ResponseURL event field (Correct answer)
- Publish a message to an SNS topic monitored by CloudFormation
Correct answer: Send a PUT request to the pre-signed S3 URL in the ResponseURL event field
CloudFormation custom resources require the Lambda function to PUT a JSON response to the ResponseURL pre-signed S3 URL provided in the event, signaling SUCCESS or FAILED.
Question 7: When writing an AWS CDK app in Python, which command synthesizes the CloudFormation template without deploying it?
- cdk deploy --dry-run
- cdk synth (Correct answer)
- cdk diff
- cdk preview
Correct answer: cdk synth
cdk synth generates and prints the CloudFormation template for the CDK app without making any changes to the AWS environment.
A DevOps engineer needs to run a shell script as a post-deploy hook in AWS CodeDeploy.
Which AppSpec file section should contain this script reference?