AWS services or capabilities described in AWS Documentation may vary by region/location. Click Getting Started with Amazon AWS to see specific differences applicable to the China (Beijing) Region.

Class: Aws::RailsProvisioner::DBCluster

Inherits:
Object
  • Object
show all
Defined in:
lib/aws-rails-provisioner/db_cluster.rb

Defined Under Namespace

Classes: BackUp, ParameterGroup

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ DBCluster

Configuration value under :db_cluster

Parameters:

  • options (Hash) (defaults to: {})
  • oprions (Hash)

    a customizable set of options

Options Hash (options):

  • :username (String)

    DB username, default to `SERVICE_NAMEDBAdminUser`

  • :engine (required, String)

    provide the engine for the database cluster: `aurora`, `aurora-mysql` or `aurora-postgresql`

  • :engine_version (String)

    version of the database to start, when not provided, default for the engine is used.

  • :instance_type (String)

    type of instance to start for the replicas, if not provided, a default :instance_type will be populated responding to the type of engine provided.

  • :instance_subnet (String)

    where to place the instances within the VPC, default to `isolated` subnet (recommend)

  • :backup (Hash)

    backup config for DB databases

    @example: at `aws-rails-provisioner.yml`

    backup:
      retention_days: 7
      preferred_window: '01:00-02:00'
    

    @see BackUp

  • :cluster_identifier (String)

    An optional identifier for the cluster, If not supplied, a name is automatically generated

  • :db_name (required, String)

    name for the DB inside the cluster

  • :removal_policy (String)

    policy to apply when the cluster and its instances are removed from the stack or replaced during an update. `retain`, `destroy` available, default to `retain`

  • :instance_identifier (String)

    every replica is named by appending the replica number to this string, default to 'Instance'

  • :instances (Integer)

    how many replicas/instances to create, defaults to 2

  • :port (Integer)

    if not provided, default value is based on :engine

  • :kms_key_arn (String)

    the he KMS key arn for storage encryption

  • :preferred_maintenance_window (String)

    daily time range in 24-hours UTC format in which backups preferably execute

See Also:

  • CDK DatabaseClusterProps


69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/aws-rails-provisioner/db_cluster.rb', line 69

def initialize(options = {})
  @username = options[:username] || 'DBAdminUser'

  @engine = _engine_type(options[:engine])
  @engine_version = options[:engine_version]
  @postgres = @engine == 'AURORA_POSTGRESQL'
  unless @postgres
    # MySql require username between 1 to 16
    @username = options[:username][0..15]
  end

  @instance_type = options[:instance_type] || _default_instance_type
  @instance_subnet = Aws::RailsProvisioner::Utils.subnet_type(
    options[:instance_subnet] || 'isolated')

  @backup = BackUp.new(options[:backup]) if options[:backup]
  @db_name = options.fetch(:db_name)
  @cluster_identifier = options[:cluster_identifier]
  @removal_policy = Aws::RailsProvisioner::Utils.removal_policy(
    options[:removal_policy] || 'retain')

  @instance_identifier = options[:instance_identifier]
  @instances = options[:instances] || 2

  @kms_key = options[:kms_key_arn]

  @port = options[:port]
  @preferred_maintenance_window = options[:preferred_maintenance_window]

  pg_opts = options[:parameter_group] || {}
  pg_opts[:profile] = options[:profile] if options[:profile]
  pg_opts[:stub_client] = options[:stub_client] # test only
  @parameter_group = ParameterGroup.new(@engine, pg_opts)
  @db_port = @port || _default_db_port
end

Instance Attribute Details

#backupBackUp (readonly)

Returns:



151
152
153
# File 'lib/aws-rails-provisioner/db_cluster.rb', line 151

def backup
  @backup
end

#cluster_identifierString (readonly)

Returns:

  • (String)


133
134
135
# File 'lib/aws-rails-provisioner/db_cluster.rb', line 133

def cluster_identifier
  @cluster_identifier
end

#db_nameString (readonly)

Returns:

  • (String)


130
131
132
# File 'lib/aws-rails-provisioner/db_cluster.rb', line 130

def db_name
  @db_name
end

#db_portInteger (readonly)

Returns:

  • (Integer)


154
155
156
# File 'lib/aws-rails-provisioner/db_cluster.rb', line 154

def db_port
  @db_port
end

#engineString (readonly)

Returns:

  • (String)


112
113
114
# File 'lib/aws-rails-provisioner/db_cluster.rb', line 112

def engine
  @engine
end

#engine_versionString (readonly)

Returns:

  • (String)


115
116
117
# File 'lib/aws-rails-provisioner/db_cluster.rb', line 115

def engine_version
  @engine_version
end

#instance_identifierString (readonly)

Returns:

  • (String)


124
125
126
# File 'lib/aws-rails-provisioner/db_cluster.rb', line 124

def instance_identifier
  @instance_identifier
end

#instance_subnetString (readonly)

Returns:

  • (String)


121
122
123
# File 'lib/aws-rails-provisioner/db_cluster.rb', line 121

def instance_subnet
  @instance_subnet
end

#instance_typeString (readonly)

Returns:

  • (String)


118
119
120
# File 'lib/aws-rails-provisioner/db_cluster.rb', line 118

def instance_type
  @instance_type
end

#instancesInteger (readonly)

Returns:

  • (Integer)


127
128
129
# File 'lib/aws-rails-provisioner/db_cluster.rb', line 127

def instances
  @instances
end

#kms_keyString (readonly)

Returns:

  • (String)


139
140
141
# File 'lib/aws-rails-provisioner/db_cluster.rb', line 139

def kms_key
  @kms_key
end

#parameter_groupParameterGroup (readonly)

Returns:



148
149
150
# File 'lib/aws-rails-provisioner/db_cluster.rb', line 148

def parameter_group
  @parameter_group
end

#portInteger (readonly)

Returns:

  • (Integer)


142
143
144
# File 'lib/aws-rails-provisioner/db_cluster.rb', line 142

def port
  @port
end

#postgresBoolean (readonly)

Returns:

  • (Boolean)


106
107
108
# File 'lib/aws-rails-provisioner/db_cluster.rb', line 106

def postgres
  @postgres
end

#preferred_maintenance_windowString (readonly)

Returns:

  • (String)


145
146
147
# File 'lib/aws-rails-provisioner/db_cluster.rb', line 145

def preferred_maintenance_window
  @preferred_maintenance_window
end

#removal_policyString (readonly)

Returns:

  • (String)


136
137
138
# File 'lib/aws-rails-provisioner/db_cluster.rb', line 136

def removal_policy
  @removal_policy
end

#usernameString (readonly)

Returns:

  • (String)


109
110
111
# File 'lib/aws-rails-provisioner/db_cluster.rb', line 109

def username
  @username
end