diff options
author | Jordan Cook <jordan.cook@pioneer.com> | 2022-04-19 17:19:50 -0500 |
---|---|---|
committer | Jordan Cook <jordan.cook@pioneer.com> | 2022-04-19 18:57:14 -0500 |
commit | e5dec6a209bc685ad9ac93992d8df953d2b420c1 (patch) | |
tree | 0168e87b431bfda7aa20019b032a657e507663d2 | |
parent | d19776ca25db85912529182daca5f03ba38f60a8 (diff) | |
download | requests-cache-e5dec6a209bc685ad9ac93992d8df953d2b420c1.tar.gz |
Add an example CloudFormation template for DynamoDB
-rw-r--r-- | .pre-commit-config.yaml | 1 | ||||
-rw-r--r-- | docs/user_guide/backends/dynamodb.md | 36 | ||||
-rw-r--r-- | examples/cloudformation.yml | 32 |
3 files changed, 61 insertions, 8 deletions
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 9500153..f272ddc 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -4,6 +4,7 @@ repos: hooks: - id: check-toml - id: check-yaml + args: ['--unsafe'] - id: end-of-file-fixer - id: mixed-line-ending - id: trailing-whitespace diff --git a/docs/user_guide/backends/dynamodb.md b/docs/user_guide/backends/dynamodb.md index ebd2e01..f807a77 100644 --- a/docs/user_guide/backends/dynamodb.md +++ b/docs/user_guide/backends/dynamodb.md @@ -36,13 +36,33 @@ This backend accepts any keyword arguments for {py:meth}`boto3.session.Session.r >>> session = CachedSession(backend=backend) ``` -## Creating Tables -Tables will be automatically created if they don't already exist. This is convienient if you just +## Table +A table will be automatically created if one doesn't already exist. This is convienient if you just want to quickly test out DynamoDB as a cache backend, but in a production environment you will -likely want to create the tables yourself, for example with [CloudFormation](https://aws.amazon.com/cloudformation/) or [Terraform](https://www.terraform.io/). Here are the -details you'll need: +likely want to create the tables yourself, for example with +[CloudFormation](https://aws.amazon.com/cloudformation/) or [Terraform](https://www.terraform.io/). -- Tables: two tables, named `responses` and `redirects` -- Partition key (aka namespace): `namespace` -- Range key (aka sort key): `key` -- Attributes: `namespace` (string) and `key` (string) +Here are the details you will need: + +- Table: `http_cache` (or any other name, as long as it matches the `table_name` parameter for `DynamoDbCache`) +- Attributes: + - `namespace`: String + - `key`: String +- Keys: + - Partition key (aka namespace): `namespace` + - Range key (aka sort key): `key` + +### Example CloudFormation Template +:::{admonition} Example: [cloudformation.yml](https://github.com/reclosedev/requests-cache/blob/master/examples/cloudformation.yml) +:class: toggle +```{literalinclude} ../../../examples/cloudformation.yml +:language: yaml +``` +::: + +Then deploy with: +``` +aws cloudformation deploy \ + --stack-name requests-cache \ + --template-file examples/cloudformation.yml +``` diff --git a/examples/cloudformation.yml b/examples/cloudformation.yml new file mode 100644 index 0000000..ef5d749 --- /dev/null +++ b/examples/cloudformation.yml @@ -0,0 +1,32 @@ +AWSTemplateFormatVersion: "2010-09-09" +Description: An example of creating a DynamoDB table to use as a requests-cache backend + +Parameters: + CacheTableName: + Type: String + Default: http_cache + Description: > + An alternate DynamoDB table name to use. If provided, this must match the + table_name parameter for DynamoDbCache. + +Resources: + DynamoDBRequestCache: + Type: AWS::DynamoDB::Table + Properties: + TableName: !Ref CacheTableName + AttributeDefinitions: + - AttributeName: namespace + AttributeType: S + - AttributeName: key + AttributeType: S + KeySchema: + - AttributeName: namespace + KeyType: HASH + - AttributeName: key + KeyType: RANGE + BillingMode: PAY_PER_REQUEST + # Uncomment for provisioned throughput instead of on-demand + # BillingMode: PROVISIONED + # ProvisionedThroughput: + # WriteCapacityUnits: 2 + # ReadCapacityUnits: 2 |