Answer - A.
The AWS Documentation mentions the following.
When you launch stacks, you can install and configure software applications on Amazon EC2 instances by using the cfn-init helper script and the AWS::CloudFormation::Init resource.
By using AWS::CloudFormation::Init, you can describe the configurations that you want rather than scripting procedural steps.
Because of what the AWS documentation clearly mentions, all other options are invalid.
For more information on the best practices for Cloudformation, please refer to the below URL-
https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/best-practices.html
The correct answer for this question is option A: Use the cfn-init helper script in Cloudformation.
Explanation:
AWS CloudFormation is an Infrastructure as Code (IaC) service that allows users to model and provision AWS resources using templates. CloudFormation templates are JSON or YAML-formatted text files that describe the infrastructure and applications that users want to deploy on AWS.
To preconfigure EC2 Instances with the NGINX web server, CloudFormation provides a helper script called cfn-init. The cfn-init script is a part of the AWS CloudFormation Helper Scripts, which is a collection of scripts that are used to bootstrap and manage EC2 Instances. The cfn-init script allows users to install and configure software packages on EC2 Instances when they are launched.
To use the cfn-init script, users must first add it to the UserData section of the EC2 instance resource in the CloudFormation template. The UserData section is a script that is run by the EC2 instance when it is launched. The cfn-init script can then be used to install and configure NGINX on the EC2 Instance.
Example of how to use the cfn-init script in a CloudFormation template:
Resources: EC2Instance: Type: AWS::EC2::Instance Properties: ImageId: ami-0c55b159cbfafe1f0 InstanceType: t2.micro UserData: Fn::Base64: !Sub | #!/bin/bash -xe yum update -y yum install -y aws-cfn-bootstrap /opt/aws/bin/cfn-init -v \ --stack ${AWS::StackName} \ --resource EC2Instance \ --region ${AWS::Region}
In the example above, the cfn-init script is installed and run on the EC2 Instance in the UserData section of the EC2 instance resource. The script installs the AWS CloudFormation Helper Scripts, and then runs the cfn-init script to configure NGINX on the EC2 Instance.
Option B, C, and D are incorrect:
B. Use the Output resource type in CloudFormation: The Output resource type is used to export values from the CloudFormation stack. It is not used to preconfigure software on EC2 Instances.
C. Use the Parameter resource type in CloudFormation: The Parameter resource type is used to pass input values to the CloudFormation stack. It is not used to preconfigure software on EC2 Instances.
D. Use SAML to deploy the template: SAML (Security Assertion Markup Language) is not used to deploy CloudFormation templates. It is a protocol used for web-based Single Sign-On (SSO) authentication.