AWS DevOps DevOps Automation Tools & Scripting Techniques 4 — Questions and Answers
Question 1: A bash script running in CodeBuild needs to exit immediately when any command fails. Which bash option enables this behavior?
- set -x
- set -e (Correct answer)
- set -u
- set -o pipefail
Correct answer: set -e
set -e causes the shell to exit immediately when any command returns a non-zero exit status, preventing silent failures from propagating.
Question 2: Which feature of AWS CodePipeline allows a pipeline to pause and wait for a human to review an artifact before proceeding to the next stage?
- Approval action in the pipeline stage (Correct answer)
- CodePipeline waitForToken built-in condition
- SNS notification with automatic 24-hour pause
- CloudWatch alarm gating the pipeline transition
Correct answer: Approval action in the pipeline stage
A manual approval action pauses the pipeline and sends an optional SNS notification; the pipeline resumes only after an authorized reviewer approves or rejects.
Question 3: A team uses AWS SAM CLI to test a Lambda function locally before deploying. Which command invokes the function locally using a sample event JSON file?
- sam deploy --local --event event.json
- sam local invoke -e event.json FunctionName (Correct answer)
- sam run --function FunctionName --payload event.json
- sam test --local FunctionName event.json
Correct answer: sam local invoke -e event.json FunctionName
sam local invoke -e event.json FunctionName runs the specified Lambda function locally using the provided event JSON file for testing before deployment.
Question 4: In a CloudFormation template, a developer uses !Sub to construct an ARN string. Which syntax correctly substitutes the AWS account ID into a string?
- !Sub 'arn:aws:s3:::${AccountId}-bucket'
- !Sub 'arn:aws:s3:::${AWS::AccountId}-bucket' (Correct answer)
- !Ref 'AWS::AccountId' + '-bucket'
- !Join ['', ['arn:aws:s3:::AccountId-bucket']]
Correct answer: !Sub 'arn:aws:s3:::${AWS::AccountId}-bucket'
!Sub uses ${AWS::AccountId} with the pseudo parameter AWS::AccountId to dynamically substitute the current account ID into the string.
Question 5: A Lambda function triggered by S3 events needs to process files only from a specific prefix path. Where is this filter configured?
- In the Lambda function code using an if statement
- In the S3 bucket's bucket policy
- In the S3 event notification filter rules with prefix and suffix conditions (Correct answer)
- In the Lambda function's environment variables
Correct answer: In the S3 event notification filter rules with prefix and suffix conditions
S3 event notifications support filter rules on key prefix and suffix, so only objects matching the pattern trigger the Lambda function.
Question 6: Which AWS CodeBuild environment variable automatically contains the full URI of the ECR repository, available without manual configuration in standard CodeBuild projects?
- $AWS_ECR_REGISTRY
- $CODEBUILD_RESOLVED_SOURCE_VERSION
- There is no built-in ECR URI variable; it must be set manually (Correct answer)
- $AWS_DEFAULT_ECR_URI
Correct answer: There is no built-in ECR URI variable; it must be set manually
CodeBuild does not provide a built-in ECR URI variable; teams must define it as a custom environment variable or construct it from $AWS_ACCOUNT_ID and $AWS_DEFAULT_REGION.
Question 7: A script uses the AWS CLI to wait until a CloudFormation stack reaches CREATE_COMPLETE status before proceeding. Which command implements this blocking wait?
- aws cloudformation describe-stacks --query StackStatus until CREATE_COMPLETE
- aws cloudformation wait stack-create-complete --stack-name MyStack (Correct answer)
- aws cloudformation poll-status --stack-name MyStack --status CREATE_COMPLETE
- aws cloudformation watch --stack-name MyStack
Correct answer: aws cloudformation wait stack-create-complete --stack-name MyStack
aws cloudformation wait stack-create-complete polls the stack status at 30-second intervals and returns only when the stack reaches CREATE_COMPLETE or fails.
A bash script running in CodeBuild needs to exit immediately when any command fails.
Which bash option enables this behavior?