database resize

The database resize command moves a deployed relational database to the instanceSize in your config with a pause of seconds, without deploying anything else. It also continues a resize that a deploy or an earlier run left unfinished. Changing the instance size explains both ways a size can change, the measured pauses and what is kept afterwards.

Usage

stacktape database resize [<database>] --stage <stage> --region <region>
stacktape database resize [<database>] --stage <stage> --region <region> --status
stacktape database resize [<database>] --stage <stage> --region <region> --finish

Without a database name, the command covers every relational database in the config.

For each database, the command compares the size in the config with the deployed one. When they differ and the database can take it, the command resizes it:

  • Aurora: a temporary instance serves writes while the original changes size. Writes pause for a few seconds twice.
  • RDS for PostgreSQL, MySQL and MariaDB: AWS builds a copy on the new size and switches to it. Writes pause once for a few seconds. The previous instance is kept for 24 hours.

When the short pause is not possible, the command says why and changes nothing. A deploy with --database-resize plain then resizes the database the plain way, with about two minutes without connections.

The command reads sizes from the config. When the config has overrides for the database or a final transform, the template can hold another size, so the command refuses and a deploy does the resize instead.

The command takes the same stack lock as a deploy, so the two never change a stack at the same time. On a stage that is not known to be non-production it asks for confirmation; --yes confirms it. With --agent, --yes is required there.

After the resize, the stack's template still names the old size. The next stacktape deploy records the new one and does not touch the database.

Stopping and continuing

The command can be stopped at any point and run again. It reads from AWS what is already done and continues from there. A run by you starts with fresh attempts, so a switch that gave up after its last tries is tried again once the cause is fixed. To undo an unfinished resize, set the size back in the config and run the command again.

--status

Shows which resize is in progress and which previous instance is kept until when. It changes nothing.

--finish

Continues a resize that stopped in the middle to the sizes it was started for, without reading the config. When the database of such a resize no longer exists in AWS, it removes the record of that resize instead. Then it deletes the instance an RDS database ran on before its resize, and the CloudWatch log groups RDS created for it and for the copy the resize made. AWS keeps the deleted instance's automated backups for its backup retention (automatedBackupRetentionDays), so a restore to a time before the resize remains possible until then. Deleting the stage deletes them too. Before 24 hours have passed since the resize, the command asks first. Without --finish, the instance bills until the first deploy after the 24 hours deletes it.

Permissions

With credentials from the Stacktape Console nothing needs to be set up. With your own restricted AWS credentials, the resize needs these RDS actions in addition to what a deploy needs:

  • Aurora: rds:CreateDBInstance, rds:ModifyDBInstance, rds:ModifyDBCluster, rds:FailoverDBCluster, rds:DeleteDBInstance, rds:AddTagsToResource.
  • RDS: rds:CreateBlueGreenDeployment, rds:CreateDBInstanceReadReplica, rds:SwitchoverBlueGreenDeployment, rds:PromoteReadReplica, rds:DeleteBlueGreenDeployment, rds:ModifyDBInstance, rds:DeleteDBInstance, rds:AddTagsToResource, and logs:DescribeLogGroups and logs:DeleteLogGroup for the log groups of the deleted instance. Without the last two, those log groups stay and the command says so.
  • Both: the rds:Describe* actions, including rds:DescribeDBProxies and rds:DescribeDBProxyTargets, and cloudwatch:GetMetricData.

When an action is refused, the command stops before it has created anything and names the action.

Flags reference

stacktape database resize <resource-name>CLI options
-r, --regionrequired"us-east-2" | "us-east-1" | "us-west-1" | "us-west-2" | "ap-east-1" | "ap-south-1" | "ap-northeast-3" | "ap-northeast-2" | "ap-southeast-1" | "ap-southeast-2" | "ap-northeast-1" | "ca-central-1" | "eu-central-1" | "eu-west-1" | "eu-west-2" | "eu-west-3" | "eu-north-1" | "me-south-1" | "sa-east-1" | "af-south-1" | "eu-south-1"

AWS Region

The AWS region for the operation. For a list of available regions, see the AWS documentation.

For commands such as deploy, this flag overrides the project's configured region. If you omit it, Stacktape checks the project's config, AWS_DEFAULT_REGION, the default saved with defaults set, then the AWS profile.

-s, --stagerequiredstring

Stage

The stage for the operation (e.g., production, staging, dev-john). You can set a default stage using the defaults set command. Stage names use lowercase letters, numbers and dashes, with at least 2 characters. The project name, a dash and the stage form the CloudFormation stack name, which can have at most 128 characters. Stacktape shortens an AWS resource name that would be too long and adds a hash.

-y, --yesboolean

Auto-Confirm Operation

Confirms an operation that would otherwise ask first: deleting a stack, an update that may delete stateful resources, creating a project that does not exist yet, and the other deletions that ask. Without a terminal to ask in (CI, --agent, machine-readable output), such an operation fails with CONFIRMATION_REQUIRED unless this flag is set. --agent does not confirm anything.

--aws-accountstring

AWS Account

The name of the AWS account to use for the operation. The account must first be connected in the Stacktape Console.

Without it, the account is chosen by --profile, AWS_PROFILE or AWS credentials in environment variables, then by your saved default, then by your organization's only connected account. --aws-account takes precedence over all of them, but AWS credentials in environment variables must then belong to that account.

-c, --configstring

Config File Path

The path to your Stacktape configuration file, relative to the current working directory. Without it, Stacktape uses the one stacktape.ts, stacktape.yml, stacktape.yaml or stacktape.js in the working directory. When there are several, the command stops and asks you to choose one with this option.

--cwdstring

Current Working Directory

The working directory for the operation. All file paths in your configuration will be resolved relative to this directory. By default, this is the directory containing the configuration file.

--finishboolean

Finish

Finishes a resize that stopped before its end, to the sizes it was started for (or removes its record when the database no longer exists in AWS), and deletes the instance a database ran on before its resize, which is kept after an RDS resize. Its automated backups stay. Before 24 hours have passed since the resize, the command asks first.

-h, --helpstring

Show Help

If provided, the command will not execute and will instead print help information.

--log-level"info" | "debug" | "error"

Log Level

The level of logs to print to the console.

  • info: Basic information about the operation.
  • error: Only errors.
  • debug: Detailed information for debugging.
-p, --profilestring

AWS Profile

The AWS profile to use for the command. You can manage profiles using the aws-profile:* commands and set a default profile with defaults set.

For commands that use a connected AWS account, --profile (or AWS_PROFILE) selects the connected account the profile belongs to, unless --aws-account is set. The command fails if that account is not connected.

--projectstring

Project Name

The name of the Stacktape project for this operation.

Commands that target a stack take it from projectName in the project's config when the flag is absent.

--quietboolean

Quiet

Hide progress, banners, success messages and hints. Command output, warnings and errors are still printed.

--resource-name (positional 1)string

Resource Name

The name of the resource as defined in your Stacktape configuration.

--statusboolean

Status

Shows which resize is in progress and which previous instance is kept until when. Changes nothing.

Examples

stacktape database resize mainDatabase --stage production --region eu-west-1
stacktape database resize --stage production --region eu-west-1 --status
stacktape database resize mainDatabase --stage production --region eu-west-1 --finish --yes