├── LICENSE ├── README.md ├── cloudformation-restore-sqlserver.yaml ├── cloudformation-sqlserver-master-database.yaml └── shell-script-samples ├── create-alerts.sh ├── create-database-instance.sh ├── create-manual-snapshot.sh ├── delete-alerts.sh ├── modify-database-instance.sh └── restore-to-pointintime.sh /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Code samples 2 | ## Part 2 - Role of the DBA when moving to RDS: Automation 3 | An important aspect of being an effective DBA when your business is running at top speed is leveraging code and automation whenever you can. 4 | Use the examples in this blog to help jumpstart your automation efforts. 5 | 6 | ## Main Files 7 | Cloud formation template that will create a simple, base SQL Server RDS database open to 0.0.0.0/0. 8 | Strongly advise that you modify the CIDR range for your environment. 9 | 10 | cloudformation-sqlserver-master-database.yaml 11 | 12 | Cloud formation script to restore your SQL Server snapshot with several CloudWatch alarms enabled. 13 | 14 | You can deploy the stack from the AWS console or from the AWS CLI with a parameter file. 15 | For more information on AWS CLI deployments: http://docs.aws.amazon.com/cli/latest/reference/cloudformation/ 16 | 17 | cloudformation-restore-sqlserver.yaml 18 | 19 | ### Bash shell script samples 20 | Bash script demonstrating creation of various AWS/RDS CloudWatch alarms on an existing database. 21 | 22 | create-alerts.sh 23 | 24 | Bash script demonstrating database creation with the AWS CLI 25 | 26 | create-database-instance.sh 27 | 28 | Bash script initiating a manual Amazon RDS snapshot 29 | 30 | create-manual-snapshot.sh 31 | 32 | Bash script removing existing CloudWatch alarms 33 | 34 | delete-alerts.sh 35 | 36 | Bash script demonstrating how to modify a database instance size, parameter group, and option group. Script assumes that the parameter group and the option group already exist. 37 | 38 | modify-database-instance.sh 39 | 40 | Bash script to restore a database to a point in time. Check your latest restore time for your instance and update the script accordingly. 41 | 42 | restore-to-pointintime.sh 43 | 44 | -------------------------------------------------------------------------------- /cloudformation-restore-sqlserver.yaml: -------------------------------------------------------------------------------- 1 | AWSTemplateFormatVersion: 2010-09-09 2 | Description: CloudFormation template for Restoring RDS database from snapshot. 3 | Parameters: 4 | DatabaseInstanceType: 5 | Default: db.r3.large 6 | AllowedValues: 7 | - db.m4.large 8 | - db.m4.xlarge 9 | - db.m4.2xlarge 10 | - db.r3.large 11 | - db.r3.xlarge 12 | - db.r3.2xlarge 13 | Description: The instance type to use for this test iteration. 14 | Type: String 15 | DatabaseSecurityGroups: 16 | Type: List 17 | Description: Security group in your VPC with ingress to your database port. 18 | DatabaseSnapshotIdentifier: 19 | Description: The name or id of the master snapshot to restore for the test cycle 20 | Type: String 21 | DatabaseMonitoringRole: 22 | Description: The ARN of the monitoring role to use for enhanced monitoring 23 | Type: String 24 | DatabaseParameterGroup: 25 | Description: The name of the parameter group to use for this test cycle 26 | Type: String 27 | DatabaseOptionGroup: 28 | Description: The name of the option group to use for Native Backup process 29 | Type: String 30 | DatabaseSNSNotification: 31 | Description: The ARN of Amazon Simple Notification Service (Amazon SNS) topic 32 | Type: String 33 | Metadata: 34 | AWS::CloudFormation::Interface: 35 | ParameterGroups: 36 | - Label: 37 | default: Account and VPC values, same for each test in the account 38 | Parameters: 39 | - DatabaseSecurityGroups 40 | - DatabaseSnapshotIdentifier 41 | - DatabaseMonitoringRole 42 | - DatabaseSNSNotification 43 | - Label: 44 | default: Unit test values, modified per test cycle 45 | Parameters: 46 | - DatabaseInstanceType 47 | - DatabaseParameterGroup 48 | - DatabaseOptionGroup 49 | ParameterLabels: 50 | DatabaseSecurityGroups: 51 | default: Security group 52 | DatabaseSnapshotIdentifier: 53 | default: Snapshot to restore 54 | DatabaseMonitoringRole: 55 | default: CloudWatch monitoring role 56 | DatabaseInstanceType: 57 | default: RDS instance type 58 | DatabaseParameterGroup: 59 | default: RDS parameter group 60 | DatabaseOptionGroup: 61 | default: RDS option group 62 | DatabaseSNSNotification: 63 | default: Amazon SNS topic 64 | Resources: 65 | SQLDatabase: 66 | Type: "AWS::RDS::DBInstance" 67 | Properties: 68 | AutoMinorVersionUpgrade: false 69 | BackupRetentionPeriod: 1 70 | CharacterSetName: String 71 | DBInstanceClass: 72 | Ref: DatabaseInstanceType 73 | DBSnapshotIdentifier: 74 | Ref: DatabaseSnapshotIdentifier 75 | DBSubnetGroupName: "default" 76 | MonitoringInterval: 5 77 | MonitoringRoleArn: 78 | Ref: DatabaseMonitoringRole 79 | MultiAZ: true 80 | DBParameterGroupName: 81 | Ref: DatabaseParameterGroup 82 | OptionGroupName: 83 | Ref: DatabaseOptionGroup 84 | PubliclyAccessible: true 85 | Tags: 86 | - 87 | Key: "Name" 88 | Value: "sqlunittest" 89 | - 90 | Key: "project" 91 | Value: "development unittest" 92 | VPCSecurityGroups: 93 | Ref: DatabaseSecurityGroups 94 | WritethroughputAlarm: 95 | Type: "AWS::CloudWatch::Alarm" 96 | Properties: 97 | ActionsEnabled: true 98 | AlarmActions: 99 | - Ref: DatabaseSNSNotification 100 | AlarmDescription: "Write-throughput" 101 | ComparisonOperator: "GreaterThanOrEqualToThreshold" 102 | Dimensions: 103 | - Name: DBInstanceIdentifier 104 | Value: 105 | Ref: SQLDatabase 106 | EvaluationPeriods: 1 107 | MetricName: "Writethroughputs" 108 | Namespace: "AWS/RDS" 109 | Period: 300 110 | Statistic: Maximum 111 | Threshold: 1.0 112 | TreatMissingData: "notBreaching" 113 | ReadLatencyAlarm: 114 | Type: "AWS::CloudWatch::Alarm" 115 | Properties: 116 | ActionsEnabled: true 117 | AlarmActions: 118 | - Ref: DatabaseSNSNotification 119 | AlarmDescription: "Read-latency" 120 | ComparisonOperator: "GreaterThanOrEqualToThreshold" 121 | Dimensions: 122 | - Name: DBInstanceIdentifier 123 | Value: 124 | Ref: SQLDatabase 125 | EvaluationPeriods: 2 126 | MetricName: "ReadLatency" 127 | Namespace: "AWS/RDS" 128 | Period: 300 129 | Statistic: Maximum 130 | Threshold: 1.0 131 | TreatMissingData: "notBreaching" 132 | WriteLatencyAlarm: 133 | Type: "AWS::CloudWatch::Alarm" 134 | Properties: 135 | ActionsEnabled: true 136 | AlarmActions: 137 | - Ref: DatabaseSNSNotification 138 | AlarmDescription: "Write-latency" 139 | ComparisonOperator: "GreaterThanOrEqualToThreshold" 140 | Dimensions: 141 | - Name: DBInstanceIdentifier 142 | Value: 143 | Ref: SQLDatabase 144 | EvaluationPeriods: 2 145 | MetricName: "WriteLatency" 146 | Namespace: "AWS/RDS" 147 | Period: 300 148 | Statistic: Maximum 149 | Threshold: 1.0 150 | TreatMissingData: "notBreaching" 151 | Outputs: 152 | SQLDatabaseEndpoint: 153 | Description: Database endpoint 154 | Value: !Sub "${SQLDatabase.Endpoint.Address}:${SQLDatabase.Endpoint.Port}" 155 | WritethroughputAlarmARN: 156 | Description: ARN of Write throughput alarm 157 | Value: !GetAtt WritethroughputAlarm.Arn 158 | ReadLatencyAlarmARN: 159 | Description: ARN of Read latency alarm 160 | Value: !GetAtt ReadLatencyAlarm.Arn 161 | WriteLatencyAlarmARN: 162 | Description: ARN of Write latency alarm 163 | Value: !GetAtt WritelatencyAlarm.Arn -------------------------------------------------------------------------------- /cloudformation-sqlserver-master-database.yaml: -------------------------------------------------------------------------------- 1 | AWSTemplateFormatVersion: '2010-09-09' 2 | Description: Creates an empty SQL Server RDS database as an example for automated deployments. 3 | Parameters: 4 | SqlServerInstanceName: 5 | NoEcho: 'false' 6 | Description: RDS SQL Server Instance Name 7 | Type: String 8 | Default: SqlRdsDB 9 | MinLength: '1' 10 | MaxLength: '63' 11 | AllowedPattern: "[a-zA-Z][a-zA-Z0-9]*" 12 | DatabaseUsername: 13 | AllowedPattern: "[a-zA-Z0-9]+" 14 | ConstraintDescription: must contain only alphanumeric characters. 15 | Description: The database admin account user name. 16 | MaxLength: '16' 17 | MinLength: '1' 18 | Type: String 19 | DatabasePassword: 20 | AllowedPattern: "^(?=.*[0-9])(?=.*[a-zA-Z])([a-zA-Z0-9]+)" 21 | ConstraintDescription: Must contain only alphanumeric characters with at least one capital letter and one number. 22 | Description: The database admin account password. 23 | MaxLength: '41' 24 | MinLength: '8' 25 | NoEcho: 'true' 26 | Type: String 27 | Metadata: 28 | AWS::CloudFormation::Interface: 29 | ParameterGroups: 30 | - Label: 31 | default: SQL Instance name, master username and password 32 | Parameters: 33 | - SqlServerInstanceName 34 | - DatabaseUsername 35 | - DatabasePassword 36 | ParameterLabels: 37 | SqlServerInstanceName: 38 | default: Instance name 39 | DatabaseUsername: 40 | default: Master user name 41 | DatabasePassword: 42 | default: Password 43 | Resources: 44 | SQLServerSecurityGroup: 45 | Type: AWS::EC2::SecurityGroup 46 | Properties: 47 | GroupDescription: SQL Server Security Group 48 | SecurityGroupIngress: 49 | - IpProtocol: tcp 50 | FromPort: '1433' 51 | ToPort: '1433' 52 | CidrIp: 0.0.0.0/0 53 | SQLDatabase: 54 | Type: AWS::RDS::DBInstance 55 | Properties: 56 | VPCSecurityGroups: 57 | - Fn::GetAtt: 58 | - SQLServerSecurityGroup 59 | - GroupId 60 | DBInstanceIdentifier: 61 | Ref: SqlServerInstanceName 62 | LicenseModel: license-included 63 | Engine: sqlserver-se 64 | EngineVersion: 12.00.4422.0.v1 65 | MultiAZ: true 66 | DBInstanceClass: db.m4.large 67 | AllocatedStorage: '500' 68 | MasterUsername: 69 | Ref: DatabaseUsername 70 | MasterUserPassword: 71 | Ref: DatabasePassword 72 | PubliclyAccessible: 'true' 73 | Tags: 74 | - 75 | Key: "Name" 76 | Value: "sqlmaster" 77 | - 78 | Key: "project" 79 | Value: "development unittest" 80 | BackupRetentionPeriod: '1' 81 | DependsOn: SQLServerSecurityGroup 82 | Outputs: 83 | SQLDatabaseEndpoint: 84 | Description: Database endpoint 85 | Value: !Sub "${SQLDatabase.Endpoint.Address}:${SQLDatabase.Endpoint.Port}" 86 | -------------------------------------------------------------------------------- /shell-script-samples/create-alerts.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Change this value if you want to work with a different region 4 | REGION="us-west-2" 5 | # Change this to your actual email address 6 | EMAILADDR="my-address@example.com" 7 | # Change this value to the datbase you want to set alerts on 8 | DB="sqlse" 9 | 10 | aws sns create-topic --name "application-dba-notification" --region $REGION 11 | #This will prompt you to enter the new topic ARN if you want to run this as a full script 12 | echo "Enter the topic ARN: " 13 | read TOPICARN 14 | # Subscribe to the new topic 15 | # To actually create a subscription, the subscription must be confirmed 16 | aws sns subscribe --topic-arn $TOPICARN \ 17 | --protocol email --notification-endpoint $EMAILADDR --region $REGION 18 | 19 | # Adding an alarm through the CLI 20 | aws cloudwatch put-metric-alarm --alarm-name "Write throughput" --alarm-description "write-throughput" --actions-enabled \ 21 | --alarm-actions "$TOPICARN" --metric-name "WriteThroughput" --namespace "AWS/RDS" --statistic "Maximum" \ 22 | --dimensions "Name=DBInstanceIdentifier,Value=$DB" --period 300 --evaluation-periods 2 --threshold 48000 \ 23 | --comparison-operator GreaterThanOrEqualToThreshold --treat-missing-data notBreaching --region $REGION 24 | 25 | # Adding an alarm through the CLI 26 | aws cloudwatch put-metric-alarm --alarm-name "Write latency" --alarm-description "write-latency" --actions-enabled \ 27 | --alarm-actions "$TOPICARN" --metric-name "WriteLatency" --namespace "AWS/RDS" --statistic "Maximum" \ 28 | --dimensions "Name=DBInstanceIdentifier,Value=$DB" --period 300 --evaluation-periods 2 --threshold 0.004 \ 29 | --comparison-operator GreaterThanOrEqualToThreshold --treat-missing-data notBreaching --region $REGION 30 | 31 | # Adding an alarm through the CLI 32 | aws cloudwatch put-metric-alarm --alarm-name "Read Latency" \ 33 | --alarm-description "read-latency" --actions-enabled \ 34 | --alarm-actions "$TOPICARN" \ 35 | --metric-name "ReadLatency" --namespace "AWS/RDS" --statistic "Maximum" \ 36 | --dimensions "Name=DBInstanceIdentifier,Value=$DB" --period 300 \ 37 | --evaluation-periods 2 --threshold 0.010 --comparison-operator GreaterThanOrEqualToThreshold \ 38 | --treat-missing-data notBreaching --region $REGION 39 | -------------------------------------------------------------------------------- /shell-script-samples/create-database-instance.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Change this value if you want to work with a different region 4 | REGION="us-west-2" 5 | # Change this security group value to one that is valid for your VPC 6 | SECURITY_GROUP="sg-66876201" 7 | 8 | # create a new SQLServer RDS Multi-AZ database with default parameter, default option group, and publicly accessible 9 | # database should be Standard Edition v12 with license included 10 | aws rds create-db-instance --db-instance-identifier "sqltest" --allocated-storage 500 --db-instance-class db.m4.large \ 11 | --engine sqlserver-se --engine-version "12.00.4422.0.v1" --master-username "myuser" --master-user-password "mypassword" \ 12 | --vpc-security-group-ids $SECURITY_GROUP --backup-retention-period 7 --license-model license-included \ 13 | --tags "Key=project,Value=configdata" --region "us-west-2" --multi-az --publicly-accessible --region $REGION 14 | # The output of this command will be the database configuration. DB will take a few minutes to create 15 | # and take the initial snapshot -------------------------------------------------------------------------------- /shell-script-samples/create-manual-snapshot.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Change this value if you want to work with a different region 4 | REGION="us-west-2" 5 | # Enter the database name you want to take a manual snapshot of 6 | DB="sqltest" 7 | 8 | # take a manual snapshot of the database 9 | aws rds create-db-snapshot --db-snapshot-identifier "sqltest-master-snapshot" \ 10 | --db-instance-identifier $DB --tags "Key=project,Value=basedatabase" --region $REGION 11 | 12 | -------------------------------------------------------------------------------- /shell-script-samples/delete-alerts.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Change this value if you want to work with a different region 4 | REGION="us-west-2" 5 | 6 | # Example for deleting the Commit latency test alarm created earlier through the CLI 7 | aws cloudwatch delete-alarms --alarm-names "Commit latency" --region $REGION 8 | 9 | # Example for deleting the Insert latency test alarm created earlier through the CLI 10 | aws cloudwatch delete-alarms --alarm-names "Insert latency" --region $REGION 11 | 12 | # Example for deleting the Delete latency test alarm created earlier through the CLI 13 | aws cloudwatch delete-alarms --alarm-names "Delete latency" --region $REGION 14 | 15 | -------------------------------------------------------------------------------- /shell-script-samples/modify-database-instance.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Set this value for the database identifier you want to modify 3 | DB="sqltest" 4 | 5 | # Change this value if you want to work with a different region 6 | REGION="us-west-2" 7 | # Prerequisites for running these code examples 8 | # This script assumes you have created your parameter and option groups ahead of time or you are using default 9 | PARAMETER_GROUP_NAME="sqlserver-se-12-c2-audit-enabled" 10 | OPTION_GROUP_NAME="sqlserver-se-12-native-backup" 11 | 12 | # modify an rds instance to use a bigger box 13 | # This command can also be used to scale down the instance or change other values based on your engine 14 | aws rds modify-db-instance --db-instance-identifier $DB --db-instance-class db.m4.xlarge \ 15 | --apply-immediately --region $REGION 16 | 17 | # modify the rds instance to use a different option group and apply it immediately 18 | aws rds modify-db-instance --db-instance-identifier $DB --option-group-name $OPTION_GROUP_NAME\ 19 | --apply-immediately --region $REGION -------------------------------------------------------------------------------- /shell-script-samples/restore-to-pointintime.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Change this value if you want to work with a different region 3 | REGION="us-west-2" 4 | # Change this value to the datbase you want to restore to a point in time. 5 | DB="sqltest" 6 | # Issue a describe-db-instances to retrieve the value of 7 | # "LatestRestorableTime": "2017-10-04T01:53:01Z", 8 | aws rds describe-db-instances --db-instance-identifier sqltest --region $REGION 9 | # If your latest restore time from the output is 2017-10-04T01:53:01Z 10 | # and your retention period is 1 day the command below will succeed 11 | # 12 | # Change the restore time to match the values on your instance 13 | # Database will be restored to database-name-copy 14 | aws rds restore-db-instance-to-point-in-time --source-db-instance-identifier $DB \ 15 | --target-db-instance-identifier $DB-copy \ 16 | --restore-time 2017-10-04T00:00:00.000Z --region $REGION --------------------------------------------------------------------------------