How to Create a AWS CloudFormation Stack – Tutorial – Part 4

0
344
How to Create a AWS CloudFormation Stack

What is CloudFormation?

With AWS CloudFormation we don’t need to individually create and configure AWS resources. By using AWS CloudFormation, we easily manage a collection of resources as a single unit. With a right template, we can deploy at once all the AWS resources we need for an application.

Since CloudFormation helps us model and set up our Amazon Web Services resources, we can spend less time managing resources and more time focusing on our applications that run in AWS. We just create a template that describes all the AWS resources that we want such as Amazon EC2 instances or Amazon RDS DB instances. The AWS CloudFormation takes care of provisioning and configuring those resources for us.

CloudFormation takes case of ASGs, an ELBs, and RDS database instances, so we can just create or modify an existing AWS CloudFormation template which describes all of our resources and their properties.

When we use that template to create an AWS CloudFormation stack, AWS CloudFormation provisions all resources. After the stack has been successfully created, our AWS resources are up and running. We can delete the stack just as easily, which deletes all the resources in the stack.

Note

In this tutorial, we’ll create a WordPress blog as a stack, monitors the stack creation process, examines the resources on the stack, and then deletes the stack.

Here will see How to Create stack on the AWS CloudFormation console,

Starting the Create Stack Wizard

To create a stack on the AWS CloudFormation console

Step1: Log in to the AWS Management Console and select CloudFormation in the Menu

AWS CloudFormation selectStep2: Create a new stack by using one of the following options:

  • Click Create Stack. This is the only option if you have a currently running stack.

Cloud formation stackSelect Stack Template

AWS CloudFormation templates are JSON- or YAML-formatted files that specify the AWS resources that make up your stack. For more information about AWS CloudFormation templates, see Working with AWS CloudFormation Templates.

To choose a stack template:

  1. On the Select Template page, choose a stack template by using one of the following options:

Design a template

To create or modify a template, use AWS CloudFormation Designer, a drag-and-drop interface. Refer What Is AWS CloudFormation Designer?.

Choose a template

  • Select a sample template.

Select an AWS CloudFormation template from a list of samples. For descriptions of the templates, see Sample Templates.

To create a stack from existing AWS resources by using the CloudFormer tool, select CloudFormer from the list. For more information, see Using CloudFormer to Create Templates.

  • Upload a template to Amazon S3.

Select an AWS CloudFormation template on your local computer. Choose Choose File to select the template file that you want to upload. The template can be a maximum size of 460,800 bytes.

If you use the CLI or API to create a stack, you can upload a template with a maximum size of 51,200 bytes.

Note

If you upload a local template file, AWS CloudFormation uploads it to an Amazon Simple Storage Service (Amazon S3) bucket in your AWS account. The buckets are accessible to anyone with Amazon S3 permissions in your AWS account. If you don’t already have an S3 bucket that was created by AWS CloudFormation, it creates a unique bucket for each Region in which you upload a template file. If you already have an S3 bucket that was created by AWS CloudFormation in your AWS account, AWS CloudFormation adds the template to that bucket.

You can use your own bucket and manage its permissions by manually uploading templates to Amazon S3. When you create or update a stack, specify the Amazon S3 URL of a template file.

  • Specify an Amazon S3 template URL.

Specify a URL to a template in an S3 bucket.

Important

If your template includes nested stacks (for example, stacks described in other template documents located in subdirectories), ensure that your S3 bucket contains the necessary files and directories.

If you have a template in a versioning-enabled bucket, you can specify a specific version of the template, such as https://s3.amazonaws.com/templates/myTemplate.template?versionId=123ab1cdeKdOW5IH4GAcYbEngcpTJTDW. For more information, see Managing Objects in a Versioning-Enabled Bucket in the Amazon Simple Storage Service Console User Guide.

The URL must point to a template with a maximum size of 460,800 bytes that is stored in an S3 bucket that you have read permissions to and that is located in the same region as the stack. The URL can be a maximum of 1024 characters long.

