How does this differ from RDS automatic snapshots?
Note that RDS comes with nightly snapshots by default. The main reason to use this function is:
You want to take snapshots of your database more often than once per night.
You want to store all of your snapshots in a separate AWS account for security and redundancy purposes.
You want to retain backups for longer than the 35-day limit for automatic snapshots.
How do you backup your RDS snapshots to a separate AWS account?
One of the main use cases for this module is to be able to store your RDS snapshots in a completely separate AWS account.
That reduces the chances that you, or perhaps an intruder who breaks into your AWS account, can accidentally or
intentionally delete all your snapshots.
Let's say you have an RDS database in account A and you want to store snapshots in account B. To set that up, you need
to do the following:
Deploy this lambda function (lambda-create-snapshot) and the lambda-share-snapshot
lambda function in account A. Configure this lambda function to trigger the
lambda-share-snapshot function by setting the following variables:
module"create_snapshot" {
source = "git::git@github.com:gruntwork-io/module-data-storage.git//modules/lambda-create-snapshot?ref=v1.0.8"# ... (other params ommitted) ...
share_snapshot_with_another_account = true
share_snapshot_lambda_arn = "(ARN of the lambda-share-snapshot function)"
share_snapshot_with_account_id = "(The ID of account B)"
}
This will make the snapshots from account A visible in account B, but it won't actually copy them into the
account. To copy them into account B, deploy the lambda-copy-shared-snapshot
module in account B and configure it with the account ID of account A:
module"copy_shared_snapshot" {
source = "git::git@github.com:gruntwork-io/module-data-storage.git//modules/lambda-copy-shared-snapshot?ref=v1.0.8"# ... (other params ommitted) ...
rds_db_identifier = "(The identifier of the RDS DB in account A)"
rds_db_account_id = "(The ID of account A)"
}
Why use lambda functions?
The reason we use lambda functions for handling snapshots is:
It's easy to use scheduled events and
schedule expressions
to run a lambda function on a periodic basis that is more reliable than just using cron.
You can give your lambda function access to RDS via IAM roles instead of using API keys with an external app.
The main use case for these lambda snapshot modules is to copy RDS snapshots to an external AWS account. That means
you need to run code in multiple accounts. It's easier to deploy the necessary lambda functions in each account
and give those functions access to RDS via IAM roles than it is to create a CI job that can securely access both
accounts.
How do you configure this module?
This module allows you to configure a number of parameters, such as which database to backup, how often to run the
backups, what account to share the backups with, and more. For a list of all available variables and their
descriptions, see vars.tf.
How do you configure multiple backup schedules?
You can use this module multiple times by configuring different namespaces for the snapshots, which allows you to have
multiple backup schedules with different retention periods. For example you could keep hourly backups for three days,
and weekly backups for one year by configuring two instances of this modules.
Configure sharing in the same way as described earlier. Only the snapshots from the module with sharing enabled will be
copied.
It's important to use both snapshot and lambda namespaces in all instances to avoid ambiguity for the
lambda-cleanup-snapshots module. The
lambda-cleanup-snapshots module can be configured with a snapshot_namespace too so
different retention periods can be configured for each set of snapshots. See the
lambda-rds-snapshot-multiple-schedules example.
Questions? Ask away.
We're here to talk about our services, answer any questions, give advice, or just to chat.
{"treedata":{"name":"root","toggled":true,"children":[{"name":".circleci","children":[{"name":"config.yml","path":".circleci/config.yml","sha":"e161caf8ec8e50bf9bc8412104db4130a18fc76f"}]},{"name":".gitignore","path":".gitignore","sha":"b221764008a74751a75f9ba58821c7e7bd7422b2"},{"name":".pre-commit-config.yaml","path":".pre-commit-config.yaml","sha":"dd17d910687309b3ad64bae6e967df72e5417357"},{"name":"CODEOWNERS","path":"CODEOWNERS","sha":"f6e0666fa0dee5df6743291167734a2bcfbb359b"},{"name":"LICENSE.txt","path":"LICENSE.txt","sha":"f4e3d9bd4717a044ed31ad847a300eee74371a78"},{"name":"README.adoc","path":"README.adoc","sha":"683afbce72ea0c7b626932bd314b9c2ae992c207"},{"name":"_docs","children":[{"name":"aurora-serverless.png","path":"_docs/aurora-serverless.png","sha":"5a53145be56705c76f7f7aa6a25aa0ddee78e4a3"},{"name":"aurora.png","path":"_docs/aurora.png","sha":"fc218831bfa34097a56f1b0e47fe05521bdb4a8a"},{"name":"data-backup-architecture.png","path":"_docs/data-backup-architecture.png","sha":"fcc7ce8753e28c19af87ea5cea96e6ded648d429"},{"name":"data-backup.png","path":"_docs/data-backup.png","sha":"116b10f231073f8c52255ca98e48cc228c48a2c3"},{"name":"mariadb.png","path":"_docs/mariadb.png","sha":"d540d3d3ff8797c4a4c3a62c65e7d3f63621568f"},{"name":"mysql.png","path":"_docs/mysql.png","sha":"73b55bd0d517dcba53c878712544abf96be3a66e"},{"name":"oracle.png","path":"_docs/oracle.png","sha":"b5f1ca801f5af4a30f1b812eea17cec516c1fe6c"},{"name":"postgresql.png","path":"_docs/postgresql.png","sha":"fd9c7ec282aef38a5813e8542d92227b96bd5be8"},{"name":"rds-architecture.png","path":"_docs/rds-architecture.png","sha":"8f2b1b5b4015a5777032c6aa64627ceee24330fc"},{"name":"sqlserver.png","path":"_docs/sqlserver.png","sha":"a800d188398262593f4f89f27c8f3ce2ce1e76a4"}]},{"name":"examples","children":[{"name":"aurora-global-cluster","children":[{"name":"README.md","path":"examples/aurora-global-cluster/README.md","sha":"bbefa516493669a8134131aa4f6c9892ca17a932"},{"name":"main.tf","path":"examples/aurora-global-cluster/main.tf","sha":"86f00cb270ff79546ce995fb6c2e204016745d28"},{"name":"outputs.tf","path":"examples/aurora-global-cluster/outputs.tf","sha":"105d706d41684b4c7be092ebd43bf6ba8ebf6f80"},{"name":"vars.tf","path":"examples/aurora-global-cluster/vars.tf","sha":"29b33911054fde667cd778658a7bc63f3a61bedd"}]},{"name":"aurora-serverless","children":[{"name":"README.md","path":"examples/aurora-serverless/README.md","sha":"073a25d4190dc28f64d2e1675c30e60eb255d306"},{"name":"main.tf","path":"examples/aurora-serverless/main.tf","sha":"059474ef6c778717ede7bdc2367453ac41d11c53"},{"name":"outputs.tf","path":"examples/aurora-serverless/outputs.tf","sha":"7da44a91e9ac6e14a5c7c144c60c5ad0ceb5ce1b"},{"name":"vars.tf","path":"examples/aurora-serverless/vars.tf","sha":"be0acaabd7f525d00ded7bb8ace8a3e54b03e160"}]},{"name":"aurora-with-cross-region-replica","children":[{"name":"README.md","path":"examples/aurora-with-cross-region-replica/README.md","sha":"17c93f6fc01e4df4bc8014f33773dc5f05ab8017"},{"name":"main.tf","path":"examples/aurora-with-cross-region-replica/main.tf","sha":"d7afff3c426686203b179446cda4bdbc12f51d71"},{"name":"outputs.tf","path":"examples/aurora-with-cross-region-replica/outputs.tf","sha":"58a3862180d107c3d0501ec9b289b08ed09af3a8"},{"name":"vars.tf","path":"examples/aurora-with-cross-region-replica/vars.tf","sha":"0890cddb1b6aac72b378632e9ed131a9bd177e04"}]},{"name":"aurora","children":[{"name":"README.md","path":"examples/aurora/README.md","sha":"8190444c83829a5b7a4e9acad31414e0dced277a"},{"name":"main.tf","path":"examples/aurora/main.tf","sha":"e92bd5e6c1bcdd18b482eaf326a35d7a8c3bc20a"},{"name":"outputs.tf","path":"examples/aurora/outputs.tf","sha":"142569b7d9772c741ee28846de617f5a4b7f0d84"},{"name":"vars.tf","path":"examples/aurora/vars.tf","sha":"e046db594a501fcb4ff0252a2ac5e187dd382ccf"}]},{"name":"efs","children":[{"name":"README.md","path":"examples/efs/README.md","sha":"5b883e1deac79fb511a39fa062bd854f2a903579"},{"name":"main.tf","path":"examples/efs/main.tf","sha":"b79d5ebd7d310957e67c834f7464e47a86c94b08"},{"name":"outputs.tf","path":"examples/efs/outputs.tf","sha":"b5a6400d4a67e1e6f6773c513acaa8784ceda46b"},{"name":"vars.tf","path":"examples/efs/vars.tf","sha":"db0919b5bbfca3fee37baf1d35272ed2108d5405"}]},{"name":"lambda-rds-snapshot-multiple-schedules","children":[{"name":"README.md","path":"examples/lambda-rds-snapshot-multiple-schedules/README.md","sha":"c76bcf6ba6865fe2a9e4a7d9b47d231ae7822e47"},{"name":"main.tf","path":"examples/lambda-rds-snapshot-multiple-schedules/main.tf","sha":"ffab74de147c8db13f4bc1ad2ee9fb5096460bbd"},{"name":"outputs.tf","path":"examples/lambda-rds-snapshot-multiple-schedules/outputs.tf","sha":"7a8f966782c659d1568f35684197f232939ea9ec"},{"name":"vars.tf","path":"examples/lambda-rds-snapshot-multiple-schedules/vars.tf","sha":"f6ae16692c02a1ae6ed95d58e16bd3e02b98f703"}]},{"name":"lambda-rds-snapshot","children":[{"name":"README.md","path":"examples/lambda-rds-snapshot/README.md","sha":"d7422ca3a039c7e1056c17fc73fbbddfddce6741"},{"name":"main.tf","path":"examples/lambda-rds-snapshot/main.tf","sha":"75251ca7c930bcb08c445fb54c3aa020c1cedc43"},{"name":"outputs.tf","path":"examples/lambda-rds-snapshot/outputs.tf","sha":"375c8bb979dd4133c3675d9e6263e1138c448973"},{"name":"vars.tf","path":"examples/lambda-rds-snapshot/vars.tf","sha":"b777711ea9860aa43f766a5e5edf8b817e994885"}]},{"name":"rds-mariadb","children":[{"name":"README.md","path":"examples/rds-mariadb/README.md","sha":"6540229dddcb38071d37b6697762d27a54e28cc8"},{"name":"main.tf","path":"examples/rds-mariadb/main.tf","sha":"4e5f33f401105871a290f413648ead0627da1ff1"},{"name":"outputs.tf","path":"examples/rds-mariadb/outputs.tf","sha":"bd45b0035943021763d0365da3fe0d1e9f9b16b9"},{"name":"vars.tf","path":"examples/rds-mariadb/vars.tf","sha":"6a8212a3c4e8d4bbd1fe6f000bb699b9f5ecf1e0"}]},{"name":"rds-mysql-with-cross-region-replica","children":[{"name":"README.md","path":"examples/rds-mysql-with-cross-region-replica/README.md","sha":"4671d1e9a47e6179c5dc809bf27cffc3468b3460"},{"name":"main.tf","path":"examples/rds-mysql-with-cross-region-replica/main.tf","sha":"c311da161b96fefb50c7f0d585238236447c3fa7"},{"name":"outputs.tf","path":"examples/rds-mysql-with-cross-region-replica/outputs.tf","sha":"2d79e34b6bc52c934a62e40e38e3cdcace5196a0"},{"name":"vars.tf","path":"examples/rds-mysql-with-cross-region-replica/vars.tf","sha":"e29f844891c30bb88097a66328081dde94b2e611"}]},{"name":"rds-mysql","children":[{"name":"README.md","path":"examples/rds-mysql/README.md","sha":"6a7fb5d5560cc42ec9a6ac830358aa7ab7ca502d"},{"name":"main.tf","path":"examples/rds-mysql/main.tf","sha":"e86671206fa3089c64d24076c80b0f261096bf93"},{"name":"outputs.tf","path":"examples/rds-mysql/outputs.tf","sha":"e2ae2afdbcc0d27baa5d50be333f9d0a717e1a33"},{"name":"vars.tf","path":"examples/rds-mysql/vars.tf","sha":"0ee52281448e95f13fcaacf427bed62600a32c23"}]},{"name":"rds-postgres","children":[{"name":"README.md","path":"examples/rds-postgres/README.md","sha":"ab4e18c200fc749a54ee700223d27261c731e436"},{"name":"main.tf","path":"examples/rds-postgres/main.tf","sha":"e122b2ad8421c1ed31d8381c0e9dc7cac89e374c"},{"name":"outputs.tf","path":"examples/rds-postgres/outputs.tf","sha":"5371c2284c0ea3d4de5790077ba45d9d445c2965"},{"name":"vars.tf","path":"examples/rds-postgres/vars.tf","sha":"0f2541c42ceef4f29fcfdc4aa8141d18b854f7f5"}]},{"name":"rds-sqlserver","children":[{"name":"README.md","path":"examples/rds-sqlserver/README.md","sha":"26bf52d347c247e5f63bc113476e87d75375ba84"},{"name":"main.tf","path":"examples/rds-sqlserver/main.tf","sha":"376fd7e96798604d81c1a8526f204114500ff835"},{"name":"outputs.tf","path":"examples/rds-sqlserver/outputs.tf","sha":"a1726fd73528af38b436c053128f24a17da740c3"},{"name":"vars.tf","path":"examples/rds-sqlserver/vars.tf","sha":"dabccb3da2548b8a9e302ed5e9be01b18c275ca9"}]},{"name":"rds-with-replicas","children":[{"name":"README.md","path":"examples/rds-with-replicas/README.md","sha":"327357a98e9b2bbf650d91a207bd96fc4a6f452f"},{"name":"main.tf","path":"examples/rds-with-replicas/main.tf","sha":"d8079695d12f3ac41c447f5c1375877d87a7a369"},{"name":"outputs.tf","path":"examples/rds-with-replicas/outputs.tf","sha":"991d5436a635194fec1ad1476eb7be6616032c7a"},{"name":"vars.tf","path":"examples/rds-with-replicas/vars.tf","sha":"a1ab0eaadeaee910d4b81265ba28524917926e6c"}]}]},{"name":"modules","children":[{"name":"aurora","children":[{"name":"README-Aurora-Serverless.adoc","path":"modules/aurora/README-Aurora-Serverless.adoc","sha":"9029de222f9bcf675ff37d7e97b9eae29664fb34"},{"name":"README-Aurora.adoc","path":"modules/aurora/README-Aurora.adoc","sha":"89ebb7a7c5aa8632a930c34993fc6c4cebe7efb4"},{"name":"README.adoc","path":"modules/aurora/README.adoc","sha":"d0e19665bb22ad2a62968f6ae047d1685f984d80"},{"name":"core-concepts.md","path":"modules/aurora/core-concepts.md","sha":"c359faf7ca9789e73296433b9c5fdb19956fa16a"},{"name":"main.tf","path":"modules/aurora/main.tf","sha":"82c263652f421f934dd9f2c0771a46e7bab39f33"},{"name":"outputs.tf","path":"modules/aurora/outputs.tf","sha":"f27a9f761484528ef8d6cdfc687dbb936307bf48"},{"name":"vars.tf","path":"modules/aurora/vars.tf","sha":"fb9bf14db0a05facdb07197e916ea42d189c3431"}]},{"name":"efs","children":[{"name":"README.adoc","path":"modules/efs/README.adoc","sha":"165387a5ef2015a3f3a930ea3d4f1703453254bd"},{"name":"main.tf","path":"modules/efs/main.tf","sha":"163d66587f1372cd7ad28e32aab43afb552fa7ce"},{"name":"outputs.tf","path":"modules/efs/outputs.tf","sha":"b505b3d3c4ade32e06286ebea60be1a5f67ce77a"},{"name":"vars.tf","path":"modules/efs/vars.tf","sha":"ada809d408ec9a125e372dd4f04b1b1c30e28d82"}]},{"name":"lambda-cleanup-snapshots","children":[{"name":"README.md","path":"modules/lambda-cleanup-snapshots/README.md","sha":"2c491aeca99fac0536e6c86ef850e00146ac7259"},{"name":"cleanup-rds-snapshots","children":[{"name":"index.py","path":"modules/lambda-cleanup-snapshots/cleanup-rds-snapshots/index.py","sha":"9e651d2d57310054e21d891aec481d02c9d79489"}]},{"name":"main.tf","path":"modules/lambda-cleanup-snapshots/main.tf","sha":"0cc60eb6b3491ff144ecf64d078b9a962f993f7b"},{"name":"outputs.tf","path":"modules/lambda-cleanup-snapshots/outputs.tf","sha":"a99c0265d859dd0c87a6eba62aaf2b013e224873"},{"name":"vars.tf","path":"modules/lambda-cleanup-snapshots/vars.tf","sha":"6a8d68f55cf51d75ec84caed75ebcb2ea25a5dab"}]},{"name":"lambda-copy-shared-snapshot","children":[{"name":"README.md","path":"modules/lambda-copy-shared-snapshot/README.md","sha":"9953dc7e2429ffa95751d868b725018fedc03a4e"},{"name":"copy-shared-rds-snapshot","children":[{"name":"index.py","path":"modules/lambda-copy-shared-snapshot/copy-shared-rds-snapshot/index.py","sha":"6b1a0331ee9ffc57c95e0923a4b1db46dec0b2c5"}]},{"name":"main.tf","path":"modules/lambda-copy-shared-snapshot/main.tf","sha":"3cadd2f4a757bc5284a994266ef2cf9ab574ac0d"},{"name":"outputs.tf","path":"modules/lambda-copy-shared-snapshot/outputs.tf","sha":"f4833d96fa6d47190b9d2c3af243142aefc59d59"},{"name":"vars.tf","path":"modules/lambda-copy-shared-snapshot/vars.tf","sha":"167544053dc243f447befed6b576c3b515bc6d58"}]},{"name":"lambda-create-snapshot","children":[{"name":"README.adoc","path":"modules/lambda-create-snapshot/README.adoc","sha":"4c6a9c7fa49b66aeeeae492b895bb98d97ab3062"},{"name":"core-concepts.md","path":"modules/lambda-create-snapshot/core-concepts.md","sha":"3b0830d9d0af865d78d5014d4bd2d57c25eb4bf0","toggled":true},{"name":"create-rds-snapshot","children":[{"name":"index.py","path":"modules/lambda-create-snapshot/create-rds-snapshot/index.py","sha":"16bc7d1b67dcee20577808cdbf39b1938972c5cb"}]},{"name":"main.tf","path":"modules/lambda-create-snapshot/main.tf","sha":"4293138b27a0f883d75510a360c89eba356f0deb"},{"name":"outputs.tf","path":"modules/lambda-create-snapshot/outputs.tf","sha":"a0f5ffafa8ef11d00b72f1858b81e182ab2471dd"},{"name":"vars.tf","path":"modules/lambda-create-snapshot/vars.tf","sha":"f18942d85d2e7c5dc4c629b1503a1c32a52e4b56"}],"toggled":true},{"name":"lambda-share-snapshot","children":[{"name":"README.md","path":"modules/lambda-share-snapshot/README.md","sha":"f00a0ab9745632e85d5f4c8e7a9389e1a8608b6b"},{"name":"main.tf","path":"modules/lambda-share-snapshot/main.tf","sha":"51bcabb9cca3400b0fd42cf0ff8be63592b1c926"},{"name":"outputs.tf","path":"modules/lambda-share-snapshot/outputs.tf","sha":"c0d2854f967a6c963662c660d6ae96d8cabe471a"},{"name":"share-rds-snapshot","children":[{"name":"index.py","path":"modules/lambda-share-snapshot/share-rds-snapshot/index.py","sha":"b4e784ff72172d1f3e84f0f97a48fdf60405ed27"}]},{"name":"vars.tf","path":"modules/lambda-share-snapshot/vars.tf","sha":"683571dbf98c2fb4f8077e7adadcb4df4241b9b4"}]},{"name":"rds","children":[{"name":"README-MariaDb.adoc","path":"modules/rds/README-MariaDb.adoc","sha":"52c88eedb3410b14c6ccc4db8ea3eaa484b7c13a"},{"name":"README-MySQL.adoc","path":"modules/rds/README-MySQL.adoc","sha":"75a2e92b04368988ffe7fb405a99155881f2c4f7"},{"name":"README-Oracle.adoc","path":"modules/rds/README-Oracle.adoc","sha":"a9f084cfbd084413bbcc818fd9f438a4faee367b"},{"name":"README-PostgreSQL.adoc","path":"modules/rds/README-PostgreSQL.adoc","sha":"2486401acaa724eba2f0a8814ef9dfa19c510ae0"},{"name":"README-SqlServer.adoc","path":"modules/rds/README-SqlServer.adoc","sha":"76d7220a727d84567e819102617bd01a3bda0cb2"},{"name":"README.adoc","path":"modules/rds/README.adoc","sha":"fa2c8270106116804fa8ee61a7b5885ab8a4833f"},{"name":"core-concepts.md","path":"modules/rds/core-concepts.md","sha":"29463161611168b652ba94e011604f23395cde9a"},{"name":"main.tf","path":"modules/rds/main.tf","sha":"1afe15825f438b1dcfb64c7414504027e8e772ff"},{"name":"outputs.tf","path":"modules/rds/outputs.tf","sha":"ffd8da9da933ee678f56befbf8ee7edcc19cd6cf"},{"name":"vars.tf","path":"modules/rds/vars.tf","sha":"d03e3df258908ee7c3cf712aeae83fbd17872280"}]}],"toggled":true},{"name":"test","children":[{"name":"README.md","path":"test/README.md","sha":"ebcf2313b7664113168ca7e73d01acbd232d8f39"},{"name":"example_aurora_global_test.go","path":"test/example_aurora_global_test.go","sha":"12cd47486d7f62a862f36265fb41c08fb598404a"},{"name":"example_aurora_test.go","path":"test/example_aurora_test.go","sha":"14485405d1f5899ca61bea11ba4b7f41d6234d6e"},{"name":"example_aurora_with_cross_region_replica_test.go","path":"test/example_aurora_with_cross_region_replica_test.go","sha":"2fe4b909abbeebfc4cddff2237d6b2470982cd8a"},{"name":"example_efs_test.go","path":"test/example_efs_test.go","sha":"c84d706017cb7ca512c4a4070b470ecc586ffc89"},{"name":"example_lambda_rds_snapshot_create_resources_test.go","path":"test/example_lambda_rds_snapshot_create_resources_test.go","sha":"1af623cab68b918b65fe3e7389377ce08a7bf98c"},{"name":"example_lambda_rds_snapshot_multiple_schedules_test.go","path":"test/example_lambda_rds_snapshot_multiple_schedules_test.go","sha":"094a8a691f259f79943e7fbf672d2ff8b40b65e4"},{"name":"example_lambda_rds_snapshot_test.go","path":"test/example_lambda_rds_snapshot_test.go","sha":"092e678c8f1297d2767141295933ea4e5795aae1"},{"name":"example_rds_mariadb_test.go","path":"test/example_rds_mariadb_test.go","sha":"bdfeed4be219420de6fe37471d9f3231cdd5a829"},{"name":"example_rds_mysql_test.go","path":"test/example_rds_mysql_test.go","sha":"cfc6ef03fb0a9ae01f889f6a5db83ed49b008ed2"},{"name":"example_rds_mysql_with_cross_region_replica_test.go","path":"test/example_rds_mysql_with_cross_region_replica_test.go","sha":"048a9b1ec7ca8fd9acce6f9022e178312b5b2b68"},{"name":"example_rds_postgres_test.go","path":"test/example_rds_postgres_test.go","sha":"d301ebc1542294b294eb299038abff9d305da804"},{"name":"example_rds_sqlserver_test.go","path":"test/example_rds_sqlserver_test.go","sha":"96ae522976ae664c9e74cbd29293f49d7ed2fa26"},{"name":"example_rds_with_replicas_test.go","path":"test/example_rds_with_replicas_test.go","sha":"ed3c82e66d48c8388a04363cab2e1b3458f4a7fb"},{"name":"go.mod","path":"test/go.mod","sha":"3245f043b6d05e295fb010ff8886971e4bf1a26a"},{"name":"go.sum","path":"test/go.sum","sha":"de745a2994481da56e437d25c745cea5c7d7fd9f"},{"name":"util.go","path":"test/util.go","sha":"a29464ed90a313f6182d38126198a9069b8a1262"}]}]},"detailsContent":"<h1 class=\"preview__body--title\" id=\"data-backup-core-concepts\">Data backup core concepts</h1><div class=\"preview__body--border\"></div><h2 class=\"preview__body--subtitle\" id=\"how-does-this-differ-from-rds-automatic-snapshots\">How does this differ from RDS automatic snapshots?</h2>\n<p>Note that RDS comes with nightly snapshots by default. The main reason to use this function is:</p>\n<ol>\n<li>You want to take snapshots of your database more often than once per night.</li>\n<li>You want to store all of your snapshots in a separate AWS account for security and redundancy purposes.</li>\n<li>You want to retain backups for longer than the 35-day limit for automatic snapshots.</li>\n</ol>\n<h2 class=\"preview__body--subtitle\" id=\"how-do-you-backup-your-rds-snapshots-to-a-separate-aws-account\">How do you backup your RDS snapshots to a separate AWS account?</h2>\n<p>One of the main use cases for this module is to be able to store your RDS snapshots in a completely separate AWS account.\nThat reduces the chances that you, or perhaps an intruder who breaks into your AWS account, can accidentally or\nintentionally delete all your snapshots.</p>\n<p>Let's say you have an RDS database in account A and you want to store snapshots in account B. To set that up, you need\nto do the following:</p>\n<ol>\n<li>\n<p>Deploy this lambda function (<code>lambda-create-snapshot</code>) and the <a href=\"/repos/v0.17.1/module-data-storage/modules/lambda-share-snapshot\" class=\"preview__body--description--blue\">lambda-share-snapshot\nlambda function</a> in account A. Configure this lambda function to trigger the\n<code>lambda-share-snapshot</code> function by setting the following variables:</p>\n<pre><span class=\"hljs-keyword\">module</span> <span class=\"hljs-string\">\"create_snapshot\"</span> {\n source = <span class=\"hljs-string\">\"git::git@github.com:gruntwork-io/module-data-storage.git//modules/lambda-create-snapshot?ref=v1.0.8\"</span>\n\n <span class=\"hljs-comment\"># ... (other params ommitted) ...</span>\n\n share_snapshot_with_another_account = true\n share_snapshot_lambda_arn = <span class=\"hljs-string\">\"(ARN of the lambda-share-snapshot function)\"</span>\n share_snapshot_with_account_id = <span class=\"hljs-string\">\"(The ID of account B)\"</span>\n}\n</pre>\n</li>\n<li>\n<p>This will make the snapshots from account A <em>visible</em> in account B, but it won't actually copy them into the\naccount. To copy them into account B, deploy the <a href=\"/repos/v0.17.1/module-data-storage/modules/lambda-copy-shared-snapshot\" class=\"preview__body--description--blue\">lambda-copy-shared-snapshot\nmodule</a> in account B and configure it with the account ID of account A:</p>\n<pre><span class=\"hljs-keyword\">module</span> <span class=\"hljs-string\">\"copy_shared_snapshot\"</span> {\n source = <span class=\"hljs-string\">\"git::git@github.com:gruntwork-io/module-data-storage.git//modules/lambda-copy-shared-snapshot?ref=v1.0.8\"</span>\n\n <span class=\"hljs-comment\"># ... (other params ommitted) ...</span>\n\n rds_db_identifier = <span class=\"hljs-string\">\"(The identifier of the RDS DB in account A)\"</span>\n rds_db_account_id = <span class=\"hljs-string\">\"(The ID of account A)\"</span>\n}\n</pre>\n</li>\n</ol>\n<h2 class=\"preview__body--subtitle\" id=\"why-use-lambda-functions\">Why use lambda functions?</h2>\n<p>The reason we use lambda functions for handling snapshots is:</p>\n<ol>\n<li>\n<p>It's easy to use <a href=\"http://docs.aws.amazon.com/lambda/latest/dg/with-scheduled-events.html\" class=\"preview__body--description--blue\" target=\"_blank\">scheduled events</a> and\n<a href=\"http://docs.aws.amazon.com/lambda/latest/dg/tutorial-scheduled-events-schedule-expressions.html\" class=\"preview__body--description--blue\" target=\"_blank\">schedule expressions</a>\nto run a lambda function on a periodic basis that is more reliable than just using cron.</p>\n</li>\n<li>\n<p>You can give your lambda function access to RDS via IAM roles instead of using API keys with an external app.</p>\n</li>\n<li>\n<p>The main use case for these lambda snapshot modules is to copy RDS snapshots to an external AWS account. That means\nyou need to run code in multiple accounts. It's easier to deploy the necessary lambda functions in each account\nand give those functions access to RDS via IAM roles than it is to create a CI job that can securely access both\naccounts.</p>\n</li>\n</ol>\n<h2 class=\"preview__body--subtitle\" id=\"how-do-you-configure-this-module\">How do you configure this module?</h2>\n<p>This module allows you to configure a number of parameters, such as which database to backup, how often to run the\nbackups, what account to share the backups with, and more. For a list of all available variables and their\ndescriptions, see <a href=\"/repos/v0.17.1/module-data-storage/modules/lambda-create-snapshot/vars.tf\" class=\"preview__body--description--blue\">vars.tf</a>.</p>\n<h2 class=\"preview__body--subtitle\" id=\"how-do-you-configure-multiple-backup-schedules\">How do you configure multiple backup schedules?</h2>\n<p>You can use this module multiple times by configuring different namespaces for the snapshots, which allows you to have\nmultiple backup schedules with different retention periods. For example you could keep hourly backups for three days,\nand weekly backups for one year by configuring two instances of this modules.</p>\n<pre><code>```hcl\nmodule "create_daily_snapshot" {\n source = "git::git@github.com:gruntwork-io/module-data-storage.git//modules/lambda-create-snapshot?ref=v1.0.8"\n\n # ... (other params omitted) ...\n\n lambda_namespace = "${var.rds_db_identifier}-create-weekly-snapshot"\n snapshot_namespace = "daily"\n schedule_expression = "rate(1 day)"\n}\n\nmodule "create_weekly_snapshot" {\n source = "git::git@github.com:gruntwork-io/module-data-storage.git//modules/lambda-create-snapshot?ref=v1.0.8"\n\n # ... (other params omitted) ...\n lambda_namespace = "${var.rds_db_identifier}-create-weekly-snapshot"\n snapshot_namespace = "weekly"\n schedule_expression = "rate(1 week)"\n}\n```\n</code></pre>\n<p>Configure sharing in the same way as described earlier. Only the snapshots from the module with sharing enabled will be\ncopied.</p>\n<p>It's important to use both snapshot and lambda namespaces in all instances to avoid ambiguity for the\n<a href=\"/repos/v0.17.1/module-data-storage/modules/lambda-cleanup-snapshots\" class=\"preview__body--description--blue\">lambda-cleanup-snapshots</a> module. The\n<a href=\"/repos/v0.17.1/module-data-storage/modules/lambda-cleanup-snapshots\" class=\"preview__body--description--blue\">lambda-cleanup-snapshots</a> module can be configured with a <code>snapshot_namespace</code> too so\ndifferent retention periods can be configured for each set of snapshots. See the\n<a href=\"/repos/v0.17.1/module-data-storage/examples/lambda-rds-snapshot-multiple-schedules\" class=\"preview__body--description--blue\">lambda-rds-snapshot-multiple-schedules</a> example.</p>\n","repoName":"module-data-storage","repoRef":"v0.13.0","serviceDescriptor":{"serviceName":"Database backup","serviceRepoName":"module-data-storage","serviceRepoOrg":"gruntwork-io","serviceMainReadmePath":"/modules/lambda-create-snapshot/README.adoc","cloudProviders":["aws"],"description":"Snapshot your RDS databases and copy the snapshots to other AWS accounts on a scheduled basis for disaster recovery.","imageUrl":"grunt.png","licenseType":"subscriber","technologies":["Terraform","JavaScript","Lambda"],"compliance":[],"tags":[""]},"serviceCategoryName":"Backup & recovery","fileName":"core-concepts.md","filePath":"/modules/lambda-create-snapshot/core-concepts.md","title":"Repo Browser: Database backup","description":"Browse the repos in the Gruntwork Infrastructure as Code Library."}