Skip to content

create_relational_database

create_relational_database(
    relational_database_name: ResourceName,
    relational_database_blueprint_id: string,
    relational_database_bundle_id: string,
    master_database_name: string,
    master_username: string,
    *,
    config_overrides: Optional[LightsailClientConfig] = None,
    availability_zone: Optional[string] = None,
    master_user_password: Optional[SensitiveString] = None,
    preferred_backup_window: Optional[string] = None,
    preferred_maintenance_window: Optional[string] = None,
    publicly_accessible: Optional[boolean] = None,
    tags: Optional[TagList] = None,
) -> CreateRelationalDatabaseResult

Creates a new database in Amazon Lightsail.

The create relational database operation supports tag-based access control via request tags. For more information, see the Amazon Lightsail Developer Guide.

Parameters:

  • relational_database_name (ResourceName) –

    The name to use for your new Lightsail database resource.

    Constraints:

    • Must contain from 2 to 255 alphanumeric characters, or hyphens.

    • The first and last character must be a letter or number.

  • availability_zone (Optional[string], default: None ) –

    The Availability Zone in which to create your new database. Use the us-east-2a case-sensitive format.

    You can get a list of Availability Zones by using the get regions operation. Be sure to add the include relational database Availability Zones parameter to your request.

  • relational_database_blueprint_id (string) –

    The blueprint ID for your new database. A blueprint describes the major engine version of a database.

    You can get a list of database blueprints IDs by using the get relational database blueprints operation.

  • relational_database_bundle_id (string) –

    The bundle ID for your new database. A bundle describes the performance specifications for your database.

    You can get a list of database bundle IDs by using the get relational database bundles operation.

  • master_database_name (string) –

    The meaning of this parameter differs according to the database engine you use.

    MySQL

    The name of the database to create when the Lightsail database resource is created. If this parameter isn't specified, no database is created in the database resource.

    Constraints:

    • Must contain 1 to 64 letters or numbers.

    • Must begin with a letter. Subsequent characters can be letters, underscores, or digits (0- 9).

    • Can't be a word reserved by the specified database engine.

      For more information about reserved words in MySQL, see the Keywords and Reserved Words articles for MySQL 5.6, MySQL 5.7, and MySQL 8.0.

    PostgreSQL

    The name of the database to create when the Lightsail database resource is created. If this parameter isn't specified, a database named postgres is created in the database resource.

    Constraints:

    • Must contain 1 to 63 letters or numbers.

    • Must begin with a letter. Subsequent characters can be letters, underscores, or digits (0- 9).

    • Can't be a word reserved by the specified database engine.

      For more information about reserved words in PostgreSQL, see the SQL Key Words articles for PostgreSQL 9.6, PostgreSQL 10, PostgreSQL 11, and PostgreSQL 12.

  • master_username (string) –

    The name for the master user.

    MySQL

    Constraints:

    • Required for MySQL.

    • Must be 1 to 16 letters or numbers. Can contain underscores.

    • First character must be a letter.

    • Can't be a reserved word for the chosen database engine.

      For more information about reserved words in MySQL 5.6 or 5.7, see the Keywords and Reserved Words articles for MySQL 5.6, MySQL 5.7, or MySQL 8.0.

    PostgreSQL

    Constraints:

    • Required for PostgreSQL.

    • Must be 1 to 63 letters or numbers. Can contain underscores.

    • First character must be a letter.

    • Can't be a reserved word for the chosen database engine.

      For more information about reserved words in MySQL 5.6 or 5.7, see the Keywords and Reserved Words articles for PostgreSQL 9.6, PostgreSQL 10, PostgreSQL 11, and PostgreSQL 12.

  • master_user_password (Optional[SensitiveString], default: None ) –

    The password for the master user. The password can include any printable ASCII character except "/", """, or "@". It cannot contain spaces.

    MySQL

    Constraints: Must contain from 8 to 41 characters.

    PostgreSQL

    Constraints: Must contain from 8 to 128 characters.

  • preferred_backup_window (Optional[string], default: None ) –

    The daily time range during which automated backups are created for your new database if automated backups are enabled.

    The default is a 30-minute window selected at random from an 8-hour block of time for each AWS Region. For more information about the preferred backup window time blocks for each region, see the Working With Backups guide in the Amazon Relational Database Service documentation.

    Constraints:

    • Must be in the hh24:mi-hh24:mi format.

      Example: 16:00-16:30

    • Specified in Coordinated Universal Time (UTC).

    • Must not conflict with the preferred maintenance window.

    • Must be at least 30 minutes.

  • preferred_maintenance_window (Optional[string], default: None ) –

    The weekly time range during which system maintenance can occur on your new database.

    The default is a 30-minute window selected at random from an 8-hour block of time for each AWS Region, occurring on a random day of the week.

    Constraints:

    • Must be in the ddd:hh24:mi-ddd:hh24:mi format.

    • Valid days: Mon, Tue, Wed, Thu, Fri, Sat, Sun.

    • Must be at least 30 minutes.

    • Specified in Coordinated Universal Time (UTC).

    • Example: Tue:17:00-Tue:17:30

  • publicly_accessible (Optional[boolean], default: None ) –

    Specifies the accessibility options for your new database. A value of true specifies a database that is available to resources outside of your Lightsail account. A value of false specifies a database that is available only to your Lightsail resources in the same region as your database.

  • tags (Optional[TagList], default: None ) –

    The tag keys and optional values to add to the resource during create.

    Use the TagResource action to tag a resource after it's created.

Raises:

  • AccessDeniedException –

    Lightsail throws this exception when the user cannot be authenticated or uses invalid credentials to access a resource.

  • AccountSetupInProgressException –

    Lightsail throws this exception when an account is still in the setup in progress state.

  • InvalidInputException –

    Lightsail throws this exception when user input does not conform to the validation rules of an input field.

    Domain and distribution APIs are only available in the N. Virginia (us-east-1) Amazon Web Services Region. Please set your Amazon Web Services Region configuration to us-east-1 to create, view, or edit these resources.

  • NotFoundException –

    Lightsail throws this exception when it cannot find a resource.

  • OperationFailureException –

    Lightsail throws this exception when an operation fails to execute.

  • RegionSetupInProgressException –

    Lightsail throws this exception when an operation is performed on resources in an opt-in Region that is currently being set up.

  • ServiceException –

    A general service exception.

  • UnauthenticatedException –

    Lightsail throws this exception when the user has not been authenticated.

  • UnknownServiceError –

    The service returned an error code this client does not model.

Source code in docs_src/capo_lightsail/_services/lightsail.py
def create_relational_database(
    self,
    relational_database_name: "capo_lightsail.types.resource_name.ResourceName",
    relational_database_blueprint_id: "capo_lightsail.types.string.string",
    relational_database_bundle_id: "capo_lightsail.types.string.string",
    master_database_name: "capo_lightsail.types.string.string",
    master_username: "capo_lightsail.types.string.string",
    *,
    config_overrides: Optional[LightsailClientConfig] = None,
    availability_zone: Optional["capo_lightsail.types.string.string"] = None,
    master_user_password: Optional[
        "capo_lightsail.types.sensitive_string.SensitiveString"
    ] = None,
    preferred_backup_window: Optional["capo_lightsail.types.string.string"] = None,
    preferred_maintenance_window: Optional[
        "capo_lightsail.types.string.string"
    ] = None,
    publicly_accessible: Optional["capo_lightsail.types.boolean.boolean"] = None,
    tags: Optional["capo_lightsail.types.tag_list.TagList"] = None,
) -> "capo_lightsail.types.create_relational_database_result.CreateRelationalDatabaseResult":
    """<p>Creates a new database in Amazon Lightsail.</p> <p>The <code>create relational database</code> operation supports tag-based access control via request tags. For more information, see the <a href=\"https://docs.aws.amazon.com/lightsail/latest/userguide/amazon-lightsail-controlling-access-using-tags\">Amazon Lightsail Developer Guide</a>.</p>

    Args:
        relational_database_name: <p>The name to use for your new Lightsail database resource.</p> <p>Constraints:</p> <ul> <li> <p>Must contain from 2 to 255 alphanumeric characters, or hyphens.</p> </li> <li> <p>The first and last character must be a letter or number.</p> </li> </ul>
        availability_zone: <p>The Availability Zone in which to create your new database. Use the <code>us-east-2a</code> case-sensitive format.</p> <p>You can get a list of Availability Zones by using the <code>get regions</code> operation. Be sure to add the <code>include relational database Availability Zones</code> parameter to your request.</p>
        relational_database_blueprint_id: <p>The blueprint ID for your new database. A blueprint describes the major engine version of a database.</p> <p>You can get a list of database blueprints IDs by using the <code>get relational database blueprints</code> operation.</p>
        relational_database_bundle_id: <p>The bundle ID for your new database. A bundle describes the performance specifications for your database.</p> <p>You can get a list of database bundle IDs by using the <code>get relational database bundles</code> operation.</p>
        master_database_name: <p>The meaning of this parameter differs according to the database engine you use.</p> <p> <b>MySQL</b> </p> <p>The name of the database to create when the Lightsail database resource is created. If this parameter isn't specified, no database is created in the database resource.</p> <p>Constraints:</p> <ul> <li> <p>Must contain 1 to 64 letters or numbers.</p> </li> <li> <p>Must begin with a letter. Subsequent characters can be letters, underscores, or digits (0- 9).</p> </li> <li> <p>Can't be a word reserved by the specified database engine.</p> <p>For more information about reserved words in MySQL, see the Keywords and Reserved Words articles for <a href=\"https://dev.mysql.com/doc/refman/5.6/en/keywords.html\">MySQL 5.6</a>, <a href=\"https://dev.mysql.com/doc/refman/5.7/en/keywords.html\">MySQL 5.7</a>, and <a href=\"https://dev.mysql.com/doc/refman/8.0/en/keywords.html\">MySQL 8.0</a>.</p> </li> </ul> <p> <b>PostgreSQL</b> </p> <p>The name of the database to create when the Lightsail database resource is created. If this parameter isn't specified, a database named <code>postgres</code> is created in the database resource.</p> <p>Constraints:</p> <ul> <li> <p>Must contain 1 to 63 letters or numbers.</p> </li> <li> <p>Must begin with a letter. Subsequent characters can be letters, underscores, or digits (0- 9).</p> </li> <li> <p>Can't be a word reserved by the specified database engine.</p> <p>For more information about reserved words in PostgreSQL, see the SQL Key Words articles for <a href=\"https://www.postgresql.org/docs/9.6/sql-keywords-appendix.html\">PostgreSQL 9.6</a>, <a href=\"https://www.postgresql.org/docs/10/sql-keywords-appendix.html\">PostgreSQL 10</a>, <a href=\"https://www.postgresql.org/docs/11/sql-keywords-appendix.html\">PostgreSQL 11</a>, and <a href=\"https://www.postgresql.org/docs/12/sql-keywords-appendix.html\">PostgreSQL 12</a>.</p> </li> </ul>
        master_username: <p>The name for the master user.</p> <p> <b>MySQL</b> </p> <p>Constraints:</p> <ul> <li> <p>Required for MySQL.</p> </li> <li> <p>Must be 1 to 16 letters or numbers. Can contain underscores.</p> </li> <li> <p>First character must be a letter.</p> </li> <li> <p>Can't be a reserved word for the chosen database engine.</p> <p>For more information about reserved words in MySQL 5.6 or 5.7, see the Keywords and Reserved Words articles for <a href=\"https://dev.mysql.com/doc/refman/5.6/en/keywords.html\">MySQL 5.6</a>, <a href=\"https://dev.mysql.com/doc/refman/5.7/en/keywords.html\">MySQL 5.7</a>, or <a href=\"https://dev.mysql.com/doc/refman/8.0/en/keywords.html\">MySQL 8.0</a>.</p> </li> </ul> <p> <b>PostgreSQL</b> </p> <p>Constraints:</p> <ul> <li> <p>Required for PostgreSQL.</p> </li> <li> <p>Must be 1 to 63 letters or numbers. Can contain underscores.</p> </li> <li> <p>First character must be a letter.</p> </li> <li> <p>Can't be a reserved word for the chosen database engine.</p> <p>For more information about reserved words in MySQL 5.6 or 5.7, see the Keywords and Reserved Words articles for <a href=\"https://www.postgresql.org/docs/9.6/sql-keywords-appendix.html\">PostgreSQL 9.6</a>, <a href=\"https://www.postgresql.org/docs/10/sql-keywords-appendix.html\">PostgreSQL 10</a>, <a href=\"https://www.postgresql.org/docs/11/sql-keywords-appendix.html\">PostgreSQL 11</a>, and <a href=\"https://www.postgresql.org/docs/12/sql-keywords-appendix.html\">PostgreSQL 12</a>.</p> </li> </ul>
        master_user_password: <p>The password for the master user. The password can include any printable ASCII character except \"/\", \"\"\", or \"@\". It cannot contain spaces.</p> <p> <b>MySQL</b> </p> <p>Constraints: Must contain from 8 to 41 characters.</p> <p> <b>PostgreSQL</b> </p> <p>Constraints: Must contain from 8 to 128 characters.</p>
        preferred_backup_window: <p>The daily time range during which automated backups are created for your new database if automated backups are enabled.</p> <p>The default is a 30-minute window selected at random from an 8-hour block of time for each AWS Region. For more information about the preferred backup window time blocks for each region, see the <a href=\"https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_WorkingWithAutomatedBackups.html#USER_WorkingWithAutomatedBackups.BackupWindow\">Working With Backups</a> guide in the Amazon Relational Database Service documentation.</p> <p>Constraints:</p> <ul> <li> <p>Must be in the <code>hh24:mi-hh24:mi</code> format.</p> <p>Example: <code>16:00-16:30</code> </p> </li> <li> <p>Specified in Coordinated Universal Time (UTC).</p> </li> <li> <p>Must not conflict with the preferred maintenance window.</p> </li> <li> <p>Must be at least 30 minutes.</p> </li> </ul>
        preferred_maintenance_window: <p>The weekly time range during which system maintenance can occur on your new database.</p> <p>The default is a 30-minute window selected at random from an 8-hour block of time for each AWS Region, occurring on a random day of the week.</p> <p>Constraints:</p> <ul> <li> <p>Must be in the <code>ddd:hh24:mi-ddd:hh24:mi</code> format.</p> </li> <li> <p>Valid days: Mon, Tue, Wed, Thu, Fri, Sat, Sun.</p> </li> <li> <p>Must be at least 30 minutes.</p> </li> <li> <p>Specified in Coordinated Universal Time (UTC).</p> </li> <li> <p>Example: <code>Tue:17:00-Tue:17:30</code> </p> </li> </ul>
        publicly_accessible: <p>Specifies the accessibility options for your new database. A value of <code>true</code> specifies a database that is available to resources outside of your Lightsail account. A value of <code>false</code> specifies a database that is available only to your Lightsail resources in the same region as your database.</p>
        tags: <p>The tag keys and optional values to add to the resource during create.</p> <p>Use the <code>TagResource</code> action to tag a resource after it's created.</p>

    Raises:
        capo_lightsail.errors.access_denied_exception.AccessDeniedException: <p>Lightsail throws this exception when the user cannot be authenticated or uses invalid credentials to access a resource.</p>
        capo_lightsail.errors.account_setup_in_progress_exception.AccountSetupInProgressException: <p>Lightsail throws this exception when an account is still in the setup in progress state.</p>
        capo_lightsail.errors.invalid_input_exception.InvalidInputException: <p>Lightsail throws this exception when user input does not conform to the validation rules of an input field.</p> <note> <p>Domain and distribution APIs are only available in the N. Virginia (<code>us-east-1</code>) Amazon Web Services Region. Please set your Amazon Web Services Region configuration to <code>us-east-1</code> to create, view, or edit these resources.</p> </note>
        capo_lightsail.errors.not_found_exception.NotFoundException: <p>Lightsail throws this exception when it cannot find a resource.</p>
        capo_lightsail.errors.operation_failure_exception.OperationFailureException: <p>Lightsail throws this exception when an operation fails to execute.</p>
        capo_lightsail.errors.region_setup_in_progress_exception.RegionSetupInProgressException: <p>Lightsail throws this exception when an operation is performed on resources in an opt-in Region that is currently being set up.</p>
        capo_lightsail.errors.service_exception.ServiceException: <p>A general service exception.</p>
        capo_lightsail.errors.unauthenticated_exception.UnauthenticatedException: <p>Lightsail throws this exception when the user has not been authenticated.</p>
        capo_lightsail.errors.UnknownServiceError: The service returned an error code this client does not model.
    """

    def _handler(
        req: "OperationRequest[capo_lightsail.types.create_relational_database_request.CreateRelationalDatabaseRequest]",
    ) -> OperationResponse[
        "capo_lightsail.types.create_relational_database_result.CreateRelationalDatabaseResult"
    ]:
        import capo_lightsail._operations.lightsail_20161128.create_relational_database

        output, http_response = (
            capo_lightsail._operations.lightsail_20161128.create_relational_database.create_relational_database(
                req.options, req.input
            )
        )
        return OperationResponse(output=output, response=http_response)

    def _redact_input(
        input_: "capo_lightsail.types.create_relational_database_request.CreateRelationalDatabaseRequest",
    ) -> dict[str, Any]:
        import capo_lightsail.types.create_relational_database_request

        return capo_lightsail.types.create_relational_database_request.redact_sensitive(
            input_
        )

    interceptors_, options_ = self.operation_options(
        config_overrides,
        OperationLogging("CreateRelationalDatabase", redact_input=_redact_input),
    )
    input_: capo_lightsail.types.create_relational_database_request.CreateRelationalDatabaseRequest = {
        "relational_database_name": relational_database_name,
        "relational_database_blueprint_id": relational_database_blueprint_id,
        "relational_database_bundle_id": relational_database_bundle_id,
        "master_database_name": master_database_name,
        "master_username": master_username,
    }
    if availability_zone is not None:
        input_["availability_zone"] = availability_zone
    if master_user_password is not None:
        input_["master_user_password"] = master_user_password
    if preferred_backup_window is not None:
        input_["preferred_backup_window"] = preferred_backup_window
    if preferred_maintenance_window is not None:
        input_["preferred_maintenance_window"] = preferred_maintenance_window
    if publicly_accessible is not None:
        input_["publicly_accessible"] = publicly_accessible
    if tags is not None:
        input_["tags"] = tags

    response = execute_pipeline(
        OperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    response.response.close()
    return response.output