Before creating resources, AWS CloudFormation validates your template to catch syntactic and some semantic errors, such as circular dependencies. During validation, AWS CloudFormation first checks if the template is valid JSON. If it isn’t, AWS CloudFormation checks if the template is valid YAML. If both checks fail, AWS CloudFormation returns a template validation error.

In our case will select the sample wordpress template to create the stack.

select sample templateSpecifying Stack Name

After selecting a stack template, specify the stack name and values for the parameters that were defined in the template.

spectify stack detailsWith parameters, you can customize your stack at creation time. Your parameter values can be used in the stack template to modify how resources are configured. That way you don’t have to hard code values in multiple templates to specify different settings. For more information about parameters in an AWS CloudFormation template, see Parameters.

To specify the stack name parameter values

  • On the Specify Details page, type a stack name in the Stack name box.

The stack name is an identifier that helps you find a particular stack from a list of stacks. A stack name can contain only alphanumeric characters (case-sensitive) and hyphens. It must start with an alphabetic character and can’t be longer than 128 characters.

  • In the Parameters section, specify parameters that are defined in the stack template.

You can use or change any parameters with default values.

Setting AWS CloudFormation Stack Options

After specifying parameters that are defined in the template, you can set additional options for your stack.

stack optionYou can set the following stack options:

Tags

Tags are arbitrary key-value pairs that can be used to identify your stack for purposes such as cost allocation. For more information about what tags are and how they can be used, see Tagging Your Resources in the Amazon EC2 User Guide.

A Key consists of any alphanumeric characters or spaces. Tag keys can be up to 127 characters long. A Value consists of any alphanumeric characters or spaces. Tag values can be up to 255 characters long.

Advance Option:

stack advance optionPermissions

An existing AWS Identity and Access Management (IAM) service role that AWS CloudFormation can assume.

Instead of using your account credentials, AWS CloudFormation uses the role’s credentials to create your stack. For more information, see AWS CloudFormation Service Role.

Notification Options

A new or existing Amazon Simple Notification Service topic where notifications about stack events are sent.

If you create an Amazon SNS topic, you must specify a name and an email address, where stack event notifications are sent.

Timeout

The number of minutes before stack creation times out. If the stack could not be created before the time expires, creation fails due to timeout and the stack is rolled back. By default, the stack creation never times out.

Rollback on failure

Specifies whether the stack should be rolled back if stack creation fails. Typically, you want to accept the default value of Yes. Select No if you want the stack’s state retained even if creation fails, such as when you are debugging a stack template.

Stack policy

Defines the resources that you want to protect from unintentional updates during a stack update. By default, all resources can be updated during a stack update. For more information, see Prevent Updates to Stack Resources.

Enable termination protection

Prevents a stack from being accidently deleted. If a user attempts to delete a stack with termination protection enabled, the deletion fails and the stack–including its status–remains unchanged. For more information, see Protecting a Stack From Being Deleted.

Review Your Stack

The final step before your stack is launched is to review the values entered while creating the stack. You can also estimate the cost of your stack.

  1. review stackOn the Review page, review the details of your stack.

If you need to change any of the values prior to launching the stack, click Back to go back to the page that has the setting that you want to change.

  1. (Optional) You can click the Cost link to estimate the cost of your stack. The AWS Simple Monthly Calculator displays values from your stack template and launch settings.
  2. After you review the stack launch settings and the estimated cost of your stack, click Create to launch your stack.

Your stack appears in the list of AWS CloudFormation stacks, with a status of CREATE_IN_PROGRESS.

Stack statusAfter your stack has been successfully created, its status changes to CREATE_COMPLETE. You can then select it (if necessary) and click the Outputs tab to view your stack’s outputs if you have defined any in the template.

stack complete

The sample WordPress stack creates a WordPress website. We can continue with the WordPress setup by running the WordPress installation script.

On the Outputs tab, in the WebsiteURL row, click the link in the Value column.

stack outputThe WebsiteURL output value is the URL of the installation script for the WordPress website that we created with the stack.

User the URL and Access the wordpress site which we created.

wordpress login

We have completed the AWS CloudFormation getting started tasks.

Read More: AWS CloudFormation – Part 5

NO COMMENTS