A CloudFormation template includes an AWS::EC2::Instance resource and a custom resource implemented by a Lambda function that needs to perform actions on that EC2 instance. During deployment the Lambda custom resource runs before the EC2 instance exists and fails. How do you ensure the custom resource waits until the EC2 instance is created?
Choose an answer
Tap an option to check your answer.
Correct answer: Add a DependsOn attribute to the custom resource that names the EC2 instance..
Why this is the answer
The DependsOn attribute in CloudFormation explicitly defines the creation order of resources. By adding DependsOn to the custom resource and specifying the EC2 instance's logical ID, you instruct CloudFormation to create the EC2 instance completely before attempting to create or invoke the custom resource. This ensures the EC2 instance exists when the Lambda function (backing the custom resource) executes. Updating the ServiceToken is about pointing to the correct Lambda function, not controlling execution order. Modifying the Lambda to use cfn-response is crucial for the custom resource to signal success or failure back to CloudFormation, but it doesn't address the dependency issue. Fn::If is a conditional function for template processing, not for runtime dependency management between resources.
Pass your exam — without the endless answer hunt
Get every verified question and explanation for this exam in one place, and save hours of prep. 1,000+ certifications · 20+ languages · free to start.
Pass your exam faster → No card needed