AWS Certified SysOps Administrator – Associate — Question 385

A company has created an AWS CloudFormation template that consists of the AWS::EC2::Instance resource and a custom CloudFormation resource. The custom CloudFormation resource is an AWS Lambda function that attempts to run automation on the Amazon EC2 instance.

During testing, the Lambda function fails because the Lambda function tries to run before the EC2 instance is launched.

Which solution will resolve this issue?

Answer options

Correct answer: A

Explanation

The DependsOn attribute in AWS CloudFormation is used to specify that the creation of a specific resource follows another. By adding a DependsOn attribute to the custom resource and pointing it to the AWS::EC2::Instance, CloudFormation guarantees the EC2 instance is fully created before the Lambda function runs. Other options like updating the service token, using cfn-response, or using Fn::If do not address the resource creation dependency order.