-
Book Overview & Buying
-
Table Of Contents
Amazon Redshift Cookbook
By :
With an AWS CloudFormation template, you treat your infrastructure as code. This enables you to create an Amazon Redshift cluster using a JSON or YAML file. The declarative code in the file contains the steps to create the AWS resources and enables easy automation and distribution. This template allows you to standardize the Amazon Redshift provisioned cluster creation to meet your organizational infrastructure and security standards.
Further, you can distribute them to different teams within your organization using the AWS service catalog for an easy setup. In this recipe, you will learn how to use a CloudFormation template to deploy an Amazon Redshift provisioned cluster and the different parameters associated with it.
To complete this recipe, you will need:
We use the CloudFormation template to author the Amazon Redshift cluster infrastructure as code using a JSON-based template. Follow these steps to create the Amazon Redshift provisioned cluster using the CloudFormation template:
Creating_Amazon_Redshift_Cluster.json file from your local computer, and click Next.myredshiftcluster.dev.awsuser./, "", or @.ra3.xlplus.5439.AWS CloudFormation has deployed all the infrastructure and configuration listed in the template in completed and we’ll wait till the status changes to CREATE_COMPLETE.
How it works…
Let’s now see how this CloudFormation template works. The CloudFormation template is organized into three broad sections: input parameters, resources, and outputs. Let’s discuss them one by one.
The Parameters section is used to allow user input choices and also can be used to apply constraints to the values. To create an Amazon Redshift resource, we collect parameters such as database name, master username/ password, and cluster type. The parameters will later be substituted when creating the resources. Here is an illustration of the Parameters section of the template:
"Parameters": {
"DatabaseName": {
"Description": "The name of the first database to be created when the cluster is created",
"Type": "String",
"Default": "dev",
"AllowedPattern": "([a-z]|[0-9])+"
},
"NodeType": {
"Description": "The type of node to be provisioned",
"Type": "String",
"Default": "ra3.xlplus",
"AllowedValues": [
"ra3.16xlarge",
"ra3.4xlarge",
"ra3.xlplus",
]
}
In the previous input section, DatabaseName is a string value that defaults to dev and also enforces an alphanumeric validation when specified using the condition check of AllowedPattern: ([a-z]|[0-9])+. Similarly, NodeType defaults to ra3.xlplus and allows the valid NodeType from a list of values.
The Resources section contains a list of resource objects, and the Amazon resource is invoked using AWS::Redshift::Cluster along with references to the input parameters, such as DatabaseName, ClusterType, NumberOfNodes, NodeType, MasterUsername, and MasterUserPassword:
"Resources": {
"RedshiftCluster": {
"Type": "AWS::Redshift::Cluster",
"DependsOn": "AttachGateway",
"Properties": {
"ClusterType": {
"Ref": "ClusterType"
},
"NumberOfNodes": {
…
},
"NodeType": {
"Ref": "NodeType"
},
"DBName": {
"Ref": "DatabaseName"
},
..
The Resources section references the input section for values such as NumberOfNodes, NodeType, DatabaseName, that will be used during the resource creation.
The Outputs section is a handy place to capture the essential information about your resources or input parameters that you want to have available after the stack has been created, so you can easily identify the resource object names that are created.
For example, you can capture output such as ClusterEndpoint that will be used to connect into the cluster as follows:
"Outputs": {
"ClusterEndpoint": {
"Description": "Cluster endpoint",
"Value": {
"Fn::Join": [
":",
[
{
"Fn::GetAtt": [
"RedshiftCluster",
"Endpoint.Address"
]
},
{
"Fn::GetAtt": [
"RedshiftCluster",
"Endpoint.Port"
]
}
]
]
}
}
When authoring the template from scratch, you can take advantage of the AWS Application Composer – an integrated development environment for authoring and validating code. Once the template is ready, you can launch the resources by creating a stack (collection of resources) or using the AWS CloudFormation console, API, or AWS CLI. You can also update or delete the template afterward.