aws-amplify / amplify-category-api

The AWS Amplify CLI is a toolchain for simplifying serverless web and mobile development. This plugin provides functionality for the API category, allowing for the creation and management of GraphQL and REST based backends for your amplify project.
https://docs.amplify.aws/
Apache License 2.0
90 stars 76 forks source link

Enable PointInTimeRecovery for a single DynamoDB table by cloudFormation (not all in schema) #202

Open cs-thorsten opened 3 years ago

cs-thorsten commented 3 years ago

Which Category is your question related to?

I want to activate PointInTimeRecovery for just one single table in the schema by CloudFormation.

Amplify CLI Version

4.44.0

What AWS Services are you utilizing?

AWS Amplify, Amazon DynamoDB, AWS CloudFormation, AWS CDK

Provide additional details e.g. code snippets

I know to enable PITR by setting PointInTimeRecoveryEnabled in amplify/backend/api/<api-name>/parameters.json to true. But this enables PITR for all tables in the schema.

I know to activate it maually either in the AWS DynmoDB Console or by CLI: aws dynamodb update-continuous-backups --table-name myTable --point-in-time-recovery-specification PointInTimeRecoveryEnabled=True

But I want to define it in the template, so it can be deliverd to multiple environments without manual interaction.

As there is no annotation for the type in the schema.graphql file, we thought there might be a way to set it via Cloudformation in amplify/backend/api/<myapi>/stacks/CustomResources.json but we did not find out yet.

edwardfoyle commented 3 years ago

Hi @TMMeyer the CLI does not provide a way to do this out of the box. The options you've already mentioned are probably your best bet for achieving this. Marking as an enhancement.

cs-thorsten commented 3 years ago

There is a German proverb which says, "Hope is the last to die".

cfbo commented 3 years ago

+1 Partially related to that: aws-amplify/amplify-category-api#235

hanna-becker commented 1 year ago

Not sure if the amplify version you're on already has the override feature. If so, I believe you should be able to add an override like explained here and enable PITR for a specific model.

// override.ts

import { AmplifyApiGraphQlResourceStackTemplate } from '@aws-amplify/cli-extensibility-helper';

export function override(resources: AmplifyApiGraphQlResourceStackTemplate) {
  resources.models['YourTable'].modelDDBTable.pointInTimeRecoverySpecification = {
    pointInTimeRecoveryEnabled: true,
  };
}
clintagossett commented 1 year ago

It's 2023 and this was very useful. I needed a way to turn on PITR across all of my Tables in my project. The issue is, I only want it "on" for staging and prod. NOT dev or any of our feature branches.

The best way I can imagine doing this is through an Amplify hook that can switch modes around the environment variable. I'll likely need to inject a change to PointInTimeRecoveryEnabled in amplify/backend/api/<api-name>/parameters.json.

I don't like doing this stuff because it's hard for future developers to track things down. Aside from that, is there a reason "NOT" to rely on amplify hooks in this way?

For those who happen upon this thread, I would suggest an amplify hook to call the CLI to enable PITR on a given table. Note: this will only work on build #s >1.

mutablestudio commented 8 months ago

fyi the correct key name in paramaters.json is DynamoDBEnablePointInTimeRecovery