AWS CloudFormation Custom Resource - Deploying Applications | Exam Prep

Using Custom Resources in AWS CloudFormation

Prev Question Next Question

Question

As an architect, you have decided to use CloudFormation instead of OpsWorks or Elastic Beanstalk for deploying the applications in your company.

There is a requirement to include a custom resource using the AWS CloudFormation.

How can you achieve this?

Answers

Explanations

Click on the arrows to vote for the correct answer

A. B. C. D.

Answer - B.

Custom resources enable you to write custom provisioning logic in templates that AWS CloudFormation runs anytime you create, update (if you changed the custom resource), or delete stacks.

For example, you might want to include resources that aren't available as AWS CloudFormation resource types.

You can include those resources by using custom resources (AWS::CloudFormation::CustomResource)

That way, you can still manage all your related resources in a single stack.

Options A, C and D are incorrect because they are not the correct methods to specify a custom resource in the AWS CloudFormation template.

For more information on custom resources in CloudFormation, please visit the below URL:

https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/template-custom-resources.html
The template developer and custom resource provider can be the same person or entity, but the process is the
same. The following steps describe the general process:

1. The template developer defines a custom resource in his or her template, which includes a service token and
any input data parameters. Depending on the custom resource, the input data might be required; however, the
service token is always required.

The service token specifies where AWS CloudFormation sends requests to, such as to an Amazon SNS topic
ARN or to an AWS Lambda function ARN. For more information, see AWS::CloudFormation::CustomResource.
The service token and the structure of the input data is defined by the custom resource provider.

2. Whenever anyone uses the template to create, update, or delete a custom resource, AWS CloudFormation
sends a request to the specified service token. The service token must be in the same region in which you are
creating the stack.

Sure, I'd be happy to provide a detailed explanation of the answer options for this question.

The question is asking how to include a custom resource using AWS CloudFormation, given that the architect has chosen to use CloudFormation instead of OpsWorks or Elastic Beanstalk for deploying applications in their company.

First, let's define what a custom resource is in the context of AWS CloudFormation. A custom resource is a way to define a resource type that doesn't exist natively in CloudFormation. It allows you to create and manage AWS resources that are not supported by CloudFormation out of the box. Custom resources can be created using AWS Lambda functions, which can interact with the custom resource to create, update, or delete resources.

With that in mind, let's look at each answer option:

A. Add a custom mapping in your template to specify which custom resource would be used.

This answer option is incorrect because custom mappings are used to define static values that can be used throughout a CloudFormation template. Custom mappings are not used to create custom resources.

B. Create a custom resource AWS::CloudFormation::CustomResource in the CloudFormation template.

This answer option is correct. To include a custom resource using CloudFormation, you can define a new resource type called AWS::CloudFormation::CustomResource in your CloudFormation template. This resource type allows you to specify a Lambda function that CloudFormation can use to manage the custom resource.

C. Create a Lambda function resource in the CloudFormation template and use the Lambda function to interact with the custom resource.

This answer option is partially correct, but not the most complete answer. While it's true that Lambda functions can be used to interact with custom resources, creating a Lambda function alone is not enough to create a custom resource. To create a custom resource, you must define a resource type in your CloudFormation template and specify the Lambda function to use with that resource type, as described in answer option B.

D. Create an SNS topic resource in the CloudFormation template and subscribe to the SNS topic for the custom resource.

This answer option is incorrect because SNS topics are not used to create custom resources. SNS topics are used for sending messages between AWS services, such as notifications or alerts.

In conclusion, the correct answer to the question is B: Create a custom resource AWS::CloudFormation::CustomResource in the CloudFormation template. This option allows you to define a new resource type that CloudFormation can use to manage your custom resource using a Lambda function.